X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FApplication.cpp;h=830223ef0381c5025245cac2a6c09c1cce821895;hb=60e0b9e8ec660a4f6b8e500bf0b77a31bb817b45;hp=64a8602e8d9b1c551bd2940224c3a1ab72746292;hpb=04e4e8797a63c0a89aae9882982cd864213d05ab;p=l2e.git diff --git a/src/app/Application.cpp b/src/app/Application.cpp index 64a8602..830223e 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -11,6 +11,7 @@ Application::Application(sdl::InitScreen &screen, State *initialState) : screen(screen) , states() , last(SDL_GetTicks()) +, remaining(0) , inStateChage(false) { assert(initialState && "cannot create application without initial state"); RealPushState(initialState); @@ -152,7 +153,7 @@ void Application::HandleEvents() { if (!CurrentState()) return; input.ResetInteractiveState(); SDL_Event event; - while (SDL_PollEvent(&event)) { + while (!StateChangePending() && SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: PopAllStates(); @@ -175,9 +176,16 @@ void Application::HandleEvents() { 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); } }