]> git.tdb.fi Git - r2c2.git/commitdiff
Move the responsibility of starting the train to TrainRouter
authorMikko Rasa <tdb@tdb.fi>
Tue, 31 Mar 2015 21:42:00 +0000 (00:42 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 31 Mar 2015 21:42:00 +0000 (00:42 +0300)
This avoids any further sync problems with the planner, accounts for
irregular situations and also makes more sense.

source/libr2c2/timetable.cpp
source/libr2c2/trainrouter.cpp
source/libr2c2/trainrouter.h

index 41cbbf00ab834350714025c865853d54462c4796..da01b599876d03c7f18d0e1bae05eb2951e9bff5 100644 (file)
@@ -89,22 +89,6 @@ void Timetable::tick(const Time::TimeDelta &dt)
 {
        if(update_pending && !train.get_block_allocator().is_active())
                update_route();
-
-       if(current_row->type==DEPART)
-       {
-               const Clock &clock = train.get_layout().get_clock();
-
-               Time::TimeDelta t = clock.get_current_time();
-               if(t<current_row->time)
-                       t += Time::day;
-
-               Time::TimeDelta b = t-dt*clock.get_rate();
-               if(b<current_row->time)
-               {
-                       train.ai_message(Message("set-target-speed", train.get_maximum_speed()));
-                       ++current_row;
-               }
-       }
 }
 
 void Timetable::save(list<DataFile::Statement> &st) const
@@ -202,11 +186,18 @@ void Timetable::update_route()
                        dt += Time::day;
                train.ai_message(Message("set-trip-duration", dt/clock.get_rate()));
        }
+
+       late_arrival = false;
 }
 
 void Timetable::event(TrainAI &, const Message &msg)
 {
-       if(msg.type=="arrived")
+       if(msg.type=="departed")
+       {
+               if(current_row->type==DEPART)
+                       ++current_row;
+       }
+       else if(msg.type=="arrived")
        {
                if(current_row->type==ARRIVE)
                        record_time();
index 1ada62104cee5724ac208be1e1e57cf7dd18946c..cc6277f87e9083132a20c8ccf4abea045db2b26f 100644 (file)
@@ -241,6 +241,9 @@ void TrainRouter::tick(const Time::TimeDelta &dt)
                        if(delay<Time::zero)
                        {
                                duration = max(duration+delay, Time::zero);
+                               train.ai_message(Message("set-target-speed", train.get_maximum_speed()));
+                               signal_departed.emit();
+                               signal_event.emit(Message("departed"));
                                delay = Time::zero;
                        }
                }
index 457bdf78cf59c5dd5fcfb4c49db644f991ec888b..c7c1be18b9a6f5cd55f00c632f049f253bf4e436 100644 (file)
@@ -60,6 +60,7 @@ private:
 
 public:
        sigc::signal<void, const Route *> signal_route_changed;
+       sigc::signal<void> signal_departed;
        sigc::signal<void, const TrackChain *> signal_arrived;
        sigc::signal<void, const TrackChain *> signal_waypoint_reached;