From 5541f918c1547e7eb180a83a572cf307aa4b4930 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 22 Dec 2009 18:39:03 +0000 Subject: [PATCH] Make further use of the traverse functions always returning a valid result --- source/libmarklin/layout.cpp | 4 +--- source/libmarklin/train.cpp | 17 ++++++----------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/source/libmarklin/layout.cpp b/source/libmarklin/layout.cpp index 67d646b..1df37d3 100644 --- a/source/libmarklin/layout.cpp +++ b/source/libmarklin/layout.cpp @@ -145,9 +145,7 @@ void Layout::check_routes() Track *start = track; while(1) { - int out_ep = track->traverse(ep, trk_path); - if(out_ep<0) - break; + unsigned out_ep = track->traverse(ep, trk_path); Track *next = track->get_links()[out_ep]; if(!next || next == start) break; diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index 330bb70..4beda97 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -156,17 +156,12 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt) offset += get_real_speed(loco.get_speed())*(dt/Time::sec); if(offset>cur_track->get_type().get_path_length(path)) { - int out = cur_track->traverse(cur_track_ep, path); - if(out>=0) - { - Track *next = cur_track->get_link(out); - if(next) - cur_track_ep = next->get_endpoint_by_link(*cur_track); - cur_track = next; - offset = 0; - } - else - cur_track = 0; + unsigned out = cur_track->traverse(cur_track_ep, path); + Track *next = cur_track->get_link(out); + if(next) + cur_track_ep = next->get_endpoint_by_link(*cur_track); + cur_track = next; + offset = 0; } if(cur_track) -- 2.45.2