From 065d35f5f86a5b9cda95736f59e63845e0bb6fa6 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 7 Apr 2015 13:56:47 +0300 Subject: [PATCH] Remove a queued block reservation if the block is released This can happen in some situations with instantly changing turnouts. --- source/libr2c2/layout.cpp | 16 ++++++++++++++-- source/libr2c2/layout.h | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/source/libr2c2/layout.cpp b/source/libr2c2/layout.cpp index 0aa5333..bc149df 100644 --- a/source/libr2c2/layout.cpp +++ b/source/libr2c2/layout.cpp @@ -565,7 +565,19 @@ void Layout::sensor_state_changed(Sensor &sensor, Sensor::State state) void Layout::block_reserved(Block &block, Train *train) { if(emitting_block_reserved) + { + if(!train) + { + for(deque::iterator i=block_reserve_queue.end(); i!=block_reserve_queue.begin(); ) + if((--i)->block==&block) + { + block_reserve_queue.erase(i); + return; + } + } + block_reserve_queue.push_back(BlockReservation(block, train)); + } else { SetFlag setf(emitting_block_reserved); @@ -574,7 +586,7 @@ void Layout::block_reserved(Block &block, Train *train) { BlockReservation br = block_reserve_queue.front(); block_reserve_queue.pop_front(); - signal_block_reserved.emit(br.block, br.train); + signal_block_reserved.emit(*br.block, br.train); } } } @@ -634,7 +646,7 @@ void Layout::Storage::del() Layout::BlockReservation::BlockReservation(Block &b, Train *t): - block(b), + block(&b), train(t) { } diff --git a/source/libr2c2/layout.h b/source/libr2c2/layout.h index 4bccb20..e06d4fb 100644 --- a/source/libr2c2/layout.h +++ b/source/libr2c2/layout.h @@ -72,7 +72,7 @@ private: struct BlockReservation { - Block █ + Block *block; Train *train; BlockReservation(Block &, Train *); -- 2.45.2