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);
}
void Application::UpdateState() {
+ inStateChage = true;
while (!stateChanges.empty()) {
switch (stateChanges.front().type) {
case StateCommand::PUSH:
}
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) {