TazGraph Project v0.1.0
Loading...
Searching...
No Matches
GECSEntity.h
1#pragma once
2
3#include "CellEntity.h"
4
5class LinkEntity;
6
7class EmptyEntity : public CellEntity {
8public:
9
10 EmptyEntity(Manager& mManager) : CellEntity(mManager) {}
11
12 void setComponentEntity(Component* c) override {
13 c->entity = this;
14 }
15
16
17
18 void removeFromCell() override {
19 if (this->ownerCell) {
20 removeEntityFromCell();
21 this->ownerCell = nullptr;
22 }
23 }
24
25 void removeEntityFromCell() override {
26 auto* cell = ownerCell;
27 if (!cell) return;
28
29 std::scoped_lock lock(cell->mtx); // automatically releases when leaving scope
30
31 auto& entities = cell->emptyEntities;
32 auto it = std::find(entities.begin(), entities.end(), getId());
33 if (it != entities.end())
34 entities.erase(it);
35 }
36
37
38};
39
40class NodeEntity : public EmptyEntity {
41protected:
42 std::vector<EntityID> inLinks;
43 std::vector<EntityID> outLinks;
44public:
45
46 NodeEntity(Manager& mManager) : EmptyEntity(mManager) {
47 nodeComponentArray.emplace();
48 nodeComponentBitSet.emplace();
49
50 }
51 void setComponentEntity(NodeComponent* c) override {
52 c->entity = this;
53
54 }
55
56 void removeEntityFromCell() override {
57 auto* cell = ownerCell;
58 if (!cell) return;
59
60 std::scoped_lock lock(cell->mtx); // automatically releases when leaving scope
61
62 auto& entities = cell->nodes;
63 auto it = std::find(entities.begin(), entities.end(), getId());
64 if (it != entities.end())
65 entities.erase(it);
66 }
67
68 void addInLink(EntityID link) {
69 inLinks.push_back(link);
70 }
71
72 void addOutLink(EntityID link) {
73 outLinks.push_back(link);
74 }
75
76 void removeInLink(EntityID link) {
77 auto it = std::find(inLinks.begin(), inLinks.end(), link);
78 if (it != inLinks.end()) {
79 inLinks.erase(it);
80 }
81 }
82
83 void removeOutLink(EntityID link) {
84 auto it = std::find(outLinks.begin(), outLinks.end(), link);
85 if (it != outLinks.end()) {
86 outLinks.erase(it);
87 }
88 }
89
90 const std::vector<EntityID>& getInLinks() const {
91 return inLinks;
92 }
93
94 const std::vector<EntityID>& getOutLinks() const {
95 return outLinks;
96 }
97
98 virtual void addPorts() {}
99
100 virtual void removePorts() {}
101 virtual void removeSlots() {}
102
103 virtual void updatePorts(float deltaTime) {}
104
105};
106
107
109public:
111 EntityID fromId = 0;
112 EntityID toId = 0;
113
114 enum class ConnectionType {
115 NODE_TO_NODE,
116 PORT_TO_PORT,
117 DIRECT_POSITIONS,
118 GHOST_PORT_TO_PORT
119 };
120 ConnectionType type = ConnectionType::NODE_TO_NODE;
121
123
124 glm::vec3 fromPos = glm::vec3(0);
125 glm::vec3 toPos = glm::vec3(0);
126
128 EntityID fromPort = -1;
129 EntityID toPort = -1;
130 int fromSlotIndex = -1;
131 int toSlotIndex = -1;
132
133 LinkEntity(Manager& mManager) : MultiCellEntity(mManager) {
134
135 }
136
137 LinkEntity(Manager& mManager, EntityID mfromId, EntityID mtoId)
138 : MultiCellEntity(mManager), fromId(mfromId), toId(mtoId) {
139 type = ConnectionType::NODE_TO_NODE;
140
141 }
142
144 Manager& mManager,
145 EntityID mfromId, EntityID mtoId,
146 EntityID m_fromPort, EntityID m_toPort, int m_fromSlot, int m_toSlot)
147 : MultiCellEntity(mManager), fromId(mfromId), toId(mtoId)
148 {
149 fromPort = m_fromPort;
150 toPort = m_toPort;
151 fromSlotIndex = m_fromSlot;
152 toSlotIndex = m_toSlot;
153 type = ConnectionType::PORT_TO_PORT;
154 }
155
157 Manager& mManager,
158 glm::vec3 mfrom, glm::vec3 mto
159 )
160 : MultiCellEntity(mManager), fromPos(mfrom), toPos(mto)
161 {
162 type = ConnectionType::DIRECT_POSITIONS;
163 }
164
165 void setComponentEntity(LinkComponent* c) override {
166 c->entity = this;
167 }
168
169 void removeFromCells() override {
170 removeEntityFromCell();
171 ownerCells.clear();
172 }
173
174 void removeEntityFromCell() override {
175 for (auto& cell : ownerCells) {
176 if (!cell) continue;
177
178 // Lock per-cell to prevent concurrent erase
179 std::scoped_lock lock(cell->mtx);
180
181 auto& links = cell->links;
182 auto it = std::find(links.begin(), links.end(), getId());
183 if (it != links.end()) {
184 links.erase(it);
185 }
186 }
187 }
188
189 EntityID getFromNode() const {
190 return fromId;
191 }
192
193 EntityID getToNode() const {
194 return toId;
195 }
196
197 virtual void setConnectionType(ConnectionType setType) {}
198
199 virtual void updateConnection() {}
200
201 virtual void updatePortSlots() {}
202
203 virtual void updateArrowHeads() {}
204
205 virtual void addArrowHead() {}
206
207 virtual void removeArrowHead() {}
208};
Definition CellEntity.h:38
Definition GECS.h:131
Definition GECSEntity.h:7
Definition GECS.h:141
Definition GECSEntity.h:108
EntityID fromId
When Node_to_Node.
Definition GECSEntity.h:111
glm::vec3 fromPos
When DirectPosition.
Definition GECSEntity.h:124
EntityID fromPort
When Port_to_Port.
Definition GECSEntity.h:128
Definition GECSManager.h:20
Definition CellEntity.h:56
Definition GECS.h:136
Definition GECSEntity.h:40