]> git.tdb.fi Git - r2c2.git/commitdiff
Add a utility function to get path length from Track
authorMikko Rasa <tdb@tdb.fi>
Thu, 15 Aug 2013 15:06:37 +0000 (18:06 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 15 Aug 2013 15:06:37 +0000 (18:06 +0300)
This shortens the incantation to get the length of the active path.

source/libr2c2/blockallocator.cpp
source/libr2c2/track.cpp
source/libr2c2/track.h
source/libr2c2/train.cpp

index 2e816775f7dfa7c86683a559e3f1f638e436b33f..674722bb9d21b6951bd0f8b0405fad8e4ecd4db3 100644 (file)
@@ -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;
        }
index 8ecb9b9bac00833eaa70190982fcb1933b43e9ae..4708db5d40de6c79d26de28ef61af696afe6f48d 100644 (file)
@@ -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);
index f169c0a92671c7ac9a458aca9a36ae327986da3b..79365afbcceb04c8d1e291ab7b37fee54d85c9a9 100644 (file)
@@ -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;
index 07461b80a9558ecc4000c176bf73565e4c6d922b..7e4a6904610a7b51ee19940e7f4d9cc1812f95aa 100644 (file)
@@ -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)