Skip to content

Commit a7d89ae

Browse files
author
MHDtA-dev
committed
Major bugfix
1 parent 7e1074a commit a7d89ae

39 files changed

Lines changed: 229 additions & 119 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ include(FetchContent)
77

88
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Resources/fonts DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
99
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Resources/icons DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
10+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Resources/imgui.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
1011

1112
FetchContent_Declare(
1213
webgpu

Core/App.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@ namespace LogiGates::Core {
3434

3535
void App::run() {
3636
while (!this->window->shouldClose()) {
37-
window->pollEvents([] (SDL_Event e) {
37+
window->pollEvents([=] (SDL_Event e) {
3838
ImGui_ImplSDL2_ProcessEvent(&e);
39+
40+
if (e.type == SDL_WINDOWEVENT) {
41+
if (e.window.event == SDL_WINDOWEVENT_RESIZED or e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
42+
renderer->windowResized(e.window.data1, e.window.data2);
43+
}
44+
}
3945
});
4046

4147
if (renderer->begin()) {

Core/LogicalElements/And.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ namespace LogiGates::Core::LogicalElements {
3838
ImNodes::EndNode();
3939
}
4040

41-
void And::perform() {
41+
void And::perform(std::set<int> performedIDs) {
42+
if (this->checkRecursion(performedIDs)) return;
4243
if (pins[0]->getConnectedWith() != -1) pins[0]->setState(Pin::globalPinMap[pins[0]->getConnectedWith()]->getState());
4344
if (pins[1]->getConnectedWith() != -1) pins[1]->setState(Pin::globalPinMap[pins[1]->getConnectedWith()]->getState());
4445
pins[2]->setState(pins[0]->getState() and pins[1]->getState());
45-
pins[2]->performNext();
46+
performedIDs.emplace(this->id);
47+
pins[2]->performNext(performedIDs);
4648
}
4749

4850

Core/LogicalElements/And.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace LogiGates::Core::LogicalElements {
2828
And(UI::Workspace* workspace);
2929

3030
void render() override;
31-
void perform() override;
31+
void perform(std::set<int> performedIDs = {}) override;
3232
};
3333

3434
}

Core/LogicalElements/Base.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace LogiGates::Core::LogicalElements {
2424
nodeIDCounter++;
2525
}
2626

27-
void Base::perform() {
27+
void Base::perform(std::set<int> performedIDs) {
2828

2929
}
3030

@@ -87,4 +87,13 @@ namespace LogiGates::Core::LogicalElements {
8787
return this->typeName;
8888
}
8989

90+
bool Base::checkRecursion(std::set<int> performedIDs) {
91+
if (performedIDs.find(this->id) != performedIDs.end()) {
92+
this->workspace->enableRecursionWarning();
93+
return true;
94+
}
95+
96+
return false;
97+
}
98+
9099
}

Core/LogicalElements/Base.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define LOGIGATES_BASE_H
1919

2020
#include <iostream>
21+
#include <set>
2122
#include <functional>
2223

2324
#include "../Pin.h"
@@ -47,7 +48,7 @@ namespace LogiGates::Core::LogicalElements {
4748
Base(UI::Workspace* workspace);
4849
~Base();
4950

50-
virtual void perform();
51+
virtual void perform(std::set<int> performedIDs = {});
5152
virtual void render();
5253

5354
int getID();
@@ -66,6 +67,8 @@ namespace LogiGates::Core::LogicalElements {
6667

6768
std::string typeName;
6869

70+
bool checkRecursion(std::set<int> performedIDs);
71+
6972
};
7073

7174
}

Core/LogicalElements/Equivalent.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ namespace LogiGates::Core::LogicalElements {
3939
ImNodes::EndNode();
4040
}
4141

42-
void Equivalent::perform() {
42+
void Equivalent::perform(std::set<int> performedIDs) {
43+
if (this->checkRecursion(performedIDs)) return;
4344
if (pins[0]->getConnectedWith() != -1)
4445
pins[0]->setState(Pin::globalPinMap[pins[0]->getConnectedWith()]->getState());
4546
if (pins[1]->getConnectedWith() != -1)
4647
pins[1]->setState(Pin::globalPinMap[pins[1]->getConnectedWith()]->getState());
4748
pins[2]->setState(pins[0]->getState() == pins[1]->getState());
48-
pins[2]->performNext();
49+
performedIDs.emplace(this->id);
50+
pins[2]->performNext(performedIDs);
4951
}
5052

5153
}

Core/LogicalElements/Equivalent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace LogiGates::Core::LogicalElements {
2828
Equivalent(UI::Workspace* workspace);
2929

3030
void render() override;
31-
void perform() override;
31+
void perform(std::set<int> performedIDs = {}) override;
3232
};
3333

3434
}

Core/LogicalElements/FiveBitNumberDisplay.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ namespace LogiGates::Core::LogicalElements {
4949
ImNodes::EndNode();
5050
}
5151

52-
void FiveBitNumberDisplay::perform() {
52+
void FiveBitNumberDisplay::perform(std::set<int> performedIDs) {
53+
if (this->checkRecursion(performedIDs)) return;
5354
Pin* inputs[5] = {pins[0], pins[1], pins[2], pins[3], pins[4]};
5455

5556
number = 0;
@@ -59,9 +60,11 @@ namespace LogiGates::Core::LogicalElements {
5960
number += inputs[4 - i]->getState() * pow(2, i);
6061
}
6162

63+
performedIDs.emplace(this->id);
64+
6265
for (int i = 5; i < pins.size(); i++) {
6366
pins[i]->setState(pins[i - 5]->getState());
64-
pins[i]->performNext();
67+
pins[i]->performNext(performedIDs);
6568
}
6669
}
6770

Core/LogicalElements/FiveBitNumberDisplay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace LogiGates::Core::LogicalElements {
3232
FiveBitNumberDisplay(UI::Workspace* workspace);
3333

3434
void render() override;
35-
void perform() override;
35+
void perform(std::set<int> performedIDs = {}) override;
3636

3737
SaveInfo getSaveInfo() override;
3838
void restoreFromSaveInfo(SaveInfo info) override;

0 commit comments

Comments
 (0)