zenilib: zenilib/jni/external/zenilib/zeni_rest/Zeni/Gamestate.h Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Gamestate.h
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
57 #ifndef ZENI_GAMESTATE_H
58 #define ZENI_GAMESTATE_H
59
60 #include <Zeni/Core.h>
61
62 #include <SDL/SDL.h>
63
64 #if SDL_VERSION_ATLEAST(2,0,0)
65 #include <SDL/SDL_keycode.h>
66 #elif !defined(ANDROID)
67 #include <SDL/SDL_keysym.h>
68 typedef SDLKey SDL_Keycode;
69 typedef SDL_keysym SDL_Keysym;
70 #endif
71
72 #include <map>
73
74 struct android_app;
75 struct AInputEvent;
76
77 namespace Zeni {
78
79 class ZENI_REST_DLL Gamestate;
80
81 // Derive from this class
82 class ZENI_REST_DLL Gamestate_Base {
83 friend class Gamestate;
84
85 Gamestate_Base(const Gamestate_Base &rhs);
86 Gamestate_Base & operator=(const Gamestate_Base &rhs);
87
88 public:
89 Gamestate_Base() : m_count(0), m_pausable(false) {}
90 virtual ~Gamestate_Base() {}
91
92 // The control loop
93
95 #ifdef ANDROID
96 virtual void on_event(android_app &app, const AInputEvent &event);
97 #else
98 virtual void on_event(const SDL_Event &event);
99 #endif
100 virtual void perform_logic() {}
103 virtual void prerender() {}
105 virtual void render();
106
108 virtual void on_push();
110 virtual void on_cover();
112 virtual void on_uncover();
114 virtual void on_pop();
115
116 inline const bool & is_pausable() const;
117 inline void set_pausable(const bool &pausable_);
118
119 // Converters
120
121 #ifndef ANDROID
122 static char to_char(const SDL_Keysym &ks);
123 static SDL_Keycode to_sym(const String &text_version);
124 static String to_text(const SDL_Keycode &sym);
125 #endif
126
127 protected:
128 // Event handlers
129
130 #ifndef ANDROID
131 // Keyboard events
132 virtual void on_key(const SDL_KeyboardEvent &event);
133 // Mouse events
134 virtual void on_mouse_motion(const SDL_MouseMotionEvent &event);
135 virtual void on_mouse_button(const SDL_MouseButtonEvent &event);
136 #if SDL_VERSION_ATLEAST(1,3,0)
137 virtual void on_mouse_wheel(const SDL_MouseWheelEvent &event);
138 #endif
139 // Controller events
140 virtual void on_controller_axis(const SDL_ControllerAxisEvent &event);
141 virtual void on_controller_button(const SDL_ControllerButtonEvent &event);
142 virtual void on_controller_device(const SDL_ControllerDeviceEvent &event);
143 // Quit events
144 virtual void on_quit(const SDL_QuitEvent &event);
145 // Annoying events
146 #if SDL_VERSION_ATLEAST(1,3,0)
147 virtual void on_window_event(const SDL_WindowEvent &event);
148 #endif
149 virtual void on_system_wm_event(const SDL_SysWMEvent &event);
150 #if !SDL_VERSION_ATLEAST(2,0,0)
151 virtual void on_active(const SDL_ActiveEvent &event);
152 virtual void on_video_resize(const SDL_ResizeEvent &event);
153 #endif
154 #if !SDL_VERSION_ATLEAST(1,3,0)
155 virtual void on_video_expose(const SDL_ExposeEvent &event);
156 #endif
157 // Custom events
158 virtual void on_user_event(const SDL_UserEvent &event);
159 #endif
160
161 private:
162 inline void increment();
163 inline void decrement();
164 int m_count;
165
166 bool m_pausable;
167 };
168
169 class ZENI_REST_DLL Gamestate {
170 public:
171 inline Gamestate();
172 inline Gamestate(Gamestate_Base * const &state);
173 ~Gamestate();
174
175 inline Gamestate(const Gamestate &state);
176 inline Gamestate & operator=(const Gamestate &state);
177
178 #ifdef ANDROID
179 inline void on_event(android_app &app, const AInputEvent &event);
180 #else
181 inline void on_event(const SDL_Event &event);
182 #endif
183 inline void perform_logic();
184 inline void prerender();
185 inline void render();
186
187 inline void on_push();
188 inline void on_cover();
189 inline void on_uncover();
190 inline void on_pop();
191
192 inline const bool & is_pausable() const;
193
194 inline Gamestate_Base & get();
195
196 private:
197 Gamestate_Base *m_state;
198 };
199
200 }
201
202 #endif
SDL_QuitEvent
The &quot;quit requested&quot; event.
Definition: SDL_events.h:447
SDL_ControllerDeviceEvent
Controller device event structure (event.cdevice.*)
Definition: SDL_events.h:373
sym
SDL_Keycode sym
Definition: SDL_pspevents.c:51
Zeni::render
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
Definition: Vertex_Buffer.cpp:581
SDL_Keysym
The SDL keysym structure, used in key events.
Definition: SDL_keyboard.h:47
SDL_ControllerAxisEvent
Game controller axis motion event structure (event.caxis.*)
Definition: SDL_events.h:341
SDL_Keycode
Sint32 SDL_Keycode
The SDL virtual key representation.
Definition: SDL_keycode.h:42
SDL_Keysym
struct SDL_Keysym SDL_Keysym
The SDL keysym structure, used in key events.
Zeni::Gamestate_Base::~Gamestate_Base
virtual ~Gamestate_Base()
Definition: Gamestate.h:90
Zeni::String
Definition: String.h:29
Zeni::Gamestate_Base::prerender
virtual void prerender()
No actual rendering, but any logic strictly necessary for rendering.
Definition: Gamestate.h:103
SDL_UserEvent
A user-defined event type (event.user.*)
Definition: SDL_events.h:465
android_app
Definition: android_native_app_glue.h:111
SDL_KeyboardEvent
Keyboard button event structure (event.key.*)
Definition: SDL_events.h:176
SDL_keycode.h
Zeni::Gamestate
A smartpointer for a Gamestate_Base.
Definition: Gamestate.h:169
SDL_MouseWheelEvent
Mouse wheel event structure (event.wheel.*)
Definition: SDL_events.h:251
SDL_WindowEvent
Window state change event data (event.window.*)
Definition: SDL_events.h:160
SDL_MouseMotionEvent
Mouse motion event structure (event.motion.*)
Definition: SDL_events.h:218
SDL_ControllerButtonEvent
Game controller button event structure (event.cbutton.*)
Definition: SDL_events.h:358
SDL_MouseButtonEvent
Mouse button event structure (event.button.*)
Definition: SDL_events.h:234
Zeni::Gamestate_Base
The base class for all gamestates.
Definition: Gamestate.h:82
SDL_SysWMEvent
A video driver dependent system event (event.syswm.*) This event is disabled by default, you can enable it with SDL_EventState()
Definition: SDL_events.h:485
Zeni::Gamestate_Base::Gamestate_Base
Gamestate_Base()
Definition: Gamestate.h:89
SDL_Event
General event structure.
Definition: SDL_events.h:495
Core.h
false
#define false
Definition: ftrandom.c:50
event
cl_event event
Definition: glew.h:3556