]>
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()),
33 if (settings
.get("rngseed", random_seed
)) srand(random_seed
);
36 scalar timestep
= SCALAR(80.0);
37 settings
.get("timestep", timestep
);
38 timestep_
= SCALAR(1.0) / timestep
;
39 inverse_timestep_
= timestep
;
41 scalar framerate
= SCALAR(40.0);
42 settings
.get("framerate", framerate
);
43 framerate
= SCALAR(1.0) / framerate
;
45 //timer::default_source().scale(SCALAR(0.76));
47 //update_timer_.init(boost::bind(&application::dispatch_update,
49 //timestep_, timer::repeat);
50 //add_timer(update_timer_);
52 game_time_
.reset(timestep_
);
54 draw_timer_
.init(boost::bind(&application::dispatch_draw
,
55 this, _1
, _2
), framerate
, timer::repeat
);
56 add_timer(draw_timer_
);
60 void application::dispatch_update(timer
& timer
, scalar t
)
64 while (FE_PollEvent(&event
) == 1)
70 if (event
.key
.keysym
.sym
== SDLK_ESCAPE
&&
71 (SDL_GetModState() & KMOD_CTRL
) )
74 log_warning("escape forced");
81 video::current()->resize(event
.resize
.w
, event
.resize
.h
);
89 const int MAX_CONSECUTIVE_UPDATES
= 15;
91 log_debug("updating", timer
.expiration(), "/", t
);
93 scalar deltaTime
= t
- last_update_
;
97 while (timestep_
<= accum_
&& i
< MAX_CONSECUTIVE_UPDATES
)
99 log_debug("UPDATING");
100 update(game_time_
.ticks(), timestep_
);
108 void application::dispatch_draw(timer
& timer
, scalar t
)
110 log_debug("draw", timer
.expiration(), "/", t
);
113 thread::main_runloop().run_once();
115 dispatch_update(timer
, t
);
117 scalar alpha
= accum_
* inverse_timestep_
;
119 alpha
= cml::clamp(alpha
, SCALAR(-1.0), SCALAR(2.0));
120 if (alpha
< SCALAR(0.0)) log_warning("alpha:", alpha
);
121 else if (alpha
> SCALAR(1.0)) log_warning("alpha:", alpha
);
122 else log_debug("alpha:", alpha
);
126 scalar begin
= timer::ticks();
127 video::current()->swap(t
);
129 scalar duration
= timer::ticks() - begin
;
130 log_debug("flip duration:", duration
);
This page took 0.04228 seconds and 5 git commands to generate.