]> git.tdb.fi Git - r2c2.git/commitdiff
Add an option to set simulation speed
authorMikko Rasa <tdb@tdb.fi>
Fri, 27 Mar 2015 07:12:58 +0000 (09:12 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 27 Mar 2015 07:12:58 +0000 (09:12 +0200)
Useful for testing long timetables.  Will cause problems if used with a
physical layout; currently there are no checks to prevent it.

source/engineer/engineer.cpp
source/engineer/options.cpp
source/engineer/options.h
source/libr2c2/layout.cpp
source/libr2c2/layout.h

index 36412cfeb017f857efd354c30e8e8e85c1f33fcd..ef5b54d8c7110bef454e1f76b1966622bcae70df 100644 (file)
@@ -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);
 
index 89e1fd109be155a3172aa488afc2619bf89d42fe..bdac3619356bbc6b3a1c9558a4bce74b66f6cf65 100644 (file)
@@ -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);
index ddeb62e5232c6601f9faeb118499575593dbd8cb..f64cc78fe006e7772e3c1cf6912a9569a17ef998 100644 (file)
@@ -12,6 +12,7 @@ struct Options
        std::string driver;
        bool network;
        bool simulate;
+       float sim_speed;
        std::string layout_fn;
        std::string state_fn;
 
index 70a9f106849d26ec2f9b59ad0eb2d5b8d13a2169..0aa5333d36238779b8e49bc02fdf1ae67702b363 100644 (file)
@@ -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--)
index 2488f9371aa98c08a284daadc29bae40d976c05d..4bccb20c9b26b34b436c3dc12dddeba47bc20b68 100644 (file)
@@ -151,7 +151,7 @@ public:
        const std::map<unsigned, Train *> &get_trains() const { return trains; }
        void remove_train(Train &);
 
-       void tick();
+       void tick(float = 1.0f);
 private:
        void step(const Msp::Time::TimeDelta &);
 public: