Thrive
engine.h
1 #pragma once
2 
3 #include "engine/game_state.h"
4 #include "engine/typedefs.h"
5 
6 #include <memory>
7 #include <vector>
8 #include <set>
9 
10 #include <luabind/object.hpp>
11 
12 class btDiscreteDynamicsWorld;
13 class lua_State;
14 
15 namespace luabind {
16  class scope;
17 }
18 
19 namespace Ogre {
20  class RenderWindow;
21  class Root;
22  class SceneManager;
23  class Viewport;
24 }
25 
26 namespace thrive{
27  class SoundManager;
28 }
29 
30 namespace OIS {
31  class InputManager;
32 }
33 
34 namespace thrive {
35 
36 class ComponentFactory;
37 class EntityManager;
38 class Entity;
39 class PlayerData;
40 class Keyboard;
41 class Mouse;
42 class OgreViewportSystem;
43 class CollisionSystem;
44 class System;
45 class RNG;
46 
47 
55 class Engine {
56 
57 public:
58 
87  static luabind::scope
88  luaBindings();
89 
93  Engine();
94 
99  Engine(const Engine& other) = delete;
100 
104  ~Engine();
105 
113 
130  GameState*
132  std::string name,
133  std::vector<std::unique_ptr<System>> systems,
134  GameState::Initializer initializer,
135  std::string guiLayoutName
136  );
137 
144  GameState*
145  currentGameState() const;
146 
150  PlayerData&
151  playerData();
152 
157  RNG&
158  rng();
159 
170  GameState*
171  getGameState(
172  const std::string& name
173  ) const;
174 
182  void
183  init();
184 
188  OIS::InputManager*
189  inputManager() const;
190 
195  const Keyboard&
196  keyboard() const;
197 
204  void
205  load(
206  std::string filename
207  );
214  bool
215  fileExists(
216  std::string filePath
217  );
218 
222  lua_State*
223  luaState();
224 
229  const Mouse&
230  mouse() const;
231 
235  Ogre::Root*
236  ogreRoot() const;
237 
244  void
245  save(
246  std::string filename
247  );
248 
264  void
265  saveCreation(
266  EntityId entityId,
267  const EntityManager& entityManager,
268  std::string name,
269  std::string type
270  ) const;
271 
275  void
276  saveCreation(
277  EntityId entityId,
278  std::string name,
279  std::string type
280  ) const;
281 
293  EntityId
294  loadCreation(
295  std::string file,
296  EntityManager& entityManager
297  );
298 
302  EntityId
303  loadCreation(
304  std::string file
305  );
306 
313  void
314  screenShot(
315  std::string path
316  );
317 
328  std::string
330  std::string stage
331  ) const;
332 
344  void
346  GameState* gameState
347  );
348 
355  void
356  shutdown();
357 
361  void
362  quit();
363 
367  void
368  pauseGame();
369 
373  void
374  resumeGame();
375 
376  SoundManager*
377  soundManager() const;
378 
388  void
389  update(
390  int milliseconds
391  );
392 
398  int
399  getResolutionWidth() const;
400 
406  int
407  getResolutionHeight() const;
408 
421  void
423  System& system,
424  int milliseconds
425  );
426 
435  bool
437  System& system
438  ) const;
439 
452  EntityId
454  EntityId oldEntityId,
455  EntityManager* oldEntityManager,
456  GameState* newGameState
457  );
458 
462  Ogre::RenderWindow*
463  renderWindow() const;
464 
468  void
469  registerConsoleObject(luabind::object consoleObject);
470 
471 
480  const std::string&
481  thriveVersion() const;
482 
483 private:
484 
485 
486 
487  struct Implementation;
488  std::unique_ptr<Implementation> m_impl;
489 
490 };
491 
492 }
std::function< void()> Initializer
Typedef for the game state's initializer function.
Definition: game_state.h:48
void registerConsoleObject(luabind::object consoleObject)
Registers the console object.
Definition: engine.cpp:983
int getResolutionWidth() const
Returns the width of the games window.
Definition: engine.cpp:953
const Keyboard & keyboard() const
Returns the keyboard interface.
Definition: engine.cpp:683
void resumeGame()
Resumes system updates of the game.
Definition: engine.cpp:583
Definition: engine.h:30
Random Number Generator.
Definition: rng.h:19
void init()
Initializes the engine.
Definition: engine.cpp:652
bool isSystemTimedShutdown(System &system) const
Returns whether the specified system has already been set for a timed shutdown.
Definition: engine.cpp:971
void shutdown()
Shuts the engine down.
Definition: engine.cpp:867
RNG & rng()
The engine's RNG.
Definition: engine.cpp:632
EntityId transferEntityGameState(EntityId oldEntityId, EntityManager *oldEntityManager, GameState *newGameState)
Transfers an entity from one gamestate to another.
Definition: engine.cpp:890
static luabind::scope luaBindings()
Lua bindings.
Definition: engine.cpp:547
std::string getCreationFileList(std::string stage) const
Obtains a list of filenames for saved creations that match the provided type.
Definition: engine.cpp:828
void screenShot(std::string path)
Takes a screenshot.
Definition: engine.cpp:821
Engine()
Constructor.
Definition: engine.cpp:587
Manages entities and their components.
Definition: entity_manager.h:23
A factory for components.
Definition: component_factory.h:19
Handles keyboard events.
Definition: keyboard.h:24
Handles mouse events.
Definition: mouse.h:28
A system handles one specific part of the game.
Definition: system.h:23
void load(std::string filename)
Loads a savegame.
Definition: engine.cpp:689
ComponentFactory & componentFactory()
Returns the internal component factory.
Definition: engine.cpp:597
void save(std::string filename)
Creates a savegame.
Definition: engine.cpp:736
PlayerData & playerData()
Object holding generic player data.
Definition: engine.cpp:862
void timedSystemShutdown(System &system, int milliseconds)
Keeps a system alive after being shut down for a specified amount of time.
Definition: engine.cpp:963
void saveCreation(EntityId entityId, const EntityManager &entityManager, std::string name, std::string type) const
Saves a creation to file.
Definition: engine.cpp:752
void pauseGame()
Pauses system updates of the game.
Definition: engine.cpp:578
Definition: sound_manager.h:15
Definition: player_data.h:18
void setCurrentGameState(GameState *gameState)
Sets the current game state.
Definition: engine.cpp:847
void update(int milliseconds)
Renders a single frame.
Definition: engine.cpp:908
const std::string & thriveVersion() const
Gets the current version of thrive as a string.
Definition: engine.cpp:978
Definition: bullet_to_ogre_system.h:5
Definition: bullet_ogre_conversion.h:6
lua_State * luaState()
The script engine's Lua state.
Definition: engine.cpp:713
GameState * createGameState(std::string name, std::vector< std::unique_ptr< System >> systems, GameState::Initializer initializer, std::string guiLayoutName)
Creates a new game state.
Definition: engine.cpp:603
Ogre::RenderWindow * renderWindow() const
The render window.
Definition: engine.cpp:730
Represents a distinct set of active systems and entities.
Definition: game_state.h:41
Definition: debug_drawing.h:8
const Mouse & mouse() const
Returns the mouse interface.
Definition: engine.cpp:718
GameState * currentGameState() const
Returns the currently active game state.
Definition: engine.cpp:627
OIS::InputManager * inputManager() const
The engine's input manager.
Definition: engine.cpp:677
void quit()
Request the game to close.
Definition: engine.cpp:880
~Engine()
Destructor.
Definition: engine.cpp:593
The heart of the game.
Definition: engine.h:55
GameState * getGameState(const std::string &name) const
Retrieves a game state.
Definition: engine.cpp:638
int getResolutionHeight() const
Returns the width of the games window.
Definition: engine.cpp:958
EntityId loadCreation(std::string file, EntityManager &entityManager)
Loads a creation from file.
Definition: engine.cpp:798
Ogre::Root * ogreRoot() const
The Ogre root object.
Definition: engine.cpp:724
bool fileExists(std::string filePath)
checks if a file exists
Definition: engine.cpp:697