From: Mikko Rasa Date: Fri, 27 Mar 2015 07:12:58 +0000 (+0200) Subject: Add an option to set simulation speed X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=eb8b919a1a224c0d6f206d1d29a9b4b8c3a0cac8;p=r2c2.git Add an option to set simulation speed Useful for testing long timetables. Will cause problems if used with a physical layout; currently there are no checks to prevent it. --- diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 36412cf..ef5b54d 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -170,7 +170,7 @@ void Engineer::tick() process_new_train(**i); new_trains.clear(); - layout.tick(); + layout.tick(options.sim_speed); layout_3d.tick(); event_disp.tick(Time::zero); diff --git a/source/engineer/options.cpp b/source/engineer/options.cpp index 89e1fd1..bdac361 100644 --- a/source/engineer/options.cpp +++ b/source/engineer/options.cpp @@ -13,7 +13,8 @@ Options::Options(int argc, char **argv): fullscreen(false), debug(false), network(false), - simulate(false) + simulate(false), + sim_speed(1.0f) { string res; @@ -23,6 +24,7 @@ Options::Options(int argc, char **argv): getopt.add_option('g', "debug", debug, GetOpt::NO_ARG); getopt.add_option('d', "driver", driver, GetOpt::REQUIRED_ARG); getopt.add_option('s', "simulate", simulate, GetOpt::NO_ARG); + getopt.add_option( "sim-speed", sim_speed, GetOpt::REQUIRED_ARG); getopt.add_option('n', "network", network, GetOpt::NO_ARG); getopt.add_option( "state", state_fn, GetOpt::REQUIRED_ARG); getopt(argc, argv); diff --git a/source/engineer/options.h b/source/engineer/options.h index ddeb62e..f64cc78 100644 --- a/source/engineer/options.h +++ b/source/engineer/options.h @@ -12,6 +12,7 @@ struct Options std::string driver; bool network; bool simulate; + float sim_speed; std::string layout_fn; std::string state_fn; diff --git a/source/libr2c2/layout.cpp b/source/libr2c2/layout.cpp index 70a9f10..0aa5333 100644 --- a/source/libr2c2/layout.cpp +++ b/source/libr2c2/layout.cpp @@ -414,7 +414,7 @@ void Layout::remove_train(Train &t) signal_train_removed.emit(t); } -void Layout::tick() +void Layout::tick(float speed) { if(driver) driver->tick(); @@ -425,6 +425,7 @@ void Layout::tick() dt = t-last_tick; last_tick = t; + dt *= speed; unsigned count = dt/(10*Time::msec)+1; dt /= count; while(count--) diff --git a/source/libr2c2/layout.h b/source/libr2c2/layout.h index 2488f93..4bccb20 100644 --- a/source/libr2c2/layout.h +++ b/source/libr2c2/layout.h @@ -151,7 +151,7 @@ public: const std::map &get_trains() const { return trains; } void remove_train(Train &); - void tick(); + void tick(float = 1.0f); private: void step(const Msp::Time::TimeDelta &); public: