zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Gamestate.hxx
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef ZENI_GAMESTATE_HXX
19 #define ZENI_GAMESTATE_HXX
20 
21 #include <Zeni/Gamestate.h>
22 
23 namespace Zeni {
24 
25  const bool & Gamestate_Base::is_pausable() const {
26  return m_pausable;
27  }
28 
29  void Gamestate_Base::set_pausable(const bool &pausable_) {
30  m_pausable = pausable_;
31  }
32 
33  void Gamestate_Base::increment() {
34  ++m_count;
35  }
36 
37  void Gamestate_Base::decrement() {
38  if(!--m_count)
39  delete this;
40  }
41 
43  : m_state(0)
44  {
45  }
46 
48  : m_state(state)
49  {
50  assert(m_state);
51 
52  if(m_state)
53  m_state->increment();
54  }
55 
57  : m_state(state.m_state)
58  {
59  if(m_state)
60  m_state->increment();
61  }
62 
64  if(state.m_state)
65  state.m_state->increment();
66 
67  if(m_state)
68  m_state->decrement();
69 
70  m_state = state.m_state;
71 
72  return *this;
73  }
74 
75 #ifdef ANDROID
76  void Gamestate::on_event(android_app &app, const AInputEvent &event) {
77  m_state->on_event(app, event);
78  }
79 #else
80  void Gamestate::on_event(const SDL_Event &event) {
81  m_state->on_event(event);
82  }
83 #endif
84 
86  m_state->perform_logic();
87  }
88 
90  m_state->prerender();
91  }
92 
94  m_state->render();
95  }
96 
98  m_state->on_push();
99  }
100 
102  m_state->on_cover();
103  }
104 
106  m_state->on_uncover();
107  }
108 
110  m_state->on_pop();
111  }
112 
113  const bool & Gamestate::is_pausable() const {
114  return m_state->is_pausable();
115  }
116 
118  return *m_state;
119  }
120 
121 }
122 
123 #endif
Gamestate & operator=(const Gamestate &state)
Definition: Gamestate.hxx:63
void on_event(const SDL_Event &event)
Definition: Gamestate.hxx:80
void set_pausable(const bool &pausable_)
Definition: Gamestate.hxx:29
virtual void render()
Then render. Called by Game as part of the main gameloop.
Definition: Gamestate.cpp:1093
virtual void on_pop()
Called when the Gamestate is popped off the stack in Game.
Definition: Gamestate.cpp:1110
#define assert(x)
Definition: SDL_malloc.c:1234
virtual void prerender()
No actual rendering, but any logic strictly necessary for rendering.
Definition: Gamestate.h:103
const bool & is_pausable() const
Definition: Gamestate.hxx:113
A smartpointer for a Gamestate_Base.
Definition: Gamestate.h:169
const bool & is_pausable() const
Definition: Gamestate.hxx:25
virtual void on_event(const SDL_Event &event)
First check for events. Called by Game as part of the main gameloop.
Definition: Gamestate.cpp:36
virtual void on_uncover()
Called when a Gamestate is popped off Game, making this Gamestate on top.
Definition: Gamestate.cpp:1107
The base class for all gamestates.
Definition: Gamestate.h:82
void perform_logic()
Definition: Gamestate.hxx:85
Gamestate_Base & get()
Definition: Gamestate.hxx:117
General event structure.
Definition: SDL_events.h:495
virtual void on_push()
Called when the Gamestate is pushed onto the stack in Game.
Definition: Gamestate.cpp:1101
void prerender()
Definition: Gamestate.hxx:89
virtual void perform_logic()
Then perform logic. Called by Game as part of the main gameloop.
Definition: Gamestate.h:101
virtual void on_cover()
Called when a Gamestate is pushed on top of this Gamestate in Game.
Definition: Gamestate.cpp:1104
cl_event event
Definition: glew.h:3556