]>
Dogcows Code - chaz/yoink/blob - src/moof/application.cc
84f1a24040593ef2de145d117f8401314f5b3117
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
14 #include "application.hh"
15 #include "fastevents.h"
17 #include "settings.hh"
24 application::application(settings
& settings
) :
25 last_update_(timer::ticks()),
29 if (settings
.get("rngseed", random_seed
)) srand(random_seed
);
32 scalar timestep
= SCALAR(80.0);
33 settings
.get("timestep", timestep
);
34 timestep_
= SCALAR(1.0) / timestep
;
35 inverse_timestep_
= timestep
;
37 scalar framerate
= SCALAR(40.0);
38 settings
.get("framerate", framerate
);
39 framerate
= SCALAR(1.0) / framerate
;
41 //update_timer_.init(boost::bind(&application::dispatch_update,
42 //this, _1, _2), timestep_, timer::repeat);
43 //add_timer(update_timer_);
45 game_time_
.reset(timestep_
);
46 //game_time_.scale(SCALAR(0.5));
48 draw_timer_
.init(boost::bind(&application::dispatch_draw
,
49 this, _1
, _2
), framerate
, timer::repeat
);
50 add_timer(draw_timer_
);
52 //timer::default_source().scale(SCALAR(0.2));
55 void application::dispatch_update(timer
& timer
, scalar t
)
59 while (FE_PollEvent(&event
) == 1)
64 if (event
.key
.keysym
.sym
== SDLK_ESCAPE
&&
65 (SDL_GetModState() & KMOD_CTRL
))
67 log_warning("escape forced");
73 video::current()->resize(event
.resize
.w
,
80 const int MAX_CONSECUTIVE_UPDATES
= 15;
82 log_debug("updating", timer
.expiration(), "/", t
);
84 scalar deltaTime
= t
- last_update_
;
88 while (timestep_
<= accum_
&& i
< MAX_CONSECUTIVE_UPDATES
)
90 scalar dt
= game_time_
.step();
91 update(game_time_
.ticks(), dt
);
98 void application::dispatch_draw(timer
& timer
, scalar t
)
100 log_debug("draw", timer
.expiration(), "/", t
);
103 thread::main_runloop().run_once();
105 dispatch_update(timer
, t
);
107 scalar alpha
= accum_
* inverse_timestep_
;
109 //alpha = cml::clamp(alpha, SCALAR(-1.0), SCALAR(2.0));
110 if (alpha
< SCALAR(0.0)) log_warning("alpha:", alpha
);
111 else if (alpha
> SCALAR(1.0)) log_warning("alpha:", alpha
);
112 else log_debug("alpha:", alpha
);
116 scalar begin
= timer::ticks();
117 video::current()->swap(t
);
118 scalar duration
= timer::ticks() - begin
;
119 log_debug("flip duration:", duration
, begin
, timer::ticks());
121 log_info("draw difference:", t
- last_draw_
);
This page took 0.040161 seconds and 4 git commands to generate.