From: Mikko Rasa Date: Fri, 15 Feb 2013 08:56:56 +0000 (+0200) Subject: Rearrange block reservations to present consistent state in signal_reserved X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=4086edb;p=r2c2.git Rearrange block reservations to present consistent state in signal_reserved --- diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index 936f74a..599f2dc 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -430,10 +430,13 @@ void Train::place(Block &block, unsigned entry) set_active(false); accurate_position = false; + blocks.push_back(BlockIter(&block, entry)); if(!block.reserve(this)) + { + blocks.pop_back(); return; + } - blocks.push_back(BlockIter(&block, entry)); if(reverse) { TrackIter track = BlockIter(&block, entry).reverse().track_iter(); @@ -648,8 +651,9 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt) if(dist>10*layout.get_catalogue().get_scale()) { - blocks.front()->reserve(0); + Block &block = *blocks.front(); blocks.pop_front(); + block.reserve(0); } } } @@ -967,9 +971,11 @@ void Train::reserve_more() } } + blocks.push_back(block); bool reserved = block->reserve(this); if(!reserved) { + blocks.pop_back(); /* We've found another train. If it wants to exit the block from the same endpoint we're trying to enter from or the other way around, treat it as coming towards us. Otherwise treat it as going in the @@ -1000,7 +1006,11 @@ void Train::reserve_more() /* Ask a lesser priority train going to the same direction to free the block for us */ if(other_train->free_block(*block)) - reserved = block->reserve(this); + { + blocks.push_back(block); + if(!(reserved = block->reserve(this))) + blocks.pop_back(); + } } else if(other_train!=yielding_to && (other_prioreserve(&obj); obj.blocks.push_back(BlockIter(blk, entry)); + blk->reserve(&obj); if(blk->get_sensor_id()) obj.layout.get_driver().set_sensor(blk->get_sensor_id(), true);