TazGraph Project v0.1.0
Loading...
Searching...
No Matches
GECSEntityTypesNode.h
1#pragma once
2
3#include "./GECSEntityTypes.h"
4
5class Node : public NodeEntity {
6private:
7
8public:
9
10 Node(Manager& mManager) : NodeEntity(mManager) {
11
12
13 }
14
15 void addToGroup(Group mGroup) override {
16 Entity::addToGroup(mGroup);
17 manager.AddToGroup(this, mGroup);
18 }
19
20 void removeGroup(Group mGroup) override {
21 Entity::removeGroup(mGroup);
22 manager.aboutTo_updateActiveEntities();
23 }
24
25 virtual ~Node() {
26
27 }
28
29 void update(float deltaTime)
30 {
31 //cellUpdate();
32
33 Entity::update(deltaTime);
34 }
35
36 void cellUpdate() override {
37 if (this->ownerCell) {
38 //this->GetComponent<TransformComponent>().update(0.0f);
39 Cell* newCell = manager.grid->getCell(*this, manager.grid->getGridLevel());
40 if (newCell != this->ownerCell) {
41 removeFromCell();
42 manager.grid->addNode(this, newCell);
43 }
44
45 {
46 std::scoped_lock lock(manager.movedNodesMutex);
47
48 manager.movedNodes.push_back(getId());
49 }
50
51 // update arrowheads
52 for (auto& linkId : inLinks) {
53 auto* link = dynamic_cast<LinkEntity*>(manager.getEntityFromId(linkId));
54 if (link->type == LinkEntity::ConnectionType::PORT_TO_PORT)
55 link->updateArrowHeads();
56
57 auto* nodeFrom = dynamic_cast<NodeEntity*>(manager.getEntityFromId(link->getFromNode()));
58 for (auto& depthLinkId : nodeFrom->getInLinks()) {
59 auto* depthLink = dynamic_cast<LinkEntity*>(manager.getEntityFromId(depthLinkId));
60 if (depthLink->type == LinkEntity::ConnectionType::PORT_TO_PORT)
61 depthLink->updateArrowHeads();
62 }
63 for (auto& depthLinkId : dynamic_cast<NodeEntity*>(manager.getEntityFromId(link->getFromNode()))->getOutLinks()) {
64 auto* depthLink = dynamic_cast<LinkEntity*>(manager.getEntityFromId(depthLinkId));
65 if (depthLink->type == LinkEntity::ConnectionType::PORT_TO_PORT)
66 depthLink->updateArrowHeads();
67 }
68 }
69 for (auto& linkId : outLinks) {
70 auto* link = dynamic_cast<LinkEntity*>(manager.getEntityFromId(linkId));
71 if (link->type == LinkEntity::ConnectionType::PORT_TO_PORT)
72 link->updateArrowHeads();
73 for (auto& depthLinkId : dynamic_cast<NodeEntity*>(manager.getEntityFromId(link->getToNode()))->getInLinks()) {
74 auto* depthLink = dynamic_cast<LinkEntity*>(manager.getEntityFromId(depthLinkId));
75 if (depthLink->type == LinkEntity::ConnectionType::PORT_TO_PORT)
76 depthLink->updateArrowHeads();
77 }
78 for (auto& depthLinkId : dynamic_cast<NodeEntity*>(manager.getEntityFromId(link->getToNode()))->getOutLinks()) {
79 auto* depthLink = dynamic_cast<LinkEntity*>(manager.getEntityFromId(depthLinkId));
80 if (depthLink->type == LinkEntity::ConnectionType::PORT_TO_PORT)
81 depthLink->updateArrowHeads();
82 }
83 }
84 }
85 }
86
87 void imgui_print() override {
88 glm::vec2 position = this->GetComponent<TransformComponent>().getPosition(); // Make sure Entity class has a getPosition method
89 ImGui::Text("TazPosition: (%.2f, %.2f)", position.x, position.y);
90
91
92 }
93
94 void imgui_display() override {
95 ImGui::Text("Display Info Here Node");
96 }
97
98 void destroy() {
99 Entity::destroy();
100 manager.aboutTo_updateActiveEntities();//? cant have it at destroy in baseclass
101 }
102
103 void addPorts() {
104 auto createPort = [this](NodePorts portName, const glm::vec3& localPosition, bool isHorizontal) {
105 const char* t_portName = NodePorts_ToString(portName);
106
107 if (children.contains(t_portName)) {
108 TAZ_ERROR(
109 std::string("Port already exists: ") + t_portName);
110 return;
111 }
112
113 auto& port = getManager()->addEntityFromParent<Empty>(this, t_portName);
114 port.addToGroup(Manager::groupPorts);
115 port.addComponent<TransformComponent>(glm::vec3(0), glm::vec3(0), 1.0f);
116
117
118 children[t_portName] = port.getId();
119 getManager()->getEntityFromId(children[t_portName])->setParentEntity(this);
120 getManager()->getEntityFromId(children[t_portName])->GetComponent<TransformComponent>().local_normal_position = localPosition;
121 getManager()->getEntityFromId(children[t_portName])->GetComponent<TransformComponent>().initChild();
122 getManager()->getEntityFromId(children[t_portName])->addComponent<PortComponent>(isHorizontal);
123 getManager()->getEntityFromId(children[t_portName])->update(0.0f);
124 };
125
126 // Create all ports using the lambda
127 createPort(NodePorts::LEFT, glm::vec3(-1.0f, 0.0f, 0.0f), true);
128 createPort(NodePorts::RIGHT, glm::vec3(1.0f, 0.0f, 0.0f), true);
129 createPort(NodePorts::TOP, glm::vec3(0.0f, -1.0f, 0.0f), false);
130 createPort(NodePorts::BOTTOM, glm::vec3(0.0f, 1.0f, 0.0f), false);
131
132 }
133
134 void removePorts() override {
135 for (auto portName : { NodePorts::LEFT, NodePorts::RIGHT, NodePorts::TOP, NodePorts::BOTTOM }) {
136
137 const char* t_portName = NodePorts_ToString(portName);
138
139 if (children.contains(t_portName)) {
140 getManager()->getEntityFromId(children[t_portName])->destroy();
141 for (auto& slot : getManager()->getEntityFromId(children[t_portName])->children)
142 {
143 auto* slotEnt = getManager()->getEntityFromId(slot.second);
144 slotEnt->destroy();
145 }
146 getManager()->getEntityFromId(children[t_portName])->children.clear();
147 children.erase(t_portName);
148 }
149 }
150 }
151
152 void removeSlots() override {
153 for (auto portName : { NodePorts::LEFT, NodePorts::RIGHT, NodePorts::TOP, NodePorts::BOTTOM }) {
154 const char* t_portName = NodePorts_ToString(portName);
155
156 if (children.contains(t_portName)) {
157 for (auto slot : getManager()->getEntityFromId(children[t_portName])->children)
158 {
159 getManager()->getEntityFromId(slot.second)->destroy();
160 }
161 getManager()->getEntityFromId(children[t_portName])->children.clear();
162 }
163 }
164 }
165
166};
167
168
Definition GECSEntityTypesEmpty.h:5
std::map< EntityID, EntityID > children
child_index(id) -> real_entity_id
Definition GECS.h:248
Manager & manager
the object doesnt move, so we can have pointer
Definition GECS.h:241
T & addComponent(TArgs &&... mArgs)
have addScript function
Definition GECS.h:345
Definition GECSEntity.h:108
Definition GECSManager.h:20
Definition GECSEntity.h:40
Definition GECSEntityTypesNode.h:5
Definition PortComponent.h:8
Definition TransformComponent.h:7
Definition CellEntity.h:6