]> git.tdb.fi Git - r2c2.git/commitdiff
Reserve two ids for double-address turnouts
authorMikko Rasa <tdb@tdb.fi>
Fri, 15 Oct 2010 19:15:10 +0000 (19:15 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 15 Oct 2010 19:15:10 +0000 (19:15 +0000)
Report track z coordinate correctly for turnouts
Don't reserve more blocks when arriving at end of route
Add a small offset when placing a train after loading

source/libmarklin/layout.cpp
source/libmarklin/layout.h
source/libmarklin/track.cpp
source/libmarklin/train.cpp

index d32781578243a1631634d23ecf78e7223387ec93..fc3d86ed9e39cc51b6b4fef1733c1546184cf5a0 100644 (file)
@@ -73,9 +73,12 @@ void Layout::remove_track(Track &t)
        }
 }
 
-unsigned Layout::allocate_turnout_id()
+unsigned Layout::allocate_turnout_id(bool dbl)
 {
-       return next_turnout_id++;
+       unsigned result = next_turnout_id++;
+       if(dbl)
+               ++next_turnout_id;
+       return result;
 }
 
 void Layout::add_block(Block &b)
index 4e7bcd96ce83a8da61cd1396cfab41d90168cd3a..0035e7a5481fdadc37ea29d51dd1903ed7863d84 100644 (file)
@@ -77,7 +77,7 @@ public:
        void add_track(Track &);
        const std::set<Track *> &get_tracks() const { return tracks; }
        void remove_track(Track &);
-       unsigned allocate_turnout_id();
+       unsigned allocate_turnout_id(bool);
 
        void add_block(Block &);
        Block &get_block(unsigned) const;
index 74e51acab73fddb2246b750d23a3339b9e2dab24..c940e1cd93d15e517f1501506e228172362aba6c 100644 (file)
@@ -22,7 +22,7 @@ Track::Track(Layout &l, const TrackType &t):
        rot(0),
        slope(0),
        flex(false),
-       turnout_id(type.is_turnout() ? layout.allocate_turnout_id() : 0),
+       turnout_id(type.is_turnout() ? layout.allocate_turnout_id(type.is_double_address()) : 0),
        sensor_id(0),
        links(type.get_endpoints().size()),
        active_path(0)
@@ -310,7 +310,7 @@ TrackPoint Track::get_point(unsigned epi, unsigned path, float d) const
        float c = cos(rot);
        float s = sin(rot);
 
-       p.pos = Point(pos.x+c*p.pos.x-s*p.pos.y, pos.y+s*p.pos.x+c*p.pos.y, 0);
+       p.pos = Point(pos.x+c*p.pos.x-s*p.pos.y, pos.y+s*p.pos.x+c*p.pos.y, pos.z);
        p.dir += rot;
        if(type.get_endpoints().size()==2)
        {
@@ -318,12 +318,12 @@ TrackPoint Track::get_point(unsigned epi, unsigned path, float d) const
                float grade = slope/len;
                if(epi==0)
                {
-                       p.pos.z = pos.z+grade*d;
+                       p.pos.z += grade*d;
                        p.grade = grade;
                }
                else
                {
-                       p.pos.z = pos.z+slope-grade*d;
+                       p.pos.z += slope-grade*d;
                        p.grade = -grade;
                }
        }
index f0a0bf32dcf502c4e6728ed79812a40b90ef5906..bd813d3fbe4cdc3ed380bcc8d2878d770b6e2560 100644 (file)
@@ -423,6 +423,7 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt)
        }
        else if(end_of_route && rsv_blocks.empty())
        {
+               set_active(false);
                signal_arrived.emit();
                set_route(0);
        }
@@ -1124,7 +1125,8 @@ void Train::Loader::finish()
        {
                const BlockRef &blkref = obj.cur_blocks.front();
                const Block::Endpoint &bep = blkref.block->get_endpoints()[blkref.entry];
-               obj.vehicles.back()->place(*bep.track, bep.track_ep, 0, Vehicle::BACK_BUFFER);
+               float offset = 2*obj.layout.get_catalogue().get_scale();
+               obj.vehicles.back()->place(*bep.track, bep.track_ep, offset, Vehicle::BACK_BUFFER);
 
                obj.set_status("Stopped");
        }