X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fblock.cpp;h=ec313d9d415240dab9114a27be838f27111112e4;hb=8b828fc32fd210b6e335ac6614d269aa892d4d57;hp=ca404de569046f2a2824eb7641bbbbbc20425c8e;hpb=1ff06c5bc46a677fa389ef86c6b26664368f1653;p=r2c2.git diff --git a/source/libr2c2/block.cpp b/source/libr2c2/block.cpp index ca404de..ec313d9 100644 --- a/source/libr2c2/block.cpp +++ b/source/libr2c2/block.cpp @@ -1,12 +1,7 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include +#include #include "block.h" +#include "driver.h" #include "layout.h" #include "route.h" #include "trackiter.h" @@ -22,6 +17,7 @@ Block::Block(Layout &l, Track &start): id(0), sensor_id(start.get_sensor_id()), turnout_id(start.get_turnout_id()), + state(INACTIVE), train(0) { tracks.insert(&start); @@ -59,6 +55,9 @@ Block::Block(Layout &l, Track &start): find_paths(TrackIter(endpoints[i].track, endpoints[i].track_ep), path); } + if(sensor_id && layout.has_driver()) + layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Block::sensor_event)); + layout.add_block(*this); } @@ -162,13 +161,30 @@ bool Block::reserve(Train *t) if(!t || !train) { train = t; - layout.signal_block_reserved.emit(*this, train); + signal_reserved.emit(train); return true; } else return false; } +void Block::tick(const Time::TimeDelta &dt) +{ + if(state_confirm_timeout) + { + state_confirm_timeout -= dt; + if(state_confirm_timeout<=Time::zero) + { + if(state==MAYBE_INACTIVE) + state = INACTIVE; + else if(state==MAYBE_ACTIVE) + state = ACTIVE; + state_confirm_timeout = Time::zero; + signal_state_changed.emit(state); + } + } +} + void Block::find_paths(TrackIter track, unsigned path) { unsigned mask = track.endpoint().paths; @@ -211,6 +227,25 @@ void Block::determine_id() } } +void Block::sensor_event(unsigned addr, bool s) +{ + if(addr==sensor_id) + { + if(s && stateMAYBE_INACTIVE) + { + state = MAYBE_INACTIVE; + state_confirm_timeout = 700*Time::msec; + signal_state_changed.emit(state); + } + } +} + Block::Endpoint::Endpoint(Track *t, unsigned e): track(t),