: screen(screen)
, states()
, last(SDL_GetTicks())
+, remaining(0)
, inStateChage(false) {
assert(initialState && "cannot create application without initial state");
RealPushState(initialState);
if (!CurrentState()) return;
input.ResetInteractiveState();
SDL_Event event;
- while (SDL_PollEvent(&event)) {
+ while (!StateChangePending() && SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
PopAllStates();
void Application::UpdateWorld(Uint32 deltaT) {
if (!CurrentState()) return;
- for (Uint32 i(0); i < deltaT && !StateChangePending(); ++i) {
- CurrentState()->PhysicsTimers().Update(1);
- CurrentState()->UpdateWorld(1);
+ remaining += deltaT;
+ Uint32 step = CurrentState()->Timestep();
+ if (step > 0) {
+ for (; remaining >= step && !StateChangePending(); remaining -= step) {
+ CurrentState()->PhysicsTimers().Update(step);
+ CurrentState()->UpdateWorld(step);
+ }
+ } else {
+ CurrentState()->PhysicsTimers().Update(deltaT);
+ CurrentState()->UpdateWorld(deltaT);
}
}