]> Dogcows Code - chaz/yoink/blobdiff - src/moof/application.cc
build system enhancements
[chaz/yoink] / src / moof / application.cc
index b462a0eb2efcd947317a61ffcf619f4553f83579..0da5bae4b449a989b878c427a541bd065d0ee00f 100644 (file)
@@ -27,7 +27,6 @@ namespace moof {
 
 application::application(settings& settings) :
        last_update_(timer::ticks()),
-       total_time_(SCALAR(0.0)),
        accum_(SCALAR(0.0))
 {
        unsigned random_seed;
@@ -43,14 +42,17 @@ application::application(settings& settings) :
        settings.get("framerate", framerate);
        framerate = SCALAR(1.0) / framerate;
 
-       //timer::default_source().scale(SCALAR(1.2));
+       //timer::default_source().scale(SCALAR(0.76));
 
-       //update_timer_.init(boost::bind(&application::dispatch_update, this, _1, _2),
-                                          //timestep_, timer::repeat, this);
-       next_update_ = update_timer_.expiration();
+       //update_timer_.init(boost::bind(&application::dispatch_update,
+                                                                  //this, _1, _2),
+                                          //timestep_, timer::repeat);
+       //add_timer(update_timer_);
+       
+       game_time_.reset(timestep_);
 
-       draw_timer_.init(boost::bind(&application::dispatch_draw, this, _1, _2),
-                                        framerate, timer::repeat);
+       draw_timer_.init(boost::bind(&application::dispatch_draw,
+                                                                this, _1, _2), framerate, timer::repeat);
        add_timer(draw_timer_);
 }
 
@@ -84,28 +86,19 @@ void application::dispatch_update(timer& timer, scalar t)
        }
 
 
-       //const int MAX_FRAMESKIP = 15;
+       const int MAX_CONSECUTIVE_UPDATES = 15;
 
        log_debug("updating", timer.expiration(), "/", t);
 
-       //int i = 0;
-       //while (next_update_ < t && ++i < MAX_FRAMESKIP)
-       //{
-               //total_time_ += timestep_;
-               //update(total_time_, timestep_);
-
-               //next_update_ += timestep_;
-               //log_debug("updated", next_update_, "time:", timer::ticks());
-       //}
-       
        scalar deltaTime = t - last_update_;
        accum_ += deltaTime;
 
-       while (timestep_ <= accum_)
+       int i = 0;
+       while (timestep_ <= accum_ && i < MAX_CONSECUTIVE_UPDATES)
        {
                log_debug("UPDATING");
-               update(total_time_, timestep_);
-               total_time_ += timestep_;
+               update(game_time_.ticks(), timestep_);
+               game_time_.step();
                accum_ -= timestep_;
        }
 
@@ -114,17 +107,14 @@ void application::dispatch_update(timer& timer, scalar t)
 
 void application::dispatch_draw(timer& timer, scalar t)
 {
-       log_debug("next update", update_timer_.expiration());
        log_debug("draw", timer.expiration(), "/", t);
 
+       // XXX temporary
+       thread::main_runloop().run_once();
+
        dispatch_update(timer, t);
 
-       //if (t < next_update_ - timestep_) return;
-       //scalar alpha = (t + timestep_ - next_update_) * inverse_timestep_;
-       //scalar alpha = (t + timestep_ - update_timer_.expiration()) * inverse_timestep_;
-       //scalar alpha = (next_update_ - t) * inverse_timestep_;
        scalar alpha = accum_ * inverse_timestep_;
-       //if (alpha < SCALAR(0.0) || SCALAR(1.0) < alpha) return;
        
        alpha = cml::clamp(alpha, SCALAR(-1.0), SCALAR(2.0));
        if (alpha < SCALAR(0.0)) log_warning("alpha:", alpha);
This page took 0.01918 seconds and 4 git commands to generate.