]> git.localhorst.tv Git - l2e.git/blobdiff - src/app/Application.cpp
added option for sped up integration
[l2e.git] / src / app / Application.cpp
index 0a5f5e73d4d1343c9eb770d16e09951af0c1aea2..830223ef0381c5025245cac2a6c09c1cce821895 100644 (file)
@@ -1,6 +1,7 @@
 #include "Application.h"
 
 #include "State.h"
+#include "../sdl/InitScreen.h"
 
 #include <cassert>
 
@@ -10,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);
@@ -151,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();
@@ -174,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(0.001f);
-               CurrentState()->UpdateWorld(0.001f);
+       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);
        }
 }