]>
Dogcows Code - chaz/yoink/blob - application.cc
fd9ea451fba72ec20e50212be89719646408acfa
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 next_update_(timer::ticks()),
30 total_time_(SCALAR(0.0))
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 update_timer_
.init(boost::bind(&application::dispatch_update
, this, _1
, _2
),
46 timestep_
, timer::repeat
, this);
47 draw_timer_
.init(boost::bind(&application::dispatch_draw
, this, _1
, _2
),
48 framerate
, timer::repeat
, this);
52 void application::dispatch_update(timer
& timer
, scalar t
)
56 while (FE_PollEvent(&event
) == 1)
62 if (event
.key
.keysym
.sym
== SDLK_ESCAPE
&&
63 (SDL_GetModState() & KMOD_CTRL
) )
66 log_warning("escape forced");
73 video::current()->resize(event
.resize
.w
, event
.resize
.h
);
81 const int MAX_FRAMESKIP
= 15;
84 while (next_update_
< t
&& ++i
< MAX_FRAMESKIP
)
86 total_time_
+= timestep_
;
87 update(total_time_
, timestep_
);
89 next_update_
+= timestep_
;
93 void application::dispatch_draw(timer
& timer
, scalar t
)
95 scalar alpha
= (t
+ timestep_
- next_update_
) * inverse_timestep_
;
96 if (alpha
< SCALAR(0.0)) log_error("UH OH!!!!! It's NEGATIVE", alpha
);
97 if (alpha
> SCALAR(1.0)) log_error("UH OH!!!!! It's POSITIVE", alpha
);
100 video::current()->swap();
This page took 0.038948 seconds and 3 git commands to generate.