two direction connections with blockers working
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user