18 int negativeEntityId = -1;
19 std::vector<std::unique_ptr<Entity>> entities;
21 std::array<std::vector<EmptyEntity*>, maxGroups> groupedEmptyEntities;
22 std::array<std::vector<NodeEntity*>, maxGroups> groupedNodeEntities;
23 std::array<std::vector<LinkEntity*>, maxGroups> groupedLinkEntities;
25 std::vector<EmptyEntity*> visible_emptyEntities;
26 std::vector<NodeEntity*> visible_nodes;
27 std::vector<LinkEntity*> visible_links;
29 std::array<std::vector<EmptyEntity*>, maxGroups> visible_groupedEmptyEntities;
30 std::array<std::vector<NodeEntity*>, maxGroups> visible_groupedNodeEntities;
31 std::array<std::vector<LinkEntity*>, maxGroups> visible_groupedLinkEntities;
33 bool _update_active_entities =
false;
36 std::vector<NodeEntity*> movedNodes;
37 std::mutex movedNodesMutex;
39 bool arrowheadsEnabled =
false;
40 bool last_arrowheadsEnabled =
false;
42 std::unordered_map<std::string, std::vector<std::string>> componentNames;
44 std::unique_ptr<Grid> grid;
50 void setThreader(
Threader& mthreader) {
51 _threader = &mthreader;
58 if (_threader && !_threader->t_queue.shuttingDown) {
81 for (
auto& e : movedNodes) {
82 for (
auto& link : e->getInLinks()) {
85 for (
auto& link : e->getOutLinks()) {
90 _threader->parallel(movedNodes.size(), [&](
int start,
int end) {
91 for (
int i = start; i < end; i++) {
92 for (
auto& link : movedNodes[i]->getInLinks()) {
93 link->updateLinkToPorts();
98 _threader->parallel(movedNodes.size(), [&](
int start,
int end) {
99 for (
int i = start; i < end; i++) {
100 for (
auto& link : movedNodes[i]->getOutLinks()) {
101 link->updateLinkToPorts();
109 _threader->parallel(visible_emptyEntities.size(), [&](
int start,
int end) {
110 for (
int i = start; i < end; i++) {
111 if (visible_emptyEntities[i] && visible_emptyEntities[i]->isActive()) {
112 visible_emptyEntities[i]->update(deltaTime);
118 _threader->parallel(visible_nodes.size(), [&](
int start,
int end) {
119 for (
int i = start; i < end; i++) {
120 if (visible_nodes[i] && visible_nodes[i]->isActive()) {
121 visible_nodes[i]->update(deltaTime);
128 _threader->parallel(visible_links.size(), [&](
int start,
int end) {
130 for (
int i = start; i < end; i++) {
131 if (visible_links[i] && visible_links[i]->isActive()) {
132 visible_links[i]->update(deltaTime);
144 for (
auto& e : movedNodes) {
145 for (
auto& link : e->getInLinks()) {
148 for (
auto& link : e->getOutLinks()) {
153 for (
auto& e : movedNodes) {
154 for (
auto& link : e->getInLinks()) {
155 link->updateLinkToPorts();
159 for (
auto& e : movedNodes) {
160 for (
auto& link : e->getOutLinks()) {
161 link->updateLinkToPorts();
167 for (
auto& e : visible_emptyEntities) {
168 if (!e || !e->isActive())
continue;
170 e->update(deltaTime);
173 if (arrowheadsEnabled) {
174 for (
auto& e : visible_nodes) {
175 if (!e || !e->isActive())
continue;
177 e->update(deltaTime);
183 for (
auto& e : visible_links) {
184 if (!e || !e->isActive())
continue;
186 e->update(deltaTime);
192 void updateFully(
float deltaTime = 1.0f)
195 for (
auto& e : entities) {
196 if (!e || !e->isActive())
continue;
198 e->update(deltaTime);
202 void refresh(
ICamera* camera =
nullptr)
205 if (grid && (camera->hasChanged() || grid->gridLevelChanged())) {
206 bool interceptedCellsChanged = grid->setIntersectedCameraCells(*camera);
208 if (interceptedCellsChanged) {
209 aboutTo_updateActiveEntities();
211 camera->refreshCamera();
214 if (_update_active_entities) {
215 _update_active_entities =
false;
217 updateActiveEntities();
218 updateVisibleEntities();
223 void aboutTo_updateActiveEntities() {
224 _update_active_entities =
true;
227 void updateActiveEntities();
229 void updateVisibleEntities();
231 void AddToGroup(
EmptyEntity* mEntity, Group mGroup)
233 groupedEmptyEntities[mGroup].emplace_back(mEntity);
236 void AddToGroup(
NodeEntity* mEntity, Group mGroup)
238 groupedNodeEntities[mGroup].emplace_back(mEntity);
241 void AddLinkToGroup(
LinkEntity* mEntity, Group mGroup)
243 groupedLinkEntities[mGroup].emplace_back(mEntity);
246 const std::vector<std::unique_ptr<Entity>>& getEntities()
const {
250 template <
typename T>
251 std::vector<T*> getVisible() {
252 if constexpr (std::is_same_v<T, EmptyEntity>) {
253 return visible_emptyEntities;
255 else if constexpr (std::is_same_v<T, NodeEntity>) {
256 return visible_nodes;
258 else if constexpr (std::is_same_v<T, LinkEntity>) {
259 return visible_links;
262 static_assert(
sizeof(T) == 0,
"Unsupported entity type.");
266 template <
typename T>
267 std::vector<T*>& getVisibleGroup(Group mGroup) {
268 if constexpr (std::is_same_v<T, EmptyEntity>) {
269 return visible_groupedEmptyEntities[mGroup];
271 else if constexpr (std::is_same_v<T, NodeEntity>) {
272 return visible_groupedNodeEntities[mGroup];
274 else if constexpr (std::is_same_v<T, LinkEntity>) {
275 return visible_groupedLinkEntities[mGroup];
278 static_assert(
sizeof(T) == 0,
"Unsupported entity type.");
282 template <
typename T>
283 std::vector<T*>& getGroup(Group mGroup) {
284 if constexpr (std::is_same_v<T, EmptyEntity>) {
285 return groupedEmptyEntities[mGroup];
287 else if constexpr (std::is_same_v<T, NodeEntity>) {
288 return groupedNodeEntities[mGroup];
290 else if constexpr (std::is_same_v<T, LinkEntity>) {
291 return groupedLinkEntities[mGroup];
294 static_assert(
sizeof(T) == 0,
"Unsupported entity type.");
298 template <
typename T,
typename... TArgs>
299 T& addEntityNoId(TArgs&&... mArgs)
301 T* e(
new T(*
this, std::forward<TArgs>(mArgs)...));
302 e->setId(negativeEntityId--);
303 std::unique_ptr<T> uPtr{ e };
304 entities.emplace_back(std::move(uPtr));
309 template <
typename T,
typename... TArgs>
310 T& addEntity(TArgs&&... mArgs)
312 T* e(
new T(*
this, std::forward<TArgs>(mArgs)...));
313 e->setId(lastEntityId++);
314 std::unique_ptr<T> uPtr{ e };
315 entities.emplace_back(std::move(uPtr));
320 void resetEntityId() {
324 Entity* getEntityFromId(
unsigned int mId) {
325 for (
auto& entity : entities) {
326 if (entity->getId() == mId && entity->isActive()) {
333 void clearAllEntities() {
334 for (
auto& group : groupedNodeEntities) {
337 for (
auto& group : groupedLinkEntities) {
343 void removeAllEntites() {
344 for (std::size_t group = Manager::groupBackgroundLayer; group != Manager::buttonLabels; group++) {
345 removeAllEntitiesFromGroup(group);
346 removeAllEntitiesFromLinkGroup(group);
350 void removeAllEntitiesFromGroup(Group mGroup) {
351 auto& entitiesInGroup = groupedNodeEntities[mGroup];
353 for (
Entity* entity : entitiesInGroup) {
357 void removeAllEntitiesFromLinkGroup(Group mGroup) {
358 auto& entitiesInGroup = groupedLinkEntities[mGroup];
360 for (
Entity* entity : entitiesInGroup) {
365 std::vector<Entity*> adjacentEntities(
Entity* mainEntity, Group group) {
366 std::vector<Entity*> nearbyEntities;
368 auto adjacentCells = grid->getAdjacentCells(*mainEntity, grid->getGridLevel());
370 for (
Cell* adjCell : adjacentCells) {
371 for (
auto& neighbor : adjCell->nodes) {
372 if (neighbor->hasGroup(group) && (neighbor != mainEntity) ) {
373 nearbyEntities.push_back(neighbor);
378 return nearbyEntities;
381 enum groupLabels : std::size_t
384 groupBackgroundLayer,
408 const std::unordered_map<Group, std::string> groupNames = {
409 {groupBackgroundLayer,
"groupBackgroundLayer" },
410 {panelBackground,
"panelBackground"},
413 { groupLinks_0,
"groupLinks_0" },
414 {groupGroupLinks_0,
"groupGroupLinks_0"},
415 {groupGroupLinks_1,
"groupGroupLinks_1"},
417 {groupArrowHeads_0,
"groupArrowHeads_0"},
419 { groupNodes_0,
"groupNodes_0" },
420 { groupGroupNodes_0,
"groupGroupNodes_0"},
421 { groupGroupNodes_1,
"groupGroupNodes_1"},
423 { groupEmpties,
"groupEmpties" },
424 { groupSphereEmpties,
"groupSphereEmpties" },
426 { groupColliders,
"groupColliders" },
427 { groupRenderSprites,
"groupRenderSprites" },
431 { buttonLabels,
"buttonLabels" },
434 std::string getGroupName(Group mGroup)
const;
436 void scanComponentNames(
const std::string& folderPath);
438 void setComponentNames();