CPP_SRCS += \
../src/app/Application.cpp \
../src/app/Arguments.cpp \
-../src/app/Input.cpp
+../src/app/Input.cpp \
+../src/app/State.cpp
OBJS += \
./src/app/Application.o \
./src/app/Arguments.o \
-./src/app/Input.o
+./src/app/Input.o \
+./src/app/State.o
CPP_DEPS += \
./src/app/Application.d \
./src/app/Arguments.d \
-./src/app/Input.d
+./src/app/Input.d \
+./src/app/State.d
# Each subdirectory must supply rules for building sources it contributes
CPP_SRCS += \
../src/app/Application.cpp \
../src/app/Arguments.cpp \
-../src/app/Input.cpp
+../src/app/Input.cpp \
+../src/app/State.cpp
OBJS += \
./src/app/Application.o \
./src/app/Arguments.o \
-./src/app/Input.o
+./src/app/Input.o \
+./src/app/State.o
CPP_DEPS += \
./src/app/Application.d \
./src/app/Arguments.d \
-./src/app/Input.d
+./src/app/Input.d \
+./src/app/State.d
# Each subdirectory must supply rules for building sources it contributes
void Application::RealChangeState(State *s) {
if (!states.empty()) {
- states.top()->OnPauseState(*this, screen.Screen());
- states.top()->OnExitState(*this, screen.Screen());
+ states.top()->PauseState(*this, screen.Screen());
+ states.top()->ExitState(*this, screen.Screen());
states.pop();
}
states.push(s);
- s->OnEnterState(*this, screen.Screen());
- s->OnResumeState(*this, screen.Screen());
+ s->EnterState(*this, screen.Screen());
+ s->ResumeState(*this, screen.Screen());
}
void Application::RealPushState(State *s) {
if (!states.empty()) {
- states.top()->OnPauseState(*this, screen.Screen());
+ states.top()->PauseState(*this, screen.Screen());
}
states.push(s);
- s->OnEnterState(*this, screen.Screen());
- s->OnResumeState(*this, screen.Screen());
+ s->EnterState(*this, screen.Screen());
+ s->ResumeState(*this, screen.Screen());
}
void Application::RealPopState() {
if (states.empty()) return;
- states.top()->OnPauseState(*this, screen.Screen());
- states.top()->OnExitState(*this, screen.Screen());
+ states.top()->PauseState(*this, screen.Screen());
+ states.top()->ExitState(*this, screen.Screen());
delete states.top();
states.pop();
if (!states.empty()) {
- states.top()->OnResumeState(*this, screen.Screen());
+ states.top()->ResumeState(*this, screen.Screen());
}
}
void Application::PopAllStates() {
while (!states.empty()) {
- states.top()->OnPauseState(*this, screen.Screen());
- states.top()->OnExitState(*this, screen.Screen());
+ states.top()->PauseState(*this, screen.Screen());
+ states.top()->ExitState(*this, screen.Screen());
delete states.top();
states.pop();
}
break;
case SDL_VIDEORESIZE:
screen.Resize(event.resize.w, event.resize.h);
- CurrentState()->OnResize(event.resize.w, event.resize.h);
+ CurrentState()->Resize(event.resize.w, event.resize.h);
break;
case SDL_KEYDOWN:
case SDL_KEYUP:
--- /dev/null
+/*
+ * State.cpp
+ *
+ * Created on: Oct 17, 2012
+ * Author: holy
+ */
+
+#include "State.h"
+
+namespace app {
+
+State::~State() {
+
+}
+
+
+void State::EnterState(Application &ctrl, SDL_Surface *screen) {
+ OnEnterState(ctrl, screen);
+}
+
+void State::ExitState(Application &ctrl, SDL_Surface *screen) {
+ OnExitState(ctrl, screen);
+}
+
+void State::ResumeState(Application &ctrl, SDL_Surface *screen) {
+ OnResumeState(ctrl, screen);
+}
+
+void State::PauseState(Application &ctrl, SDL_Surface *screen) {
+ OnPauseState(ctrl, screen);
+}
+
+void State::Resize(int width, int height) {
+ OnResize(width, height);
+}
+
+}
class State {
public:
- virtual ~State() { };
+ virtual ~State();
public:
+ /// Called by Application when pushing this state.
+ void EnterState(Application &ctrl, SDL_Surface *screen);
+ /// Called by Application when popping this state.
+ void ExitState(Application &ctrl, SDL_Surface *screen);
+ /// Called by Application when this state becomes the top state.
+ void ResumeState(Application &ctrl, SDL_Surface *screen);
+ /// Called by Application when this state no longer is the top state.
+ void PauseState(Application &ctrl, SDL_Surface *screen);
+
+ /// Called by Application on SDL window resize events.
+ void Resize(int width, int height);
+
+ /// Handle interactive events such as input and timers.
+ virtual void HandleEvents(const Input &) = 0;
+ /// Update the time-dependant world representation.
+ virtual void UpdateWorld(float deltaT) = 0;
+ /// Draw a picture of the world.
+ virtual void Render(SDL_Surface *) = 0;
+
+private:
/// Do some setup that needs an application and/or screen handle and thus
/// can not be done by the constructor.
/// Called when the state first enters the stack.
/// Will be fixed soom ;).
virtual void OnResize(int width, int height) = 0;
- /// Handle interactive events such as input and timers.
- virtual void HandleEvents(const Input &) = 0;
- /// Update the time-dependant world representation.
- virtual void UpdateWorld(float deltaT) = 0;
- /// Draw a picture of the world.
- virtual void Render(SDL_Surface *) = 0;
-
public:
/// Timers handle intended for graphics, sync'ed with render time.
/// These timers are only updated for the stack top and thus appear paused
void AddHero(const Hero &);
public:
- virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
- virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
- virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
- virtual void OnPauseState(app::Application &ctrl, SDL_Surface *screen);
-
- virtual void OnResize(int width, int height);
-
virtual void HandleEvents(const app::Input &);
virtual void UpdateWorld(float deltaT);
virtual void Render(SDL_Surface *);
void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
void RenderSmallHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
+private:
+ virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
+ virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
+ virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
+ virtual void OnPauseState(app::Application &ctrl, SDL_Surface *screen);
+
+ virtual void OnResize(int width, int height);
+
private:
void LoadInventory();
: ctrl(0), battle(battle), moveAnimation(0), targetAnimation(0), titleBarText(0), cursor(-1) { }
public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResize(int width, int height);
- virtual void HandleEvents(const app::Input &);
- virtual void UpdateWorld(float deltaT);
- virtual void Render(SDL_Surface *);
-
private:
void CheckAnimations();
bool HasAnimationsRunning() const;
: ctrl(0), battle(battle){ }
public:
+
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResize(int width, int height);
- virtual void HandleEvents(const app::Input &);
- virtual void UpdateWorld(float deltaT);
- virtual void Render(SDL_Surface *);
-
private:
void RenderTitleBar(SDL_Surface *screen, const geometry::Vector<int> &offset);
: ctrl(0), battle(battle) { }
public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResize(int width, int height);
- virtual void HandleEvents(const app::Input &);
- virtual void UpdateWorld(float deltaT);
- virtual void Render(SDL_Surface *);
-
private:
void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
: ctrl(0), battle(battle), parent(parent) { }
public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResize(int width, int height);
- virtual void HandleEvents(const app::Input &);
- virtual void UpdateWorld(float deltaT);
- virtual void Render(SDL_Surface *);
-
private:
void RenderFrame(SDL_Surface *, const geometry::Vector<int> &offset);
void RenderHeadline(SDL_Surface *, const geometry::Vector<int> &offset);
: ctrl(0), battle(battle), parent(parent) { }
public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResize(int width, int height);
- virtual void HandleEvents(const app::Input &);
- virtual void UpdateWorld(float deltaT);
- virtual void Render(SDL_Surface *);
-
private:
void RenderFrame(SDL_Surface *, const geometry::Vector<int> &offset);
void RenderHeadline(SDL_Surface *, const geometry::Vector<int> &offset);
: ctrl(0), battle(battle) { }
public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResize(int width, int height);
- virtual void HandleEvents(const app::Input &);
- virtual void UpdateWorld(float deltaT);
- virtual void Render(SDL_Surface *);
-
private:
void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset);
: ctrl(0), battle(battle), parent(parent) { }
public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResize(int width, int height);
- virtual void HandleEvents(const app::Input &);
- virtual void UpdateWorld(float deltaT);
- virtual void Render(SDL_Surface *);
-
private:
void RenderFrame(SDL_Surface *, const geometry::Vector<int> &offset);
void RenderHeadline(SDL_Surface *, const geometry::Vector<int> &offset);
: ctrl(0), battle(battle), parent(parent), selection(selection), cursorIcon(cursorIcon), flipFlop(true) { }
public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResize(int width, int height);
- virtual void HandleEvents(const app::Input &);
- virtual void UpdateWorld(float deltaT);
- virtual void Render(SDL_Surface *);
-
private:
void RenderCursors(SDL_Surface *screen, const geometry::Vector<int> &offset);
: ctrl(0), battle(battle), parent(parent), cursor(0), selected(-1), flipFlop(true) { }
public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResize(int width, int height);
- virtual void HandleEvents(const app::Input &);
- virtual void UpdateWorld(float deltaT);
- virtual void Render(SDL_Surface *);
-
private:
void MoveUp();
void MoveRight();
void ColorFade::OnResize(int width, int height) {
- slave->OnResize(width, height);
+ slave->Resize(width, height);
UpdateBlinds(width, height);
}
void SetLeadOutTime(int ms) { leadOut = ms; }
public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResize(int width, int height);
- virtual void HandleEvents(const app::Input &);
- virtual void UpdateWorld(float deltaT);
- virtual void Render(SDL_Surface *);
-
private:
void UpdateBlinds(int width, int height);
Uint8 GetAlpha() const;
virtual ~MapState() { }
public:
- virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
- virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
- virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
- virtual void OnPauseState(app::Application &ctrl, SDL_Surface *screen);
- virtual void OnResize(int width, int height);
-
virtual void HandleEvents(const app::Input &);
virtual void UpdateWorld(float deltaT);
virtual void Render(SDL_Surface *);
virtual void HandleSyscall(common::ScriptRunner &);
+private:
+ virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
+ virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
+ virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
+ virtual void OnPauseState(app::Application &ctrl, SDL_Surface *screen);
+
+ virtual void OnResize(int width, int height);
+
private:
static bool ZCompare(const Entity *lhs, const Entity *rhs);
virtual ~TransitionState() { }
public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+private:
virtual void OnEnterState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnExitState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResumeState(app::Application &ctrl, SDL_Surface *screen);
virtual void OnResize(int width, int height);
- virtual void HandleEvents(const app::Input &);
- virtual void UpdateWorld(float deltaT);
- virtual void Render(SDL_Surface *);
-
private:
app::Application *ctrl;
MapState *ms;