]> git.localhorst.tv Git - l2e.git/blobdiff - src/app/Application.cpp
added option for sped up integration
[l2e.git] / src / app / Application.cpp
index 64a8602e8d9b1c551bd2940224c3a1ab72746292..830223ef0381c5025245cac2a6c09c1cce821895 100644 (file)
@@ -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);
        }
 }