X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fapplication.cc;fp=src%2Fmoof%2Fapplication.cc;h=b462a0eb2efcd947317a61ffcf619f4553f83579;hp=fd9ea451fba72ec20e50212be89719646408acfa;hb=af88821a172c4dfd138b91b2a5148ae50b502fa2;hpb=d6990468d297a6cbee98e4d0d33ab37e1b2352c9 diff --git a/src/moof/application.cc b/src/moof/application.cc index fd9ea45..b462a0e 100644 --- a/src/moof/application.cc +++ b/src/moof/application.cc @@ -26,8 +26,9 @@ namespace moof { application::application(settings& settings) : - next_update_(timer::ticks()), - total_time_(SCALAR(0.0)) + last_update_(timer::ticks()), + total_time_(SCALAR(0.0)), + accum_(SCALAR(0.0)) { unsigned random_seed; if (settings.get("rngseed", random_seed)) srand(random_seed); @@ -42,10 +43,15 @@ application::application(settings& settings) : settings.get("framerate", framerate); framerate = SCALAR(1.0) / framerate; - update_timer_.init(boost::bind(&application::dispatch_update, this, _1, _2), - timestep_, timer::repeat, this); + //timer::default_source().scale(SCALAR(1.2)); + + //update_timer_.init(boost::bind(&application::dispatch_update, this, _1, _2), + //timestep_, timer::repeat, this); + next_update_ = update_timer_.expiration(); + draw_timer_.init(boost::bind(&application::dispatch_draw, this, _1, _2), - framerate, timer::repeat, this); + framerate, timer::repeat); + add_timer(draw_timer_); } @@ -78,26 +84,60 @@ void application::dispatch_update(timer& timer, scalar t) } - const int MAX_FRAMESKIP = 15; + //const int MAX_FRAMESKIP = 15; + + log_debug("updating", timer.expiration(), "/", t); - int i = 0; - while (next_update_ < t && ++i < MAX_FRAMESKIP) + //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_) { - total_time_ += timestep_; + log_debug("UPDATING"); update(total_time_, timestep_); - - next_update_ += timestep_; + total_time_ += timestep_; + accum_ -= timestep_; } + + last_update_ = t; } void application::dispatch_draw(timer& timer, scalar t) { - scalar alpha = (t + timestep_ - next_update_) * inverse_timestep_; - if (alpha < SCALAR(0.0)) log_error("UH OH!!!!! It's NEGATIVE", alpha); - if (alpha > SCALAR(1.0)) log_error("UH OH!!!!! It's POSITIVE", alpha); + log_debug("next update", update_timer_.expiration()); + log_debug("draw", timer.expiration(), "/", t); + + 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); + else if (alpha > SCALAR(1.0)) log_warning("alpha:", alpha); + else log_debug("alpha:", alpha); draw(alpha); - video::current()->swap(); + + scalar begin = timer::ticks(); + video::current()->swap(t); + + scalar duration = timer::ticks() - begin; + log_debug("flip duration:", duration); }