From 29b131b59ba562f996a338a453745e5a4dfad5b7 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 15 Oct 2010 19:15:10 +0000 Subject: [PATCH] Reserve two ids for double-address turnouts 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 | 7 +++++-- source/libmarklin/layout.h | 2 +- source/libmarklin/track.cpp | 8 ++++---- source/libmarklin/train.cpp | 4 +++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/libmarklin/layout.cpp b/source/libmarklin/layout.cpp index d327815..fc3d86e 100644 --- a/source/libmarklin/layout.cpp +++ b/source/libmarklin/layout.cpp @@ -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) diff --git a/source/libmarklin/layout.h b/source/libmarklin/layout.h index 4e7bcd9..0035e7a 100644 --- a/source/libmarklin/layout.h +++ b/source/libmarklin/layout.h @@ -77,7 +77,7 @@ public: void add_track(Track &); const std::set &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; diff --git a/source/libmarklin/track.cpp b/source/libmarklin/track.cpp index 74e51ac..c940e1c 100644 --- a/source/libmarklin/track.cpp +++ b/source/libmarklin/track.cpp @@ -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; } } diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index f0a0bf3..bd813d3 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -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"); } -- 2.45.2