Skip to content

Commit 53f7d4d

Browse files
author
MHDtA-dev
committed
Multiple workspaces, multiplexer added
1 parent 918370a commit 53f7d4d

39 files changed

Lines changed: 774 additions & 140 deletions

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ add_executable(LogiGates main.cpp
7474
UI/imgui/AboutWindow.cpp
7575
UI/imgui/AboutWindow.h
7676
Core/LogicalElements/FiveBitNumberDisplay.cpp
77-
Core/LogicalElements/FiveBitNumberDisplay.h)
77+
Core/LogicalElements/FiveBitNumberDisplay.h
78+
UI/imgui/Welcome.cpp
79+
UI/imgui/Welcome.h
80+
Core/LogicalElements/Multiplexer.cpp
81+
Core/LogicalElements/Multiplexer.h)
7882

7983

8084
target_sources(LogiGates PRIVATE

Core/App.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818

1919
namespace LogiGates::Core {
2020

21-
App::App() {
21+
App::App(int argc, char* argv[]) {
22+
std::cout << argv[0] << std::endl;
23+
2224
window = new UI::Window("LogiGates");
2325
renderer = new UI::Renderer(window);
2426

2527
UI::Images::load(renderer);
2628

27-
workspace = new UI::Workspace();
28-
dockspace = new UI::Dockspace(workspace);
29+
dockspace = new UI::Dockspace();
2930
elementsMenu = new UI::ElementsMenu();
3031

3132
UI::Localization::init();
@@ -48,7 +49,6 @@ namespace LogiGates::Core {
4849

4950
dockspace->render();
5051
elementsMenu->render();
51-
workspace->render();
5252

5353
renderer->end();
5454
}

Core/App.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace LogiGates::Core {
2929

3030
class App {
3131
public:
32-
App();
32+
App(int argc, char* argv[]);
3333
~App();
3434

3535
void run();
@@ -40,7 +40,6 @@ namespace LogiGates::Core {
4040

4141
UI::Dockspace* dockspace;
4242
UI::ElementsMenu* elementsMenu;
43-
UI::Workspace* workspace;
4443
};
4544

4645

Core/LogicalElements/And.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ namespace LogiGates::Core::LogicalElements {
4040

4141
void And::perform(std::set<int> performedIDs) {
4242
if (this->checkRecursion(performedIDs)) return;
43-
if (pins[0]->getConnectedWith() != -1) pins[0]->setState(Pin::globalPinMap[pins[0]->getConnectedWith()]->getState());
44-
if (pins[1]->getConnectedWith() != -1) pins[1]->setState(Pin::globalPinMap[pins[1]->getConnectedWith()]->getState());
43+
if (pins[0]->getConnectedWith() != -1) pins[0]->setState(workspace->globalPinMap[pins[0]->getConnectedWith()]->getState());
44+
if (pins[1]->getConnectedWith() != -1) pins[1]->setState(workspace->globalPinMap[pins[1]->getConnectedWith()]->getState());
4545
pins[2]->setState(pins[0]->getState() and pins[1]->getState());
4646
performedIDs.emplace(this->id);
4747
pins[2]->performNext(performedIDs);

Core/LogicalElements/Base.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
namespace LogiGates::Core::LogicalElements {
2121

2222
Base::Base(UI::Workspace* workspace) : workspace(workspace) {
23-
id = nodeIDCounter;
24-
nodeIDCounter++;
23+
id = workspace->nodeIDCounter;
24+
workspace->nodeIDCounter++;
2525
}
2626

2727
void Base::perform(std::set<int> performedIDs) {
@@ -64,11 +64,11 @@ namespace LogiGates::Core::LogicalElements {
6464
return ret;
6565
}
6666

67-
void Base::restoreFromSaveInfo(SaveInfo info) {
67+
void Base::restoreFromSaveInfo(SaveInfo info, ImNodesEditorContext* editorCtx) {
6868
this->id = info.id;
6969

70-
if (this->id > nodeIDCounter) {
71-
nodeIDCounter = this->id + 1;
70+
if (this->id > workspace->nodeIDCounter) {
71+
workspace->nodeIDCounter = this->id + 1;
7272
}
7373

7474
for (int i = 0; i < 255; i++) {
@@ -80,6 +80,7 @@ namespace LogiGates::Core::LogicalElements {
8080
if (info.connections[i] != -1) workspace->connectionQueue.push_back({pins[i]->getType() == PinType::OUTPUT ? pins[i]->getID() : info.connections[i], pins[i]->getType() == PinType::OUTPUT ? info.connections[i] : pins[i]->getID()});
8181
}
8282

83+
ImNodes::EditorContextSet(editorCtx);
8384
ImNodes::SetNodeEditorSpacePos(this->id, {info.positionX, info.positionY});
8485
}
8586

@@ -96,4 +97,8 @@ namespace LogiGates::Core::LogicalElements {
9697
return false;
9798
}
9899

100+
UI::Workspace* Base::getWorkspace() {
101+
return this->workspace;
102+
}
103+
99104
}

Core/LogicalElements/Base.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ namespace LogiGates::Core::LogicalElements {
5252
virtual void render();
5353

5454
int getID();
55+
UI::Workspace* getWorkspace();
5556

5657
virtual SaveInfo getSaveInfo();
57-
virtual void restoreFromSaveInfo(SaveInfo info);
58+
virtual void restoreFromSaveInfo(SaveInfo info, ImNodesEditorContext* editorCtx);
5859

5960
std::string getTypeName();
6061

@@ -63,7 +64,6 @@ namespace LogiGates::Core::LogicalElements {
6364

6465
int id = -1;
6566
std::vector<Pin*> pins;
66-
inline static int nodeIDCounter = 1;
6767

6868
std::string typeName;
6969

Core/LogicalElements/Equivalent.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include "Equivalent.h"
18+
#include "../../UI/imgui/Workspace.h"
1819

1920
namespace LogiGates::Core::LogicalElements {
2021

@@ -42,9 +43,9 @@ namespace LogiGates::Core::LogicalElements {
4243
void Equivalent::perform(std::set<int> performedIDs) {
4344
if (this->checkRecursion(performedIDs)) return;
4445
if (pins[0]->getConnectedWith() != -1)
45-
pins[0]->setState(Pin::globalPinMap[pins[0]->getConnectedWith()]->getState());
46+
pins[0]->setState(workspace->globalPinMap[pins[0]->getConnectedWith()]->getState());
4647
if (pins[1]->getConnectedWith() != -1)
47-
pins[1]->setState(Pin::globalPinMap[pins[1]->getConnectedWith()]->getState());
48+
pins[1]->setState(workspace->globalPinMap[pins[1]->getConnectedWith()]->getState());
4849
pins[2]->setState(pins[0]->getState() == pins[1]->getState());
4950
performedIDs.emplace(this->id);
5051
pins[2]->performNext(performedIDs);

Core/LogicalElements/FiveBitNumberDisplay.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include "FiveBitNumberDisplay.h"
18+
#include "../../UI/imgui/Workspace.h"
1819

1920
namespace LogiGates::Core::LogicalElements {
2021

@@ -51,13 +52,13 @@ namespace LogiGates::Core::LogicalElements {
5152

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

5657
number = 0;
5758

5859
for (int i = 0; i < 5; i++) {
59-
if (inputs[4 - i]->getConnectedWith() != -1) inputs[4 - i]->setState(Pin::globalPinMap[inputs[4 - i]->getConnectedWith()]->getState());
60-
number += inputs[4 - i]->getState() * pow(2, i);
60+
if (inputs[i]->getConnectedWith() != -1) inputs[i]->setState(workspace->globalPinMap[inputs[i]->getConnectedWith()]->getState());
61+
number += inputs[i]->getState() * pow(2, 4 - i);
6162
}
6263

6364
performedIDs.emplace(this->id);
@@ -75,9 +76,9 @@ namespace LogiGates::Core::LogicalElements {
7576
return ret;
7677
}
7778

78-
void FiveBitNumberDisplay::restoreFromSaveInfo(SaveInfo info) {
79+
void FiveBitNumberDisplay::restoreFromSaveInfo(SaveInfo info, ImNodesEditorContext* editorCtx) {
7980
this->number = info.additionalInfo[0];
80-
Base::restoreFromSaveInfo(info);
81+
Base::restoreFromSaveInfo(info, editorCtx);
8182
}
8283

8384
}

Core/LogicalElements/FiveBitNumberDisplay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace LogiGates::Core::LogicalElements {
3535
void perform(std::set<int> performedIDs = {}) override;
3636

3737
SaveInfo getSaveInfo() override;
38-
void restoreFromSaveInfo(SaveInfo info) override;
38+
void restoreFromSaveInfo(SaveInfo info, ImNodesEditorContext* editorCtx) override;
3939

4040
private:
4141
int number;

Core/LogicalElements/FiveBitNumberEncoder.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ namespace LogiGates::Core::LogicalElements {
6666

6767
void FiveBitNumberEncoder::perform(std::set<int> performedIDs) {
6868
if (this->checkRecursion(performedIDs)) return;
69-
Pin *outputs[5] = {pins[4], pins[3], pins[2], pins[1], pins[0]};
7069

7170
std::string binary = decToBaseReversed(number, 2);
7271
performedIDs.emplace(this->id);
7372

74-
for (int i = 0; i < 5; i++) {
75-
outputs[i]->setState(i < binary.size() and binary[i] == '1');
76-
outputs[i]->performNext(performedIDs);
73+
for (int i = 0; i < pins.size(); i++) {
74+
pins[i]->setState(i < binary.size() and binary[i] == '1');
75+
pins[i]->performNext(performedIDs);
7776
}
7877
}
7978

@@ -84,9 +83,9 @@ namespace LogiGates::Core::LogicalElements {
8483
return ret;
8584
}
8685

87-
void FiveBitNumberEncoder::restoreFromSaveInfo(SaveInfo info) {
86+
void FiveBitNumberEncoder::restoreFromSaveInfo(SaveInfo info, ImNodesEditorContext* editorCtx) {
8887
this->number = info.additionalInfo[0];
89-
Base::restoreFromSaveInfo(info);
88+
Base::restoreFromSaveInfo(info, editorCtx);
9089
}
9190

9291
}

0 commit comments

Comments
 (0)