#ifndef APP_APPLICATION_H_
#define APP_APPLICATION_H_
+#include "Input.h"
+#include "Timer.h"
#include "../sdl/InitScreen.h"
#include <stack>
+#include <queue>
#include <SDL.h>
class Application {
public:
- explicit Application(SDL_Surface *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<Uint32> &GlobalTimers() { return globalTimers; }
private:
- State *CurrentState(void);
+ struct StateCommand {
+ enum Type {
+ PUSH, POP, CHANGE
+ } type;
+ State *state;
+ };
+
+private:
+ 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_Surface *screen;
+ sdl::InitScreen *screen;
std::stack<State *> states;
+ std::queue<StateCommand> stateChanges;
+ Timers<Uint32> globalTimers;
+ Input input;
Uint32 last;
};