X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/9cb06c6560f458cc3a8c1d1b2f354e54d2458dd0..9322e49b932d824e5664aa8c0e0f9a41464537b1:/Model/src/splitter.cpp?ds=sidebyside diff --git a/Model/src/splitter.cpp b/Model/src/splitter.cpp index a273789..cf8804a 100644 --- a/Model/src/splitter.cpp +++ b/Model/src/splitter.cpp @@ -10,6 +10,7 @@ Splitter::Splitter(const std::string &_name):Transport(_name) out_slots = 2; max_flow = actual_flow = 0.0f; updated = true; + out_on_zero = out_ready = 0; } Splitter::~Splitter() @@ -33,12 +34,18 @@ void Splitter::recieve_msg(int msg, IConector *who, void *data) } // Me preguntan por el flujo máximo. // Primero me actualizo, y luego respondo - actual_flow = *((float *)data); + float tmp = *((float *)data); + + if (tmp < actual_flow) actual_flow = tmp; if (max_flow < actual_flow) actual_flow = max_flow; - actual_flow /= 2.0f; + if (out_on_zero == 0) + actual_flow /= 2.0f; + if (actual_flow == 0) { + out_ready = 2; + } send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &actual_flow); // Listo, mi flujo ahora es el doble de lo que me pueden @@ -50,16 +57,27 @@ void Splitter::recieve_msg(int msg, IConector *who, void *data) break; case MSG_RESPONSE_MAX_FLOW: { float max = *((float *)data); + if (out_ready == 2) break; #ifdef DEBUG std::cout << name << ":Split " << max << std::endl; #endif if (pos == OUT) { if (max == 0) { - actual_flow = max_flow; + out_on_zero++; + switch (out_on_zero) { + case 1: + if (out_ready == 0) { + actual_flow = max_flow; + } + break; + case 2: + actual_flow = 0.0; + } } else { if (max < actual_flow) actual_flow = max; if (max_flow < actual_flow) actual_flow = max_flow; } + out_ready++; } else { if (((2*max) < actual_flow) && (max != 0)) actual_flow = 2*max; @@ -98,5 +116,6 @@ void Splitter::simulate() #endif updated = false; color_updated = false; + out_on_zero = out_ready = 0; }