zenilib: zenilib/jni/external/zenilib/zeni_rest/Zeni/Game.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
Game.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
34 #ifndef ZENI_GAME_H
35 #define ZENI_GAME_H
36
37 #include <Zeni/Gamestate.h>
38 #include <Zeni/Hash_Map.h>
39 #include <Zeni/Singleton.h>
40 #include <Zeni/String.h>
41 #include <Zeni/Timer.h>
42
43 #include <SDL/SDL_gamecontroller.h>
44
45 /* \cond */
46 #include <stack>
47 #include <vector>
48 /* \endcond */
49
50 namespace Zeni {
51
52 class Console_State;
53 class Game;
54 class Popup_Menu_State_Factory;
55 class Popup_Pause_State_Factory;
56
57 class ZENI_REST_DLL Gamestate_Zero_Initializer {
58 public:
59 virtual ~Gamestate_Zero_Initializer() {}
60
61 virtual Gamestate_Base * operator()() = 0;
62 };
63
64 ZENI_REST_DLL extern Gamestate_Zero_Initializer * g_gzi;
65 ZENI_REST_DLL extern int g_argc;
66 ZENI_REST_DLL extern const char * const * g_argv;
67 #ifdef _WINDOWS
68 ZENI_REST_EXT template class ZENI_REST_DLL Singleton<Game>;
69 #endif
70
71 class ZENI_REST_DLL Game : public Singleton<Game> {
72 friend class Singleton<Game>;
73
74 static Game * create();
75
76 Game();
77 ~Game();
78
79 // Undefined
80 Game(const Game &);
81 Game & operator=(const Game &);
82
83 public:
84 inline Gamestate get_top();
85
86 #if !defined(ANDROID) && !defined(NDEBUG)
87 Console_State & get_console();
88 #endif
89 void write_to_console(const String &text);
90
91 inline size_t size() const;
92 void push_state(const Gamestate &state);
93 Gamestate pop_state();
94
95 #ifdef ANDROID
96 void on_event(android_app &app, const AInputEvent &event);
97 #else
98 void on_event(const SDL_Event &event);
99 #endif
100 void perform_logic();
101 void prerender();
102 void render();
103
104 inline size_t get_fps() const;
105 bool get_key_state(const int &key) const;
106 bool get_mouse_button_state(const int &button) const;
107 Sint16 get_controller_axis_state(const int &which, const SDL_GameControllerAxis &axis) const;
108 bool get_controller_button_state(const int &which, const SDL_GameControllerButton &button) const;
109
110 void run();
111
112 void push_Popup_Menu_State();
113 void push_Popup_Pause_State();
114 void replace_Popup_Menu_State_Factory(Popup_Menu_State_Factory * const popup_menu_state_factory);
115 void replace_Popup_Pause_State_Factory(Popup_Pause_State_Factory * const popup_pause_state_factory);
116
117 #ifndef ANDROID
118 struct ZENI_REST_DLL Controller_Mouse {
119 Controller_Mouse()
120 : enabled(false),
121 controller_axes(SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_LEFTY),
122 noise_zone(8192, 4096),
123 pixels_per_second(1000.0f, 1000.0f),
124 left_click(SDL_CONTROLLER_BUTTON_A),
125 escape(SDL_CONTROLLER_BUTTON_BACK),
126 scroll_down(SDL_CONTROLLER_BUTTON_DPAD_DOWN),
127 scroll_up(SDL_CONTROLLER_BUTTON_DPAD_UP)
128 {
129 }
130
131 bool enabled;
132
133 Point2i controller_axes;
134 Point2i noise_zone;
135 Point2i velocity;
136 Point2f pixels_per_second;
137
138 SDL_GameControllerButton left_click;
139 SDL_GameControllerButton escape;
140 SDL_GameControllerButton scroll_down;
141 SDL_GameControllerButton scroll_up;
142 } controller_mouse;
143 #endif
144
145 private:
146 void calculate_fps();
147
148 #ifdef _WINDOWS
149 #pragma warning( push )
150 #pragma warning( disable : 4251 )
151 #endif
152 std::stack<Gamestate> m_states;
153 Unordered_Map<int, bool> m_keys;
154 Unordered_Map<int, bool> m_mouse_buttons;
155 Unordered_Map<int, Unordered_Map<int, Sint16> > m_controller_axes;
156 Unordered_Map<int, Unordered_Map<int, bool> > m_controller_buttons;
157 #ifdef _WINDOWS
158 #pragma warning( pop )
159 #endif
160
161 Time time;
162 Time::Tick_Type ticks_passed, fps, fps_next;
163
164 Popup_Menu_State_Factory * m_popup_menu_state_factory;
165 Popup_Pause_State_Factory * m_popup_pause_state_factory;
166
167 #if !defined(ANDROID) && !defined(NDEBUG)
168 void activate_console();
169 void deactivate_console();
170 Gamestate & get_console_instance();
171
172 bool m_console_active;
173 #endif
174
175 public:
176 bool is_console_active() const;
177 };
178
179 ZENI_REST_DLL Game & get_Game();
180
181 struct ZENI_REST_DLL Zero_Gamestate : public Error {
182 Zero_Gamestate() : Error("Zeni Gamestate State is Empty") {}
183 };
184
185 }
186
187 #endif
SDL_CONTROLLER_AXIS_LEFTY
Definition: SDL_gamecontroller.h:198
Zeni::Popup_Pause_State_Factory
Definition: Popup_State.h:329
Zeni::Game::Controller_Mouse::velocity
Point2i velocity
Definition: Game.h:135
Zeni::Game::Controller_Mouse
Definition: Game.h:118
Zeni::Singleton< Game >
Zeni::Game::Controller_Mouse::pixels_per_second
Point2f pixels_per_second
Definition: Game.h:136
SDL_CONTROLLER_BUTTON_BACK
Definition: SDL_gamecontroller.h:244
f
GLclampf f
Definition: glew.h:3390
Zeni::Game::Controller_Mouse::noise_zone
Point2i noise_zone
Definition: Game.h:134
enabled
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
SDL_CONTROLLER_BUTTON_A
Definition: SDL_gamecontroller.h:240
Zeni::render
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
Definition: Vertex_Buffer.cpp:581
Zeni::Game::Controller_Mouse::scroll_up
SDL_GameControllerButton scroll_up
Definition: Game.h:141
SDL_GameControllerButton
SDL_GameControllerButton
Definition: SDL_gamecontroller.h:237
Zeni::get_Game
Game & get_Game()
Get access to the singleton.
Definition: Game.cpp:58
Zeni::Game
The Gamestate Stack.
Definition: Game.h:71
Zeni::String
Definition: String.h:29
SDL_gamecontroller.h
Zeni::Unordered_Map< int, bool >
android_app
Definition: android_native_app_glue.h:111
Zeni::Gamestate_Zero_Initializer::~Gamestate_Zero_Initializer
virtual ~Gamestate_Zero_Initializer()
Definition: Game.h:59
Zeni::Game::Controller_Mouse::left_click
SDL_GameControllerButton left_click
Definition: Game.h:138
Timer.h
Zeni::g_argc
int g_argc
Definition: Game.cpp:32
Zeni::Gamestate
A smartpointer for a Gamestate_Base.
Definition: Gamestate.h:169
SDL_CONTROLLER_AXIS_LEFTX
Definition: SDL_gamecontroller.h:197
Zeni::g_gzi
Gamestate_Zero_Initializer * g_gzi
Definition: Game.cpp:31
Zeni::Time::Tick_Type
size_t Tick_Type
Definition: Timer.h:65
SDL_CONTROLLER_BUTTON_DPAD_UP
Definition: SDL_gamecontroller.h:251
Zeni::Zero_Gamestate::Zero_Gamestate
Zero_Gamestate()
Definition: Game.h:182
Zeni::g_argv
const char *const * g_argv
Definition: Game.cpp:33
Zeni::Game::Controller_Mouse::enabled
bool enabled
Definition: Game.h:131
Singleton.h
Hash_Map.h
Zeni::Gamestate_Base
The base class for all gamestates.
Definition: Gamestate.h:82
Sint16
int16_t Sint16
A signed 16-bit integer type.
Definition: SDL_stdinc.h:133
String.h
Gamestate.h
Zeni::Zero_Gamestate
Definition: Game.h:181
SDL_Event
General event structure.
Definition: SDL_events.h:495
Zeni::Console_State
Provide a text console to process commands.
Definition: Console_State.h:48
Zeni::Error
The Error Class.
Definition: Error.h:52
Zeni::Game::Controller_Mouse::controller_axes
Point2i controller_axes
Definition: Game.h:133
Zeni::Point2f
A 2D Point represented with floats.
Definition: Coordinate.h:98
Zeni::Game::Controller_Mouse::scroll_down
SDL_GameControllerButton scroll_down
Definition: Game.h:140
Zeni::Game::Controller_Mouse::Controller_Mouse
Controller_Mouse()
Definition: Game.h:119
SDL_GameControllerAxis
SDL_GameControllerAxis
Definition: SDL_gamecontroller.h:194
Zeni::Gamestate_Zero_Initializer
Definition: Game.h:57
Zeni::Game::Controller_Mouse::escape
SDL_GameControllerButton escape
Definition: Game.h:139
false
#define false
Definition: ftrandom.c:50
SDL_CONTROLLER_BUTTON_DPAD_DOWN
Definition: SDL_gamecontroller.h:252
event
cl_event event
Definition: glew.h:3556
Zeni::Time
A Snapshot of the Timer.
Definition: Timer.h:63
size
GLsizei size
Definition: gl2ext.h:1467
Zeni::Point2i
A 2D Point represented with integers.
Definition: Coordinate.h:85