node deletion with connection deletion and signal redistribution implemented
This commit is contained in:
+14
-11
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "connection.h"
|
||||
#include "node-manager.h"
|
||||
#include "raylib.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
@@ -9,40 +10,42 @@ class ConnectionManager{
|
||||
|
||||
public:
|
||||
|
||||
ConnectionManager() {}
|
||||
ConnectionManager(NodeManager *nm) : nm(nm) {}
|
||||
|
||||
NodeManager *nm;
|
||||
|
||||
std::vector<Connection> connections;
|
||||
|
||||
std::map<Node*, int> counter;
|
||||
std::map<int, int> counter;
|
||||
|
||||
void reset(){
|
||||
counter.clear();
|
||||
}
|
||||
|
||||
Node* next(Node* current, Node* last){
|
||||
int next(int current, int last){
|
||||
std::vector<Connection*> paths;
|
||||
std::vector<Node*> nodes;
|
||||
std::vector<int> node_ids;
|
||||
|
||||
for(auto& p : connections){
|
||||
if((p.v1 == current && p.v1_v2) || (p.v2 == current && p.v2_v1)) {
|
||||
p.active = false;
|
||||
paths.push_back(&p);
|
||||
nodes.push_back( p.v1 == current ? p.v2 : p.v1 );
|
||||
node_ids.push_back( p.v1 == current ? p.v2 : p.v1 );
|
||||
}
|
||||
}
|
||||
|
||||
if(paths.size() == 2) {
|
||||
Node* next = nodes[0] == last ? nodes[1] : nodes[0];
|
||||
int next = node_ids[0] == last ? node_ids[1] : node_ids[0];
|
||||
if(paths[0]->v1 == next || paths[0]->v2 == next) paths[0]->active = true;
|
||||
if(paths[1]->v1 == next || paths[1]->v2 == next) paths[1]->active = true;
|
||||
return next;
|
||||
}
|
||||
|
||||
if(paths.empty()) return nullptr;
|
||||
if(paths.empty()) return -1;
|
||||
|
||||
int return_path = 0;
|
||||
|
||||
if(current->mode == Distribution::ROUNDROBIN){
|
||||
if(nm->nodes.at(current).mode == Distribution::ROUNDROBIN){
|
||||
if(counter.find(current) == counter.end()) {
|
||||
counter[current] = 0;
|
||||
} else {
|
||||
@@ -50,15 +53,15 @@ class ConnectionManager{
|
||||
return_path = counter[current];
|
||||
}
|
||||
}
|
||||
if(current->mode == Distribution::RANDOM){
|
||||
if(nm->nodes.at(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 addConnection(Node *from, Node *to){
|
||||
connections.emplace_back(from, to);
|
||||
void addConnection(int from, int to){
|
||||
connections.emplace_back(&nm->nodes, from, to);
|
||||
}
|
||||
|
||||
void drawConnections(Vec2D<float> *mouse_pos, Camera2D *cam){
|
||||
|
||||
Reference in New Issue
Block a user