]>
Dogcows Code - chaz/yoink/blob - src/moof/application.cc
e0b73b78d9ac053e7a5f8805a2431acc4c730235
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
8 *****************************************************************************/
10 #include <cstdlib> // exit, srand
11 #include <boost/noncopyable.hpp>
14 #include "fastevents.h"
16 #include "application.hh"
18 #include "settings.hh"
26 application::application(settings
& settings
) :
27 last_update_(timer::ticks()),
31 if (settings
.get("rngseed", random_seed
)) srand(random_seed
);
34 scalar timestep
= SCALAR(80.0);
35 settings
.get("timestep", timestep
);
36 timestep_
= SCALAR(1.0) / timestep
;
37 inverse_timestep_
= timestep
;
39 scalar framerate
= SCALAR(40.0);
40 settings
.get("framerate", framerate
);
41 framerate
= SCALAR(1.0) / framerate
;
43 //update_timer_.init(boost::bind(&application::dispatch_update,
44 //this, _1, _2), timestep_, timer::repeat);
45 //add_timer(update_timer_);
47 game_time_
.reset(timestep_
);
48 //game_time_.scale(SCALAR(0.5));
50 draw_timer_
.init(boost::bind(&application::dispatch_draw
,
51 this, _1
, _2
), framerate
, timer::repeat
);
52 add_timer(draw_timer_
);
54 //timer::default_source().scale(SCALAR(0.2));
57 void application::dispatch_update(timer
& timer
, scalar t
)
61 while (FE_PollEvent(&event
) == 1)
66 if (event
.key
.keysym
.sym
== SDLK_ESCAPE
&&
67 (SDL_GetModState() & KMOD_CTRL
))
69 log_warning("escape forced");
75 video::current()->resize(event
.resize
.w
,
82 const int MAX_CONSECUTIVE_UPDATES
= 15;
84 log_debug("updating", timer
.expiration(), "/", t
);
86 scalar deltaTime
= t
- last_update_
;
90 while (timestep_
<= accum_
&& i
< MAX_CONSECUTIVE_UPDATES
)
92 scalar dt
= game_time_
.step();
93 update(game_time_
.ticks(), dt
);
100 void application::dispatch_draw(timer
& timer
, scalar t
)
102 log_debug("draw", timer
.expiration(), "/", t
);
105 thread::main_runloop().run_once();
107 dispatch_update(timer
, t
);
109 scalar alpha
= accum_
* inverse_timestep_
;
111 //alpha = cml::clamp(alpha, SCALAR(-1.0), SCALAR(2.0));
112 if (alpha
< SCALAR(0.0)) log_warning("alpha:", alpha
);
113 else if (alpha
> SCALAR(1.0)) log_warning("alpha:", alpha
);
114 else log_debug("alpha:", alpha
);
118 scalar begin
= timer::ticks();
119 video::current()->swap(t
);
120 scalar duration
= timer::ticks() - begin
;
121 log_debug("flip duration:", duration
, begin
, timer::ticks());
123 log_info("draw difference:", t
- last_draw_
);
This page took 0.039203 seconds and 4 git commands to generate.