X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrain.cpp;h=7224247b5c4aaf26e8ad950d533113b24773e75b;hb=59bae8acd679127602cf35d22bcd37e316a5a056;hp=91387d85297e7f2a6b5bed13a1b620cf01f687b9;hpb=5c1ddd2f213af3fea15237e02f7da112c0abba36;p=r2c2.git diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index 91387d8..7224247 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -6,6 +6,7 @@ #include #include #include "aicontrol.h" +#include "block.h" #include "catalogue.h" #include "driver.h" #include "layout.h" @@ -13,6 +14,7 @@ #include "simplecontroller.h" #include "speedquantizer.h" #include "timetable.h" +#include "trackcircuit.h" #include "trackiter.h" #include "tracktype.h" #include "train.h" @@ -60,7 +62,7 @@ Train::Train(Layout &l, const VehicleType &t, unsigned a, const string &p): layout.get_driver().signal_loco_speed.connect(sigc::mem_fun(this, &Train::loco_speed_event)); layout.get_driver().signal_loco_function.connect(sigc::mem_fun(this, &Train::loco_func_event)); - layout.signal_block_state_changed.connect(sigc::mem_fun(this, &Train::block_state_changed)); + layout.signal_sensor_state_changed.connect(sigc::mem_fun(this, &Train::sensor_state_changed)); layout.get_driver().signal_halt.connect(sigc::mem_fun(this, &Train::halt_event)); @@ -428,9 +430,15 @@ void Train::loco_func_event(unsigned addr, unsigned func, bool state) } } -void Train::block_state_changed(Block &block, Block::State state) +void Train::sensor_state_changed(Sensor &sensor, Sensor::State state) { - if(block.get_train()==this && state==Block::MAYBE_ACTIVE) + Block *block = 0; + if(TrackCircuit *tc = dynamic_cast(&sensor)) + block = &tc->get_block(); + else + return; + + if(block->get_train()==this && state==Sensor::MAYBE_ACTIVE) { if(last_entry_block) { @@ -438,7 +446,7 @@ void Train::block_state_changed(Block &block, Block::State state) if(pure_speed && speed_quantizer && current_speed_step>0) travel_distance = 0; - for(BlockIter i=last_entry_block; &*i!=█ i=i.next()) + for(BlockIter i=last_entry_block; &*i!=block; i=i.next()) { if(i->get_sensor_id()) return; @@ -455,7 +463,7 @@ void Train::block_state_changed(Block &block, Block::State state) } } - last_entry_block = allocator.iter_for(block); + last_entry_block = allocator.iter_for(*block); last_entry_time = Time::now(); pure_speed = true; accurate_position = true;