From: Mikko Rasa Date: Thu, 15 Aug 2013 15:06:37 +0000 (+0300) Subject: Add a utility function to get path length from Track X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a5e1363ceac1ab552849640c9021fcda362c4416;p=r2c2.git Add a utility function to get path length from Track This shortens the incantation to get the length of the active path. --- diff --git a/source/libr2c2/blockallocator.cpp b/source/libr2c2/blockallocator.cpp index 2e81677..674722b 100644 --- a/source/libr2c2/blockallocator.cpp +++ b/source/libr2c2/blockallocator.cpp @@ -79,7 +79,7 @@ bool BlockAllocator::start_from(const BlockIter &block) break; blocks_to_reserve.push_back(b); for(TrackIter t=b.track_iter(); (t && &t->get_block()==&*b); t=t.next()) - remaining_length -= t->get_type().get_path_length(t->get_active_path()); + remaining_length -= t->get_path_length(); if(remaining_length<=0) break; } diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index 8ecb9b9..4708db5 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -183,6 +183,13 @@ void Track::set_active_path(unsigned p) layout.get_driver().set_turnout(turnout_id, p); } +float Track::get_path_length(int p) const +{ + if(p<0) + p = active_path; + return type.get_path_length(p); +} + OrientedPoint Track::get_point(unsigned epi, unsigned path, float d) const { OrientedPoint p = type.get_point(epi, path, d); diff --git a/source/libr2c2/track.h b/source/libr2c2/track.h index f169c0a..79365af 100644 --- a/source/libr2c2/track.h +++ b/source/libr2c2/track.h @@ -77,6 +77,7 @@ public: void set_active_path(unsigned); unsigned get_active_path() const { return active_path; } bool is_path_changing() const { return path_changing; } + float get_path_length(int = -1) const; OrientedPoint get_point(unsigned, unsigned, float) const; OrientedPoint get_point(unsigned, float) const; diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index 07461b8..7e4a690 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -530,14 +530,14 @@ float Train::get_reserved_distance_until(const Block *until_block) const if(reverse) track = track.reverse(); else - result = track->get_type().get_path_length(track->get_active_path())-result; + result = track->get_path_length()-result; result -= veh.get_type().get_length()/2; BlockIter block = track.block_iter(); // Count remaining distance in the vehicle's current block for(track=track.next(); &track->get_block()==&*block; track=track.next()) - result += track->get_type().get_path_length(track->get_active_path()); + result += track->get_path_length(); const BlockIter &last = allocator.last(); if(&*block==&*last)