GameKit  0.0.1a
C++ gamedev tools
ApplicationState.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: ApplicationState.hpp
5  *
6  * Description:
7  *
8  * Created: 05/06/2018 15:45:26
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_APPLICATIONSTATE_HPP_
15 #define GK_APPLICATIONSTATE_HPP_
16 
17 #include "gk/core/SDLHeaders.hpp"
18 #include "gk/gl/IDrawable.hpp"
19 #include "gk/gl/Transformable.hpp"
20 #include "gk/utils/NonCopyable.hpp"
21 
22 namespace gk {
23 
24 class ApplicationStateStack;
25 
30 class ApplicationState : public IDrawable, public Transformable, public NonCopyable {
31  public:
39 
44  ApplicationState(ApplicationState &&) = default;
45 
50  virtual ~ApplicationState() = default;
51 
57 
64  virtual void onEvent(const SDL_Event &) {}
65 
73  virtual void update() = 0;
74 
82 
89  void setStateStack(ApplicationStateStack *stateStack) { m_stateStack = stateStack; }
90 
91  protected:
99  void draw(gk::RenderTarget &, gk::RenderStates) const override {}
100 
102  // Member data
105 
107 };
108 
109 } // namespace gk
110 
111 #endif // GK_APPLICATIONSTATE_HPP_
112 
ApplicationState * m_parent
Parent to this state.
ApplicationStateStack * m_stateStack
Stack where this state belongs to.
void setStateStack(ApplicationStateStack *stateStack)
Change the stack this state belongs to.
virtual void update()=0
Execute actions every game tick.
ApplicationState(ApplicationState *parent=nullptr)
Default constructor.
virtual void onEvent(const SDL_Event &)
Do an action in response to an SDL event.
ApplicationState * parent()
Get the parent of this state.
void draw(gk::RenderTarget &, gk::RenderStates) const override
Draw the sprite to a render target.
Stack containing ApplicationState instances.
Abstract base class for game states.
ApplicationState & operator=(ApplicationState &&)=default
Defaulted move assignment operator.
Abstract base class for objects that can be drawn to a render target.
Definition: IDrawable.hpp:25
virtual ~ApplicationState()=default
Virtual destructor.