X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Fblock.cpp;h=03cb2dc3fa60c259f64590ed015a58f789c11c0f;hb=80e10207bee4d774f3015a5e946d463d2c828029;hp=87654e4387df997ac5b125dac1643a4bdd1cf47c;hpb=bc955b09faf8365a72d07bb5ee1253c9b958c897;p=r2c2.git diff --git a/source/libmarklin/block.cpp b/source/libmarklin/block.cpp index 87654e4..03cb2dc 100644 --- a/source/libmarklin/block.cpp +++ b/source/libmarklin/block.cpp @@ -1,3 +1,10 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + #include "control.h" #include "block.h" #include "tracktype.h" @@ -31,7 +38,7 @@ Block::Block(TrafficManager &tm, Track &start): for(unsigned i=0; iget_sensor_id()==sensor_id) + if(links[i]->get_sensor_id()==sensor_id && !links[i]->get_turnout_id() && !track->get_turnout_id()) { queue.push_back(links[i]); tracks.insert(links[i]); @@ -59,7 +66,7 @@ int Block::get_endpoint_by_link(const Block &other) const return -1; } -int Block::traverse(unsigned epi) const +int Block::traverse(unsigned epi, float *len) const { if(epi>=endpoints.size()) throw InvalidParameterValue("Endpoint index out of range"); @@ -68,6 +75,9 @@ int Block::traverse(unsigned epi) const Track *track=ep.track; unsigned track_ep=ep.track_ep; + if(len) + *len=0; + while(1) { unsigned cur_route=0; @@ -78,20 +88,22 @@ int Block::traverse(unsigned epi) const cur_route=turnout.get_route(); } + if(len) + *len+=track->get_type().get_route_length(cur_route); + int other_ep=track->traverse(track_ep, cur_route); if(other_ep<0) - return 0; + return -1; for(unsigned i=0; i(other_ep)) return i; Track *next=track->get_link(other_ep); + if(tracks.count(next)==0) + return -1; track_ep=next->get_endpoint_by_link(*track); track=next; - - if(tracks.count(track)==0) - return -1; } }