GEO mode for signals takes direction of next connection into account

This commit is contained in:
Sebastian
2024-10-30 02:00:40 +01:00
parent c63eeed1b4
commit ad7b0e4524
9 changed files with 251 additions and 73 deletions
+38 -21
View File
@@ -3,6 +3,7 @@
#include "connection.h"
#include "node-manager.h"
#include "raylib.h"
#include "raymath.h"
#include <map>
#include <vector>
@@ -23,41 +24,57 @@ class ConnectionManager{
}
int next(int current, int last){
std::vector<Connection*> paths;
std::vector<int> node_ids;
std::vector<Connection*> possible_connections;
std::vector<int> next_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);
node_ids.push_back( p.v1 == current ? p.v2 : p.v1 );
for(auto& c : connections){
if((c.v1 == current && c.v1_v2) || (c.v2 == current && c.v2_v1)) {
c.active = false;
possible_connections.push_back(&c);
next_node_ids.push_back( c.v1 == current ? c.v2 : c.v1 );
}
}
if(paths.size() == 2) {
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(possible_connections.size() == 2) {*/
/* int next = next_node_ids[0] == last ? next_node_ids[1] : next_node_ids[0];*/
/* if(possible_connections[0]->v1 == next || possible_connections[0]->v2 == next) possible_connections[0]->active = true;*/
/* if(possible_connections[1]->v1 == next || possible_connections[1]->v2 == next) possible_connections[1]->active = true;*/
/* return next;*/
/*}*/
if(paths.empty()) return -1;
if(possible_connections.empty()) return -1;
int return_path = 0;
if(nm->nodes.at(current).mode == Distribution::ROUNDROBIN){
float angle = -1;
if(nm->nodes.at(current).distributionMode == Distribution::GEOMETRIC){
Vec2D<float> coming_from = (nm->nodes.at(current).position - nm->nodes.at(last).position).norm();
int i = 0;
for(auto n : possible_connections){
int next_position = n->v1 == current ? n->v2 : n->v1;
float angle_v1_v2 = coming_from.norm().dot((nm->nodes.at(next_position).position - nm->nodes.at(current).position).norm());
if(angle_v1_v2 > angle) {
return_path = i;
angle = angle_v1_v2;
}
++i;
}
}
if(nm->nodes.at(current).distributionMode == Distribution::ROUNDROBIN){
if(counter.find(current) == counter.end()) {
counter[current] = 0;
} else {
counter[current] = (counter[current] + 1) % paths.size();
counter[current] = (counter[current] + 1) % possible_connections.size();
return_path = counter[current];
}
}
if(nm->nodes.at(current).mode == Distribution::RANDOM){
return_path = rand() % paths.size();
if(nm->nodes.at(current).distributionMode == Distribution::RANDOM){
return_path = rand() % possible_connections.size();
}
paths.at(return_path)->active = true;
return paths.at(return_path)->v1 == current ? paths.at(return_path)->v2 : paths.at(return_path)->v1;
possible_connections.at(return_path)->active = true;
return possible_connections.at(return_path)->v1 == current ? possible_connections.at(return_path)->v2 : possible_connections.at(return_path)->v1;
}
void addConnection(int from, int to){