X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fapp.cpp;h=880dc7118eaf2fcaa43e93b2a2e92c6ec91de5f1;hb=f5e5e8522b94a6b81a137d4bca7665ef15bcd2c6;hp=4a4769b4c688ae4cd7462e983040474536fd4ee3;hpb=29ee0558fdd951b25f41005ed721241b1f28aefa;p=blank.git diff --git a/src/app/app.cpp b/src/app/app.cpp index 4a4769b..880dc71 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -145,18 +145,41 @@ void Application::Render() { void Application::PushState(State *s) { + if (!states.empty()) { + states.top()->OnPause(); + } states.emplace(s); + ++s->ref_count; + if (s->ref_count == 1) { + s->OnEnter(); + } + s->OnResume(); } State *Application::PopState() { State *s = states.top(); states.pop(); + s->OnPause(); + s->OnExit(); + if (!states.empty()) { + states.top()->OnResume(); + } return s; } State *Application::SwitchState(State *s_new) { State *s_old = states.top(); states.top() = s_new; + --s_old->ref_count; + ++s_new->ref_count; + s_old->OnPause(); + if (s_old->ref_count == 0) { + s_old->OnExit(); + } + if (s_new->ref_count == 1) { + s_new->OnEnter(); + } + s_new->OnResume(); return s_old; }