X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FApplication.h;h=db089e09356c168509f5bc1dcd2c4d8b741e4bab;hb=HEAD;hp=f70dd69a29185383f395566397769e980c32aff1;hpb=867fd5d9b79c3b9c1d0fb17ba9f55cfe971b93d5;p=l2e.git diff --git a/src/app/Application.h b/src/app/Application.h index f70dd69..db089e0 100644 --- a/src/app/Application.h +++ b/src/app/Application.h @@ -1,64 +1,92 @@ -/* - * Application.h - * - * Created on: Apr 8, 2012 - * Author: holy - */ - #ifndef APP_APPLICATION_H_ #define APP_APPLICATION_H_ +namespace app { + class State; +} +namespace sdl { + class InitScreen; +} + #include "Input.h" -#include "../sdl/InitScreen.h" +#include "Timer.h" #include +#include #include namespace app { -class State; - +/// Application controller class. +/// Operates on a state stack that can be modified via ChangeState, PushState, +/// and PopState. +/// All state changes are delayed until the looping mechanism gets control again +/// (i.e. after a top level state function returns, not during). +/// SDL key events are preprocessed, see app::Input. +/// The quit event (typically window closed or signal received) is caught and +/// results in immediate (that is, after the next input loop) termination. +/// Popped states will be deleted via the plain delete operator on an app::State +/// pointer. +/// Timers created by GlobalTimers() operate on actual application time and are +/// not paused when the current state is paused (as are the timers started by +/// the app::State members). class Application { public: - Application(sdl::InitScreen *screen, State *initialState); - ~Application(void); + Application(sdl::InitScreen &screen, State *initialState); + ~Application(); private: Application(const Application &); Application &operator =(const Application &); public: - void Run(void); - void Loop(void); + void Run(); + void Loop(); public: void ChangeState(State *); void PushState(State *); - void PopState(void); - void Quit(void); + void PopState(); + void Quit(); Input &Buttons() { return input; } const Input &Buttons() const { return input; } + Timers &GlobalTimers() { return globalTimers; } + +private: + struct StateCommand { + enum Type { + PUSH, POP, CHANGE + } type; + State *state; + }; private: - State *CurrentState(void); + State *CurrentState(); + bool StateChangePending() const { return !stateChanges.empty(); } + void UpdateState(); + void RealChangeState(State *); void RealPushState(State *); - void RealPopState(void); - void PopAllStates(void); + void RealPopState(); + void PopAllStates(); private: - void HandleEvents(void); + void HandleEvents(); void UpdateWorld(Uint32 deltaT); - void Render(void); + void Render(); private: - sdl::InitScreen *screen; + sdl::InitScreen &screen; std::stack states; + std::queue stateChanges; + Timers globalTimers; Input input; Uint32 last; + Uint32 remaining; + bool inStateChage; }; } -#endif /* APP_APPLICATION_H_ */ +#endif