Skip to content

Commit a7d89ae

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

39 files changed

+229
-119
lines changed

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;

Core/LogicalElements/FiveBitNumberEncoder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ namespace LogiGates::Core::LogicalElements {
6464
ImNodes::EndNode();
6565
}
6666

67-
void FiveBitNumberEncoder::perform() {
67+
void FiveBitNumberEncoder::perform(std::set<int> performedIDs) {
68+
if (this->checkRecursion(performedIDs)) return;
6869
Pin *outputs[5] = {pins[4], pins[3], pins[2], pins[1], pins[0]};
6970

7071
std::string binary = decToBaseReversed(number, 2);
71-
72+
performedIDs.emplace(this->id);
7273

7374
for (int i = 0; i < 5; i++) {
7475
outputs[i]->setState(i < binary.size() and binary[i] == '1');
75-
outputs[i]->performNext();
76+
outputs[i]->performNext(performedIDs);
7677
}
7778
}
7879

Core/LogicalElements/FiveBitNumberEncoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ namespace LogiGates::Core::LogicalElements {
3333
FiveBitNumberEncoder(UI::Workspace* workspace);
3434

3535
void render() override;
36-
void perform() override;
36+
void perform(std::set<int> performedIDs = {}) override;
3737

3838
SaveInfo getSaveInfo() override;
3939
void restoreFromSaveInfo(SaveInfo info) override;
4040

4141
private:
4242
int last = -1;
43-
int number;
43+
int number = 0;
4444
};
4545

4646
}

Core/LogicalElements/Implication.cpp

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

43-
void Implication::perform() {
43+
void Implication::perform(std::set<int> performedIDs) {
44+
if (this->checkRecursion(performedIDs)) return;
4445
if (pins[0]->getConnectedWith() != -1)
4546
pins[0]->setState(Pin::globalPinMap[pins[0]->getConnectedWith()]->getState());
4647
if (pins[1]->getConnectedWith() != -1)
4748
pins[1]->setState(Pin::globalPinMap[pins[1]->getConnectedWith()]->getState());
4849
pins[2]->setState(not pins[0]->getState() or pins[1]->getState());
49-
pins[2]->performNext();
50+
performedIDs.emplace(this->id);
51+
pins[2]->performNext(performedIDs);
5052
}
5153

5254
}

Core/LogicalElements/Implication.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace LogiGates::Core::LogicalElements {
2828
Implication(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/Lamp.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 Lamp::perform() {
41+
void Lamp::perform(std::set<int> performedIDs) {
42+
if (this->checkRecursion(performedIDs)) return;
4243
if (pins[0]->getConnectedWith() != -1)
4344
pins[0]->setState(Pin::globalPinMap[pins[0]->getConnectedWith()]->getState());
4445
pins[1]->setState(pins[0]->getState());
45-
pins[1]->performNext();
46+
performedIDs.emplace(this->id);
47+
pins[1]->performNext(performedIDs);
4648
}
4749

4850
}

Core/LogicalElements/Lamp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace LogiGates::Core::LogicalElements {
2828
Lamp(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/Not.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 Not::perform() {
41+
void Not::perform(std::set<int> performedIDs) {
42+
if (this->checkRecursion(performedIDs)) return;
4243
if (pins[0]->getConnectedWith() != -1)
4344
pins[0]->setState(Pin::globalPinMap[pins[0]->getConnectedWith()]->getState());
4445
pins[1]->setState(!pins[0]->getState());
45-
pins[1]->performNext();
46+
performedIDs.emplace(this->id);
47+
pins[1]->performNext(performedIDs);
4648
}
4749

4850
}

Core/LogicalElements/Not.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace LogiGates::Core::LogicalElements {
2828
Not(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/Or.cpp

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

44-
void Or::perform() {
44+
void Or::perform(std::set<int> performedIDs) {
45+
if (this->checkRecursion(performedIDs)) return;
4546
if (pins[0]->getConnectedWith() != -1)
4647
pins[0]->setState(Pin::globalPinMap[pins[0]->getConnectedWith()]->getState());
4748
if (pins[1]->getConnectedWith() != -1)
4849
pins[1]->setState(Pin::globalPinMap[pins[1]->getConnectedWith()]->getState());
4950
pins[2]->setState(pins[0]->getState() or pins[1]->getState());
50-
pins[2]->performNext();
51+
performedIDs.emplace(this->id);
52+
pins[2]->performNext(performedIDs);
5153
}
5254

5355
}

Core/LogicalElements/Or.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace LogiGates::Core::LogicalElements {
2828
Or(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/Splitter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,16 @@ namespace LogiGates::Core::LogicalElements {
6060
ImNodes::EndNode();
6161
}
6262

63-
void Splitter::perform() {
63+
void Splitter::perform(std::set<int> performedIDs) {
64+
if (this->checkRecursion(performedIDs)) return;
6465
if (pins[0]->getConnectedWith() != -1)
6566
pins[0]->setState(Pin::globalPinMap[pins[0]->getConnectedWith()]->getState());
6667

68+
performedIDs.emplace(this->id);
69+
6770
for (int i = 1; i < pins.size(); i++) {
6871
pins[i]->setState(pins[0]->getState());
69-
pins[i]->performNext();
72+
pins[i]->performNext(performedIDs);
7073
}
7174
}
7275

Core/LogicalElements/Splitter.h

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

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

3434
SaveInfo getSaveInfo() override;
3535
void restoreFromSaveInfo(SaveInfo info) override;

Core/LogicalElements/Switch.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace LogiGates::Core::LogicalElements {
3333
: UI::Images::icons["switch_off"]->texture), {70, 70},
3434
{0, 0}, {1, 1})) {
3535
pins[0]->setState(!pins[0]->getState());
36-
pins[0]->performNext();
36+
this->perform();
3737
}
3838

3939
for (Pin *p: pins) {
@@ -43,8 +43,10 @@ namespace LogiGates::Core::LogicalElements {
4343
ImNodes::EndNode();
4444
}
4545

46-
void Switch::perform() {
47-
pins[0]->performNext();
46+
void Switch::perform(std::set<int> performedIDs) {
47+
if (this->checkRecursion(performedIDs)) return;
48+
performedIDs.emplace(this->id);
49+
pins[0]->performNext(performedIDs);
4850
}
4951

5052
}

Core/LogicalElements/Switch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace LogiGates::Core::LogicalElements {
2828
Switch(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/Xor.cpp

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

44-
void Xor::perform() {
44+
void Xor::perform(std::set<int> performedIDs) {
45+
if (this->checkRecursion(performedIDs)) return;
4546
if (pins[0]->getConnectedWith() != -1)
4647
pins[0]->setState(Pin::globalPinMap[pins[0]->getConnectedWith()]->getState());
4748
if (pins[1]->getConnectedWith() != -1)
4849
pins[1]->setState(Pin::globalPinMap[pins[1]->getConnectedWith()]->getState());
4950
pins[2]->setState(pins[0]->getState() xor pins[1]->getState());
50-
pins[2]->performNext();
51+
performedIDs.emplace(this->id);
52+
pins[2]->performNext(performedIDs);
5153
}
5254

5355
}

Core/LogicalElements/Xor.h

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

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

3434
}

Core/Pin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ namespace LogiGates::Core {
7575
this->state = state;
7676
}
7777

78-
void Pin::performNext() {
78+
void Pin::performNext(std::set<int> performedIDs) {
7979
if (this->type == PinType::OUTPUT and this->nextElement != nullptr) {
80-
this->nextElement->perform();
80+
this->nextElement->perform(performedIDs);
8181
}
8282
}
8383

0 commit comments

Comments
 (0)