zenilib  0.5.3.0
 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:
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 {
120  : enabled(false),
122  noise_zone(8192, 4096),
123  pixels_per_second(1000.0f, 1000.0f),
124  left_click(SDL_CONTROLLER_BUTTON_A),
126  scroll_down(SDL_CONTROLLER_BUTTON_DPAD_DOWN),
128  {
129  }
130 
131  bool enabled;
132 
137 
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;
154  Unordered_Map<int, bool> m_mouse_buttons;
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
GLclampf f
Definition: glew.h:3390
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
SDL_GameControllerButton scroll_up
Definition: Game.h:141
SDL_GameControllerButton
Game & get_Game()
Get access to the singleton.
Definition: Game.cpp:58
The Gamestate Stack.
Definition: Game.h:71
virtual ~Gamestate_Zero_Initializer()
Definition: Game.h:59
SDL_GameControllerButton left_click
Definition: Game.h:138
int g_argc
Definition: Game.cpp:32
A smartpointer for a Gamestate_Base.
Definition: Gamestate.h:169
Gamestate_Zero_Initializer * g_gzi
Definition: Game.cpp:31
size_t Tick_Type
Definition: Timer.h:65
const char *const * g_argv
Definition: Game.cpp:33
The base class for all gamestates.
Definition: Gamestate.h:82
int16_t Sint16
A signed 16-bit integer type.
Definition: SDL_stdinc.h:133
General event structure.
Definition: SDL_events.h:495
Provide a text console to process commands.
Definition: Console_State.h:48
The Error Class.
Definition: Error.h:52
A 2D Point represented with floats.
Definition: Coordinate.h:98
SDL_GameControllerButton scroll_down
Definition: Game.h:140
SDL_GameControllerAxis
SDL_GameControllerButton escape
Definition: Game.h:139
#define false
Definition: ftrandom.c:50
cl_event event
Definition: glew.h:3556
A Snapshot of the Timer.
Definition: Timer.h:63
GLsizei size
Definition: gl2ext.h:1467
A 2D Point represented with integers.
Definition: Coordinate.h:85