]> git.localhorst.tv Git - l2e.git/commitdiff
better handling of nested state changes
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 9 Oct 2012 20:40:06 +0000 (22:40 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 9 Oct 2012 20:40:06 +0000 (22:40 +0200)
src/app/Application.cpp
src/app/Application.h

index 4ff75d8ed10c1104f9abf38142b4ffe46c9d3a5a..4de48d4f90541ad55481587c092c772015f88cd2 100644 (file)
@@ -16,7 +16,8 @@ namespace app {
 Application::Application(sdl::InitScreen *screen, State *initialState)
 : screen(screen)
 , states()
-, last(SDL_GetTicks()) {
+, last(SDL_GetTicks())
+, inStateChage(false) {
        assert(screen && "cannot create application without screen");
        assert(initialState && "cannot create application without initial state");
        RealPushState(initialState);
@@ -32,6 +33,7 @@ State *Application::CurrentState() {
 }
 
 void Application::UpdateState() {
+       inStateChage = true;
        while (!stateChanges.empty()) {
                switch (stateChanges.front().type) {
                        case StateCommand::PUSH:
@@ -46,27 +48,40 @@ void Application::UpdateState() {
                }
                stateChanges.pop();
        }
+       inStateChage = false;
 }
 
 void Application::ChangeState(State *s) {
-       StateCommand cmd;
-       cmd.type = StateCommand::CHANGE;
-       cmd.state = s;
-       stateChanges.push(cmd);
+       if (inStateChage) {
+               RealChangeState(s);
+       } else {
+               StateCommand cmd;
+               cmd.type = StateCommand::CHANGE;
+               cmd.state = s;
+               stateChanges.push(cmd);
+       }
 }
 
 void Application::PushState(State *s) {
-       StateCommand cmd;
-       cmd.type = StateCommand::PUSH;
-       cmd.state = s;
-       stateChanges.push(cmd);
+       if (inStateChage) {
+               RealPushState(s);
+       } else {
+               StateCommand cmd;
+               cmd.type = StateCommand::PUSH;
+               cmd.state = s;
+               stateChanges.push(cmd);
+       }
 }
 
 void Application::PopState() {
-       StateCommand cmd;
-       cmd.type = StateCommand::POP;
-       cmd.state = 0;
-       stateChanges.push(cmd);
+       if (inStateChage) {
+               RealPopState();
+       } else {
+               StateCommand cmd;
+               cmd.type = StateCommand::POP;
+               cmd.state = 0;
+               stateChanges.push(cmd);
+       }
 }
 
 void Application::RealChangeState(State *s) {
index b7b0001f7bbbf874a193f7a8dbaeb0e2cd50a07a..41198bce88c4f2e4f5ca1a7c07c8af9c713d9c8b 100644 (file)
@@ -71,6 +71,7 @@ private:
        Timers<Uint32> globalTimers;
        Input input;
        Uint32 last;
+       bool inStateChage;
 
 };