minimal gui functional

This commit is contained in:
Sebastian
2024-10-16 02:26:02 +02:00
parent b74c63a115
commit add8749bb9
6 changed files with 93 additions and 55 deletions
+20 -9
View File
@@ -2,6 +2,7 @@
#include "connection.h"
#include <map>
#include <vector>
class ConnectionManager{
@@ -13,30 +14,40 @@ class ConnectionManager{
std::map<Node*, int> counter;
Node* next(Node* current){
Node* next(Node* current, Node* last){
std::vector<Connection*> paths;
bool last_ok = false;
for(auto& p : connections){
if((p.v1 == current && p.v1_v2) || (p.v2 == current && p.v2_v1)) {
if(((p.v1 == current && p.v1_v2) || (p.v2 == current && p.v2_v1)) && (p.v1 != last || p.v2 != last)) {
p.active = false;
paths.push_back(&p);
}
if(p.v1 == last || p.v2 == last) last_ok = true;
}
if(paths.empty() && last_ok) return last;
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];
if(current->mode == Distribution::ROUNDROBIN){
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;
if(current->mode == Distribution::RANDOM){
return_path = rand() % paths.size();
}
paths.at(return_path)->active = true;
return paths.at(return_path)->v1 == current ? paths.at(return_path)->v2 : paths.at(return_path)->v1;
}
void draw(){
std::erase_if(connections, [](Connection c){ return c.remove == true;});
for(auto& c : connections){
c.draw();
}