X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fblockallocator.cpp;h=79274b77ded54cd6df67fb7e38329e36a2a4b03a;hb=a44355019e5a27da0d5e5287aae74864e4122e1f;hp=5870a6d00474ccdcffa2478da7bb38ffc425e958;hpb=6eba064c477836843a2647d777e95823a96dda43;p=r2c2.git diff --git a/source/libr2c2/blockallocator.cpp b/source/libr2c2/blockallocator.cpp index 5870a6d..79274b7 100644 --- a/source/libr2c2/blockallocator.cpp +++ b/source/libr2c2/blockallocator.cpp @@ -39,6 +39,7 @@ BlockAllocator::BlockAllocator(Train &t): Layout &layout = train.get_layout(); layout.signal_block_reserved.connect(sigc::mem_fun(this, &BlockAllocator::block_reserved)); layout.signal_sensor_state_changed.connect(sigc::mem_fun(this, &BlockAllocator::sensor_state_changed)); + layout.get_driver().signal_halt.connect(sigc::mem_fun(this, &BlockAllocator::halt_event)); const set &tracks = layout.get_all(); for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) @@ -190,6 +191,9 @@ void BlockAllocator::reserve_more() if(blocks.empty()) throw logic_error("no blocks"); + if(train.get_layout().get_driver().is_halted()) + return; + BlockIter start = blocks.back(); if(&*start==stop_at_block) return; @@ -354,6 +358,8 @@ void BlockAllocator::advance_back() const Vehicle &veh = train.get_vehicle(rev ? 0 : train.get_n_vehicles()-1); const Block &veh_block = veh.get_placement().get_position(rev ? VehiclePlacement::FRONT_AXLE : VehiclePlacement::BACK_AXLE)->get_block(); + bool pending_cleared = false; + /* Sensors aren't guaranteed to be detriggered in order. Go through the block list and locate the first sensor that's still active. */ BlockList::iterator end = blocks.end(); @@ -387,6 +393,9 @@ void BlockAllocator::advance_back() end = i; } + if(block==pending_block) + pending_cleared = true; + // Stop if we encounter an active sensor or the train's last vehicle if(block==&veh_block || active_sensor) { @@ -399,6 +408,10 @@ void BlockAllocator::advance_back() release_blocks_begin(end); signal_rear_advanced.emit(*last()); } + + if(pending_cleared) + reserve_more(); + return; } } @@ -552,6 +565,12 @@ void BlockAllocator::update_next_sensor(Sensor *after) next_sensor = 0; } +void BlockAllocator::halt_event(bool halted) +{ + if(active && !halted) + reserve_more(); +} + void BlockAllocator::save(list &st) const { if(!blocks.empty() && cur_blocks_end!=blocks.begin())