two direction connections with blockers working

This commit is contained in:
Sebastian
2024-10-15 02:59:26 +02:00
parent 313bf767c6
commit b74c63a115
5 changed files with 101 additions and 33 deletions
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include "connection.h"
#include <map>
class ConnectionManager{
public:
ConnectionManager() {}
std::vector<Connection> connections;
std::map<Node*, int> counter;
Node* next(Node* current){
std::vector<Connection*> paths;
for(auto& p : connections){
if((p.v1 == current && p.v1_v2) || (p.v2 == current && p.v2_v1)) {
p.active = false;
paths.push_back(&p);
}
}
if(paths.empty()) return nullptr;
int return_path = 0;
if(counter.find(current) == counter.end()) {
counter[current] = 0;
} else {
counter[current] = (counter[current] + 1) % paths.size();
return_path = counter[current];
}
paths[return_path]->active = true;
return paths[return_path]->v1 == current ? paths[return_path]->v2 : paths[return_path]->v1;
}
void draw(){
for(auto& c : connections){
c.draw();
}
}
};