]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/blockallocator.cpp
Resume allocation if a train moves out of its own way
[r2c2.git] / source / libr2c2 / blockallocator.cpp
index 88fb12e8145baaf3f4e636311f9664b5a0a86e1d..7e992e00f41b65f6aecdc6afd6e89ec03e899bd0 100644 (file)
@@ -337,7 +337,7 @@ void BlockAllocator::advance_front(const Block *block, bool inclusive)
        // Update cur_blocks_end first to keep things consistent.
        cur_blocks_end = end;
        for(; i!=end; ++i)
-               train.signal_advanced.emit(**i);
+               signal_advanced.emit(**i, (*i)->get_sensor());
 }
 
 void BlockAllocator::advance_front(const Sensor *sensor)
@@ -354,6 +354,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 +389,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)
                {
@@ -397,7 +402,12 @@ void BlockAllocator::advance_back()
                                if(i!=end)
                                        ++end;
                                release_blocks_begin(end);
+                               signal_rear_advanced.emit(*last());
                        }
+
+                       if(pending_cleared)
+                               reserve_more();
+
                        return;
                }
        }
@@ -488,6 +498,8 @@ void BlockAllocator::sensor_state_changed(Sensor &sensor, Sensor::State state)
        {
                if(&sensor==next_sensor)
                {
+                       if(is_block_current(*block))
+                               signal_advanced.emit(*block, &sensor);
                        update_next_sensor(next_sensor);
                        advance_front(next_sensor);