30 std::string requestedMap;
31 std::atomic<bool> managerChangeRequested{
false };
42 ImGui::ComboAutoSelectData data;
43 ImGui::ComboAutoSelectData pathData;
46 std::vector<std::string> fileNames;
47 std::vector<std::string> pollingFileNames;
48 std::vector<std::string> pathsFileNames;
49 std::string pathLoading;
51 bool filesLoaded =
false;
54 bool startingNew =
false;
56 bool loadingPath =
false;
57 bool goingBack =
false;
59 std::map<int, NodeEntity*> mapSimToGraphNodes;
60 std::map<int, LinkEntity*> mapSimToGraphLinks;
61 std::map<int, EmptyEntity*> mapSimToGraphPaths;
63 void setMapToLoad(
const std::string& name) {
64 if (managerChangeRequested.load() ==
true)
return;
67 managerChangeRequested.store(
true);
70 std::string getMapToLoad() {
74 bool getManagerChangeRequested() {
75 return managerChangeRequested.load();
78 void setManagerChangeRequested(
bool m_request) {
79 managerChangeRequested.store(m_request);
82 void setPathLoading(
bool loading)
84 loadingPath = loading;
91 void setNewMap(
bool m_startingNew)
93 startingNew = m_startingNew;
96 void setLoading(
bool m_loading)
121 std::string getPathLoading() {
125 void SetGoingBack(
bool m_goingBack) {
126 goingBack = m_goingBack;
129 void updateFileNamesInAssets() {
131 const std::string path =
"assets/Maps";
132 for (
const auto& entry : fs::directory_iterator(path)) {
133 if (entry.is_regular_file()) {
134 fileNames.push_back(entry.path().filename().string());
139 void updatePathFileNamesInAssets() {
140 pathsFileNames.clear();
141 const std::string path =
"assets/Paths";
142 for (
const auto& entry : fs::directory_iterator(path)) {
143 if (entry.is_regular_file()) {
144 pathsFileNames.push_back(entry.path().filename().string());
147 pathsFileNames.push_back(
">Reset");
150 void ReloadAccessibleFiles() {
152 updateFileNamesInAssets();
153 updatePathFileNamesInAssets();
159 void applyStep(
Manager& manager,
int transitionToStep)
163 auto stepIt = manager.steps.begin();
164 std::advance(stepIt, transitionToStep);
166 for (
auto& node : stepIt->nodes) {
177 tc.position = node.second.position;
179 tc.size = glm::vec3(node.second.size);
187 for (
auto& link : stepIt->links) {
192 lwc.src_color = link.second.color;
193 lwc.dest_color = link.second.color;
194 lwc.width = link.second.width;
198 for (
auto& simPaths : DataManager::getInstance().mapSimToGraphPaths) {
200 auto toRemove = pathLinks;
202 for (
auto pathLinkId : toRemove) {
204 Entity* pathLink = manager.getEntityFromId(pathLinkId);
210 for (
size_t i = 0; i < stepIt->paths.size(); i++) {
212 auto stepIt = manager.steps.begin();
213 std::advance(stepIt, transitionToStep);
215 auto& path = stepIt->paths[i];
219 plc.color = path.second.color;
220 plc.width = path.second.width;
222 for (
auto linkId : path.second.link_ids) {
225 for (
auto& link : DataManager::getInstance().mapSimToGraphLinks) {
226 if (link.second->getId() == linkId) {
227 linkEntity = link.second;
232 if (!linkEntity)
break;
234 int idA = std::get<int>(linkEntity->getFromNode());
235 int idB = std::get<int>(linkEntity->getToNode());
238 auto& link = manager.addEntity<
Link>((int)idA, (
int)idB);
239 link.addToGroup(Manager::groupPathLinks);
244 manager.grid->addLink(&link, manager.grid->getGridLevel());
253 if (manager.arrowheadsEnabled) {
254 for (
auto* link : manager.getGroup<
LinkEntity>(Manager::groupPathLinks))
256 auto* link_entity =
dynamic_cast<LinkEntity*
>(link);
258 link_entity->setConnectionType(LinkEntity::ConnectionType::PORT_TO_PORT);
259 link_entity->updateConnection();
262 for (
auto* pathLinker : manager.getGroup<
EmptyEntity>(Manager::groupPathLinksHolder))
271 sim_dump::UInt32 sourceStepIndex
274 auto src = std::find_if(
275 manager.steps.begin(),
278 return s.step_index == sourceStepIndex;
282 if (src == manager.steps.end()) {
283 TAZ_ERROR(
"Source SimulationStep not found");
293 void reindexSteps(
Manager& manager)
295 sim_dump::UInt32 idx = 0;
296 for (
auto& step : manager.steps) {
297 step.step_index = idx++;
301 void addSimulationStep(
Manager& manager) {
304 new_step.step_index = manager.steps.back().step_index + 1;
305 new_step.timestamp = manager.steps.back().timestamp + 0.01f;
307 manager.steps.push_back(new_step);
309 reindexSteps(manager);
313 void addSimulationStep(
Manager& manager, sim_dump::UInt32 step,
double timestamp, sim_dump::UInt32 copyStep) {
316 if (copyStep != -1) {
317 new_step = deepCopySimulationStepTo(manager, copyStep);
323 new_step.step_index = step;
324 new_step.timestamp = timestamp;
326 if (step >= manager.steps.size()) {
327 manager.steps.push_back(new_step);
331 auto it = manager.steps.begin();
332 std::advance(it, step);
334 manager.steps.insert(it, new_step);
337 reindexSteps(manager);
340 void removeSimulationStep(
Manager& manager, sim_dump::UInt32 step) {
341 if (step >= manager.steps.size()) {
342 TAZ_ERROR(
"SimulationStep to remove not found");
345 auto it = manager.steps.begin();
346 std::advance(it, step);
348 manager.steps.erase(it);
350 reindexSteps(manager);
356 std::ostringstream out;
358 out <<
"=== Simulation Step ===\n";
359 out <<
"Index: " << step.step_index <<
"\n";
360 out <<
"Timestamp: " << step.timestamp <<
"\n";
363 out <<
"Nodes (" << step.nodes.size() <<
")\n";
364 for (
const auto& [node, simNode] : step.nodes) {
365 out <<
" Node ptr: " << node
366 <<
" pos: (" << simNode.position.x
367 <<
", " << simNode.position.y
368 <<
", " << simNode.position.z <<
")"
369 <<
" size: " << simNode.size.value
374 out <<
"Links (" << step.links.size() <<
")\n";
375 for (
const auto& [link, simLink] : step.links) {
376 out <<
" Link ptr: " << link
377 <<
" width: " << simLink.width
382 out <<
"Paths (" << step.paths.size() <<
")\n";
383 for (
const auto& [pathEntity, simPath] : step.paths) {
384 out <<
" Path ptr: " << pathEntity
385 <<
" width: " << simPath.width
388 for (EntityID
id : simPath.link_ids) {
389 out << EntityIDUtils::toString(
id) <<
" ";
394 out <<
"=======================\n";
399 std::string simulationStepToString(
const Manager& manager,
int stepIndex)
401 std::ostringstream out;
403 auto it = std::find_if(
404 manager.steps.begin(),
406 [&](
const SimulationStep& s) { return s.step_index == stepIndex; }
409 if (it != manager.steps.end()) {
410 out << simulationStepToString(*it);
413 out <<
"SimulationStep " << stepIndex <<
" not found.\n";
419 void connectClient(
int port) {
422 WSAStartup(MAKEWORD(2, 2), &wsa);
425 socket_t sock = socket(AF_INET, SOCK_STREAM, 0);
427 perror(
"socket error");
432 addr.sin_family = AF_INET;
433 addr.sin_port = htons((u_short)port);
434 inet_pton(AF_INET,
"127.0.0.1", &addr.sin_addr);
436 if (connect(sock, (sockaddr*)&addr,
sizeof(addr)) < 0) {
437 perror(
"connect error");
443 while (fgets(input,
sizeof(input), stdin)) {
444 send(sock, input, (
int)strlen(input), 0);