]>
Dogcows Code - chaz/yoink/blob - src/moof/application.cc
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #include <cstdlib> // exit, srand
13 #include <boost/noncopyable.hpp>
16 #include "fastevents.h"
18 #include "application.hh"
20 #include "settings.hh"
28 application::application(settings
& settings
) :
29 last_update_(timer::ticks()),
30 total_time_(SCALAR(0.0)),
34 if (settings
.get("rngseed", random_seed
)) srand(random_seed
);
37 scalar timestep
= SCALAR(80.0);
38 settings
.get("timestep", timestep
);
39 timestep_
= SCALAR(1.0) / timestep
;
40 inverse_timestep_
= timestep
;
42 scalar framerate
= SCALAR(40.0);
43 settings
.get("framerate", framerate
);
44 framerate
= SCALAR(1.0) / framerate
;
46 //timer::default_source().scale(SCALAR(1.2));
48 //update_timer_.init(boost::bind(&application::dispatch_update, this, _1, _2),
49 //timestep_, timer::repeat, this);
50 next_update_
= update_timer_
.expiration();
52 draw_timer_
.init(boost::bind(&application::dispatch_draw
, this, _1
, _2
),
53 framerate
, timer::repeat
);
54 add_timer(draw_timer_
);
58 void application::dispatch_update(timer
& timer
, scalar t
)
62 while (FE_PollEvent(&event
) == 1)
68 if (event
.key
.keysym
.sym
== SDLK_ESCAPE
&&
69 (SDL_GetModState() & KMOD_CTRL
) )
72 log_warning("escape forced");
79 video::current()->resize(event
.resize
.w
, event
.resize
.h
);
87 //const int MAX_FRAMESKIP = 15;
89 log_debug("updating", timer
.expiration(), "/", t
);
92 //while (next_update_ < t && ++i < MAX_FRAMESKIP)
94 //total_time_ += timestep_;
95 //update(total_time_, timestep_);
97 //next_update_ += timestep_;
98 //log_debug("updated", next_update_, "time:", timer::ticks());
101 scalar deltaTime
= t
- last_update_
;
104 while (timestep_
<= accum_
)
106 log_debug("UPDATING");
107 update(total_time_
, timestep_
);
108 total_time_
+= timestep_
;
115 void application::dispatch_draw(timer
& timer
, scalar t
)
117 log_debug("next update", update_timer_
.expiration());
118 log_debug("draw", timer
.expiration(), "/", t
);
120 dispatch_update(timer
, t
);
122 //if (t < next_update_ - timestep_) return;
123 //scalar alpha = (t + timestep_ - next_update_) * inverse_timestep_;
124 //scalar alpha = (t + timestep_ - update_timer_.expiration()) * inverse_timestep_;
125 //scalar alpha = (next_update_ - t) * inverse_timestep_;
126 scalar alpha
= accum_
* inverse_timestep_
;
127 //if (alpha < SCALAR(0.0) || SCALAR(1.0) < alpha) return;
129 alpha
= cml::clamp(alpha
, SCALAR(-1.0), SCALAR(2.0));
130 if (alpha
< SCALAR(0.0)) log_warning("alpha:", alpha
);
131 else if (alpha
> SCALAR(1.0)) log_warning("alpha:", alpha
);
132 else log_debug("alpha:", alpha
);
136 scalar begin
= timer::ticks();
137 video::current()->swap(t
);
139 scalar duration
= timer::ticks() - begin
;
140 log_debug("flip duration:", duration
);
This page took 0.044714 seconds and 5 git commands to generate.