]> git.localhorst.tv Git - l2e.git/blobdiff - src/app/Application.cpp
break out of physics loop if a state change happened
[l2e.git] / src / app / Application.cpp
index 29eaee781e9ba20780fafa2cc4bde331777d059a..4ff75d8ed10c1104f9abf38142b4ffe46c9d3a5a 100644 (file)
@@ -28,7 +28,7 @@ Application::~Application() {
 
 
 State *Application::CurrentState() {
-       return states.top();
+       return states.empty() ? 0 : states.top();
 }
 
 void Application::UpdateState() {
@@ -106,7 +106,10 @@ void Application::Quit() {
 
 void Application::PopAllStates() {
        while (!states.empty()) {
-               RealPopState();
+               states.top()->PauseState(*this, screen->Screen());
+               states.top()->ExitState(*this, screen->Screen());
+               delete states.top();
+               states.pop();
        }
 }
 
@@ -120,8 +123,12 @@ void Application::Run() {
 void Application::Loop() {
        Uint32 now(SDL_GetTicks());
        Uint32 deltaT(now - last);
-       if (deltaT > 34) deltaT = 34;
+       GlobalTimers().Update(deltaT);
+       if (deltaT > 30) deltaT = 30;
 
+       if (CurrentState()) {
+               CurrentState()->GraphicsTimers().Update(deltaT);
+       }
        HandleEvents();
        if (!StateChangePending()) {
                UpdateWorld(deltaT);
@@ -155,12 +162,13 @@ void Application::HandleEvents() {
                                break;
                }
        }
-       CurrentState()->HandleInput(input);
+       if (CurrentState()) CurrentState()->HandleEvents(input);
 }
 
 void Application::UpdateWorld(Uint32 deltaT) {
        if (!CurrentState()) return;
-       for (Uint32 i(0); i < deltaT; ++i) {
+       for (Uint32 i(0); i < deltaT && !StateChangePending(); ++i) {
+               CurrentState()->PhysicsTimers().Update(0.001f);
                CurrentState()->UpdateWorld(0.001f);
        }
 }