Thrive
game_state.h
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 #include <iostream>
6 
7 class btDiscreteDynamicsWorld;
8 
9 namespace luabind {
10  class scope;
11 }
12 
13 namespace Ogre {
14  class SceneManager;
15 }
16 
17 namespace thrive {
18 
19 class CEGUIWindow;
20 class Engine;
21 class EntityManager;
22 class StorageContainer;
23 class System;
24 
41 class GameState {
42 
43 public:
44 
48  using Initializer = std::function<void()>;
49 
60  static luabind::scope
61  luaBindings();
62 
67  GameState(const GameState&) = delete;
68 
72  ~GameState();
73 
78  GameState& operator=(const GameState&) = delete;
79 
85  Engine&
86  engine();
87 
93  const Engine&
94  engine() const;
95 
102  entityManager();
103 
109  const EntityManager&
110  entityManager() const;
111 
117  std::string
118  name() const;
119 
123  btDiscreteDynamicsWorld*
124  physicsWorld() const;
125 
130  rootGUIWindow();
131 
135  Ogre::SceneManager*
136  sceneManager() const;
137 
138  template<typename S>
139  S*
140  findSystem() {
141  for (const auto& system : this->systems()) {
142  S* foundSystem = dynamic_cast<S*>(system.get());
143  if (foundSystem) {
144  return foundSystem;
145  }
146  }
147  return nullptr;
148  }
149 
150 private:
151 
152  friend class Engine;
153 
172  GameState(
173  Engine& engine,
174  std::string name,
175  std::vector<std::unique_ptr<System>> systems,
176  Initializer initializer,
177  std::string guiLayoutName
178  );
179 
183  void
184  activate();
185 
189  void
190  deactivate();
191 
197  void
198  init();
199 
200  const std::vector<std::unique_ptr<System>>&
201  systems() const;
202 
210  void
211  load(
212  const StorageContainer& storage
213  );
214 
220  void
221  shutdown();
222 
230  StorageContainer
231  storage() const;
232 
242  void
243  update(
244  int renderTime,
245  int logicTime
246  );
247 
248  struct Implementation;
249  std::unique_ptr<Implementation> m_impl;
250 
251 
252 };
253 
254 }
EntityManager & entityManager()
Returns the game state's entity manager.
Definition: game_state.cpp:155
std::function< void()> Initializer
Typedef for the game state's initializer function.
Definition: game_state.h:48
Engine & engine()
Returns the engine this game state belongs to.
Definition: game_state.cpp:143
~GameState()
Destructor.
Definition: game_state.cpp:119
Manages entities and their components.
Definition: entity_manager.h:23
Definition: CEGUIWindow.h:17
Ogre::SceneManager * sceneManager() const
The Ogre scene manager.
Definition: game_state.cpp:220
std::string name() const
The game state's name.
Definition: game_state.cpp:201
GameState(const GameState &)=delete
Not copyable.
Definition: bullet_to_ogre_system.h:5
Definition: bullet_ogre_conversion.h:6
static luabind::scope luaBindings()
Lua bindings.
Definition: game_state.cpp:98
Represents a distinct set of active systems and entities.
Definition: game_state.h:41
Definition: debug_drawing.h:8
CEGUIWindow rootGUIWindow()
The root CEGUIWindow.
Definition: game_state.cpp:212
btDiscreteDynamicsWorld * physicsWorld() const
The physics world.
Definition: game_state.cpp:207
The heart of the game.
Definition: engine.h:55
GameState & operator=(const GameState &)=delete
Not copyable.