Advertisement
Guest User

Untitled

a guest
Sep 14th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.08 KB | None | 0 0
  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 OgreOggSound {
  27. class OgreOggSoundManager;
  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.  
  48. /**
  49. * @brief The heart of the game
  50. *
  51. * The engine keeps an ordered list of System objects and updates them each
  52. * frame. It handles initialization and shutdown of graphics, physics, scripts
  53. * and more.
  54. */
  55. class Engine {
  56.  
  57. public:
  58.  
  59. /**
  60. * @brief Lua bindings
  61. *
  62. * Exposes:
  63. * - Engine::createGameState()
  64. * - Engine::currentGameState()
  65. * - Engine::getGameState()
  66. * - Engine::setCurrentGameState()
  67. * - Engine::playerData()
  68. * - Engine::load()
  69. * - Engine::save()
  70. * - Engine::saveCreation()
  71. * - Engine::loadCreation()
  72. * - Engine::quit()
  73. * - Engine::timedSystemShutdown()
  74. * - Engine::isSystemTimedShutdown()
  75. * - Engine::componentFactory() (as property)
  76. * - Engine::keyboard() (as property)
  77. * - Engine::mouse() (as property)
  78. * - Engine::thriveVersion()
  79. * - Engine::registerConsoleObject()
  80. *
  81. * @return
  82. */
  83. static luabind::scope
  84. luaBindings();
  85.  
  86. /**
  87. * @brief Constructor
  88. */
  89. Engine();
  90.  
  91. /**
  92. * @brief Non-copyable
  93. *
  94. */
  95. Engine(const Engine& other) = delete;
  96.  
  97. /**
  98. * @brief Destructor
  99. */
  100. ~Engine();
  101.  
  102. /**
  103. * @brief Returns the internal component factory
  104. *
  105. * @return
  106. */
  107. ComponentFactory&
  108. componentFactory();
  109.  
  110. /**
  111. * @brief Creates a new game state
  112. *
  113. * @param name
  114. * The game state's name
  115. *
  116. * @param systems
  117. * The systems active in the game state
  118. *
  119. * @param initializer
  120. * The initialization function for the game state
  121. *
  122. * @return
  123. * The new game state. Will never be \c null. It is returned as a pointer
  124. * as a convenience for Lua bindings, which don't handle references well.
  125. */
  126. GameState*
  127. createGameState(
  128. std::string name,
  129. std::vector<std::unique_ptr<System>> systems,
  130. GameState::Initializer initializer,
  131. std::string guiLayoutName
  132. );
  133.  
  134. /**
  135. * @brief Returns the currently active game state
  136. *
  137. * If no game state has been set yet, returns \c nullptr
  138. *
  139. */
  140. GameState*
  141. currentGameState() const;
  142.  
  143. /**
  144. * @brief Object holding generic player data
  145. */
  146. PlayerData&
  147. playerData();
  148.  
  149. /**
  150. * @brief The engine's RNG
  151. *
  152. */
  153. RNG&
  154. rng();
  155.  
  156. /**
  157. * @brief Retrieves a game state
  158. *
  159. * @param name
  160. * The game state's name
  161. *
  162. * @return
  163. * The game state with \a name or \c nullptr if no game state with
  164. * this name exists.
  165. */
  166. GameState*
  167. getGameState(
  168. const std::string& name
  169. ) const;
  170.  
  171. /**
  172. * @brief Initializes the engine
  173. *
  174. * This sets up basic data structures for the different engine parts
  175. * (input, graphics, physics, etc.) and then calls System::init() on
  176. * all systems.
  177. */
  178. void
  179. init();
  180.  
  181. /**
  182. * @brief The engine's input manager
  183. */
  184. OIS::InputManager*
  185. inputManager() const;
  186.  
  187. /**
  188. * @brief Returns the keyboard interface
  189. *
  190. */
  191. const Keyboard&
  192. keyboard() const;
  193.  
  194. /**
  195. * @brief Loads a savegame
  196. *
  197. * @param filename
  198. * The file to load
  199. */
  200. void
  201. load(
  202. std::string filename
  203. );
  204.  
  205. /**
  206. * @brief The script engine's Lua state
  207. */
  208. lua_State*
  209. luaState();
  210.  
  211. /**
  212. * @brief Returns the mouse interface
  213. *
  214. */
  215. const Mouse&
  216. mouse() const;
  217.  
  218. /**
  219. * @brief The Ogre root object
  220. */
  221. Ogre::Root*
  222. ogreRoot() const;
  223.  
  224. /**
  225. * @brief Creates a savegame
  226. *
  227. * @param filename
  228. * The file to save
  229. */
  230. void
  231. save(
  232. std::string filename
  233. );
  234.  
  235. /**
  236. * @brief Saves a creation to file
  237. *
  238. * @param entityId
  239. * The entity which represents the creation to save
  240. *
  241. * @param entityManager
  242. * The entity manager that manages the entity
  243. *
  244. * @param name
  245. * The name of the file
  246. *
  247. * @param type
  248. * The type of creation. This also becomes the file extension.
  249. */
  250. void
  251. saveCreation(
  252. EntityId entityId,
  253. const EntityManager& entityManager,
  254. std::string name,
  255. std::string type
  256. ) const;
  257.  
  258. /**
  259. * @brief Overload of above
  260. */
  261. void
  262. saveCreation(
  263. EntityId entityId,
  264. std::string name,
  265. std::string type
  266. ) const;
  267.  
  268. /**
  269. * @brief Loads a creation from file
  270. *
  271. * @param file
  272. * The file to load from
  273. *
  274. * @param entityManager
  275. * The entity manager that will manage the loaded entity
  276. *
  277. * @return entityId
  278. */
  279. EntityId
  280. loadCreation(
  281. std::string file,
  282. EntityManager& entityManager
  283. );
  284.  
  285. /**
  286. * @brief Overload of above
  287. */
  288. EntityId
  289. loadCreation(
  290. std::string file
  291. );
  292.  
  293. /**
  294. * @brief Obtains a list of filenames for saved creations that match the provided type
  295. *
  296. * @param stage
  297. * The game stage to filter creations on
  298. *
  299. * @return
  300. * A string of concatenated paths separated by spaces.
  301. * Optimally a vector of strings would be returned but luabind causes occasional crashes with that.
  302. */
  303. std::string
  304. getCreationFileList(
  305. std::string stage
  306. ) const;
  307.  
  308. /**
  309. * @brief Sets the current game state
  310. *
  311. * The game state will be activated at the beginning of the next frame.
  312. *
  313. * \a gameState must not be \c null. It's passed by pointer as a
  314. * convenience for the Lua bindings (which can't handle references well).
  315. *
  316. * @param gameState
  317. * The new game state
  318. */
  319. void
  320. setCurrentGameState(
  321. GameState* gameState
  322. );
  323.  
  324. /**
  325. * @brief Shuts the engine down
  326. *
  327. * This calls System::shutdown() on all systems and then destroys the data
  328. * structures created in Engine::init().
  329. */
  330. void
  331. shutdown();
  332.  
  333. /**
  334. * @brief Request the game to close
  335. */
  336. void
  337. quit();
  338.  
  339. OgreOggSound::OgreOggSoundManager*
  340. soundManager() const;
  341.  
  342. /**
  343. * @brief Renders a single frame
  344. *
  345. * Before calling update() the first time, you need to call Engine::init().
  346. *
  347. * @param milliseconds
  348. * The number of milliseconds to advance. For real-time, this is the
  349. * number of milliseconds since the last frame.
  350. */
  351. void
  352. update(
  353. int milliseconds
  354. );
  355.  
  356. /**
  357. * @brief Keeps a system alive after being shut down for a specified amount of time
  358. *
  359. * Note that this causes update to be called for the specified duration so be careful
  360. * to ensure that the system is not enabled or it will get update calls twice.
  361. *
  362. * @param system
  363. * The system to keep updated
  364. *
  365. * @param milliseconds
  366. * The number of milliseconds to keep the system updated for
  367. */
  368. void
  369. timedSystemShutdown(
  370. System& system,
  371. int milliseconds
  372. );
  373.  
  374. /**
  375. * @brief Returns whether the specified system has already been set for a timed shutdown
  376. *
  377. * @param system
  378. * The system to check for
  379. *
  380. * @return
  381. */
  382. bool
  383. isSystemTimedShutdown(
  384. System& system
  385. ) const;
  386.  
  387. /**
  388. * @brief Transfers an entity from one gamestate to another
  389. *
  390. * @param oldEntityId
  391. * The id of the entity to transfer in the old entitymanager
  392. *
  393. * @param oldEntityManager
  394. * The old entitymanager which is currently handling the entity
  395. *
  396. * @param newGameState
  397. * The new gamestate to transfer the entity to
  398. */
  399. EntityId
  400. transferEntityGameState(
  401. EntityId oldEntityId,
  402. EntityManager* oldEntityManager,
  403. GameState* newGameState
  404. );
  405.  
  406. /**
  407. * @brief The render window
  408. */
  409. Ogre::RenderWindow*
  410. renderWindow() const;
  411.  
  412. /**
  413. * @brief Registers the console object
  414. */
  415. void
  416. registerConsoleObject(luabind::object consoleObject);
  417.  
  418.  
  419. /**
  420. * @brief Gets the current version of thrive as a string.
  421. *
  422. * The version is loaded from thriveversion.ver file.
  423. * It returns as "unknown" if that file was not found
  424. *
  425. * @return versionString
  426. */
  427. const std::string&
  428. thriveVersion() const;
  429.  
  430. private:
  431.  
  432.  
  433.  
  434. struct Implementation;
  435. std::unique_ptr<Implementation> m_impl;
  436.  
  437. };
  438.  
  439. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement