hx3d  1
2D/3D Simple Game Framework
game.hpp
1 /*
2  Game management.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_WINDOW_GAME
22 #define HX3D_WINDOW_GAME
23 
24 #include "hx3d/window/screen.hpp"
25 #include "hx3d/gui/text.hpp"
26 #include "hx3d/graphics/cameras/orthographic_camera.hpp"
27 #include "hx3d/graphics/batch.hpp"
28 #include "hx3d/graphics/framebuffer.hpp"
29 #include "hx3d/graphics/viewports/viewport.hpp"
30 #include "hx3d/graphics/sprite.hpp"
31 #include "hx3d/graphics/transition.hpp"
32 
33 #include "hx3d/utils/ptr.hpp"
34 #include "hx3d/utils/object_map.hpp"
35 
36 namespace hx3d {
37 namespace window {
38 
42 class Game {
43 public:
44  Game();
45 
49  virtual void create();
50 
54  virtual void render();
55 
61  virtual void update(float delta);
62 
69  virtual void resize(int width, int height);
70 
74  virtual void pause();
75 
79  virtual void resume();
80 
84  virtual void dispose();
85 
89  virtual void stop();
90 
96  void setScreen(Ptr<Screen> screen);
97 
103  void activateStats(bool enabled);
104 
110  void setTransition(const Ptr<graphics::Transition>& transition);
111 
117  void setViewport(const Ptr<graphics::viewports::Viewport>& viewport);
118 
125 
132 
141  glm::vec2 getSize();
142 
148  bool isRunning();
149 
150 private:
151  bool _running;
152  Ptr<Screen> _screen;
153  Ptr<Screen> _nextScreen;
154  gui::Text _deltaText;
155  gui::Text _fpsText;
156 
158  graphics::Batch _batch;
159 
160  graphics::Framebuffer _currentFB;
161  graphics::Framebuffer _nextFB;
162  Ptr<graphics::Transition> _currentTransition;
163  Ptr<graphics::viewports::Viewport> _currentViewport;
164 
165  ObjectMap _session;
166 
167  bool _showStats;
168 
169  void updateStats();
170 };
171 
172 } /* window */
173 } /* hx3d */
174 
175 #endif /* HX3D_WINDOW_GAME */
virtual void resume()
Resume the current screen.
Definition: game.cpp:62
virtual void update(float delta)
Update the current screen.
Definition: game.cpp:165
Game main class: multiple screens management.
Definition: game.hpp:42
virtual void render()
Render the current scren.
Definition: game.cpp:107
Text GUI element.
Definition: text.hpp:37
hx3d framework namespace
Definition: audio.hpp:26
virtual void dispose()
Clean the current screen.
Definition: game.cpp:52
glm::vec2 getSize()
Get the current game size.
Definition: game.cpp:88
2D orthographic camera w/ Z-buffer.
virtual void stop()
Stop the game.
Definition: game.cpp:194
bool isRunning()
Test if the game is running.
Definition: game.cpp:190
Simple base batch implementation. Draw at each draw call.
Definition: batch.hpp:36
Map of whatever you want. Useful for user data.
Definition: object_map.hpp:34
virtual void pause()
Pause the current screen.
Definition: game.cpp:57
void setScreen(Ptr< Screen > screen)
Set the current screen.
Definition: game.cpp:199
void setTransition(const Ptr< graphics::Transition > &transition)
Set the current transition.
Definition: game.cpp:67
const Ptr< graphics::viewports::Viewport > & getViewport()
Get the current viewport.
Definition: game.cpp:84
virtual void create()
Initialize the game.
Definition: game.cpp:50
void setViewport(const Ptr< graphics::viewports::Viewport > &viewport)
Set the current viewport.
Definition: game.cpp:71
Render-to-texture buffer.
Definition: framebuffer.hpp:37
virtual void resize(int width, int height)
Resize the current screen.
Definition: game.cpp:185
void activateStats(bool enabled)
Activate the stats.
Definition: game.cpp:222
ObjectMap & getSession()
Get the session.
Definition: game.cpp:161
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34