Thrive
Classes | Public Member Functions | Static Public Member Functions | List of all members
thrive::Engine Class Reference

The heart of the game. More...

#include <engine.h>

Classes

struct  Implementation
 

Public Member Functions

 Engine ()
 Constructor.
 
 Engine (const Engine &other)=delete
 Non-copyable.
 
 ~Engine ()
 Destructor.
 
ComponentFactory & componentFactory ()
 Returns the internal component factory. More...
 
GameState * createGameState (std::string name, std::vector< std::unique_ptr< System >> systems, GameState::Initializer initializer, std::string guiLayoutName)
 Creates a new game state. More...
 
GameState * currentGameState () const
 Returns the currently active game state. More...
 
PlayerData & playerData ()
 Object holding generic player data.
 
RNG & rng ()
 The engine's RNG.
 
GameState * getGameState (const std::string &name) const
 Retrieves a game state. More...
 
void init ()
 Initializes the engine. More...
 
OIS::InputManager * inputManager () const
 The engine's input manager.
 
const Keyboard & keyboard () const
 Returns the keyboard interface.
 
void load (std::string filename)
 Loads a savegame. More...
 
bool fileExists (std::string filePath)
 checks if a file exists More...
 
lua_State * luaState ()
 The script engine's Lua state.
 
const Mouse & mouse () const
 Returns the mouse interface.
 
Ogre::Root * ogreRoot () const
 The Ogre root object.
 
void save (std::string filename)
 Creates a savegame. More...
 
void saveCreation (EntityId entityId, const EntityManager &entityManager, std::string name, std::string type) const
 Saves a creation to file. More...
 
void saveCreation (EntityId entityId, std::string name, std::string type) const
 Overload of above.
 
EntityId loadCreation (std::string file, EntityManager &entityManager)
 Loads a creation from file. More...
 
EntityId loadCreation (std::string file)
 Overload of above.
 
void screenShot (std::string path)
 Takes a screenshot. More...
 
std::string getCreationFileList (std::string stage) const
 Obtains a list of filenames for saved creations that match the provided type. More...
 
void setCurrentGameState (GameState *gameState)
 Sets the current game state. More...
 
void shutdown ()
 Shuts the engine down. More...
 
void quit ()
 Request the game to close.
 
void pauseGame ()
 Pauses system updates of the game.
 
void resumeGame ()
 Resumes system updates of the game.
 
SoundManager * soundManager () const
 
void update (int milliseconds)
 Renders a single frame. More...
 
int getResolutionWidth () const
 Returns the width of the games window. More...
 
int getResolutionHeight () const
 Returns the width of the games window. More...
 
void timedSystemShutdown (System &system, int milliseconds)
 Keeps a system alive after being shut down for a specified amount of time. More...
 
bool isSystemTimedShutdown (System &system) const
 Returns whether the specified system has already been set for a timed shutdown. More...
 
EntityId transferEntityGameState (EntityId oldEntityId, EntityManager *oldEntityManager, GameState *newGameState)
 Transfers an entity from one gamestate to another. More...
 
Ogre::RenderWindow * renderWindow () const
 The render window.
 
void registerConsoleObject (luabind::object consoleObject)
 Registers the console object.
 
const std::string & thriveVersion () const
 Gets the current version of thrive as a string. More...
 

Static Public Member Functions

static luabind::scope luaBindings ()
 Lua bindings. More...
 

Detailed Description

The heart of the game.

The engine keeps an ordered list of System objects and updates them each frame. It handles initialization and shutdown of graphics, physics, scripts and more.

Member Function Documentation

ComponentFactory & Engine::componentFactory ( )

Returns the internal component factory.

Returns
GameState * Engine::createGameState ( std::string  name,
std::vector< std::unique_ptr< System >>  systems,
GameState::Initializer  initializer,
std::string  guiLayoutName 
)

Creates a new game state.

Parameters
nameThe game state's name
systemsThe systems active in the game state
initializerThe initialization function for the game state
Returns
The new game state. Will never be null. It is returned as a pointer as a convenience for Lua bindings, which don't handle references well.
GameState * Engine::currentGameState ( ) const

Returns the currently active game state.

If no game state has been set yet, returns nullptr

bool Engine::fileExists ( std::string  filePath)

checks if a file exists

Parameters
filenameThe file to check for
std::string Engine::getCreationFileList ( std::string  stage) const

Obtains a list of filenames for saved creations that match the provided type.

Parameters
stageThe game stage to filter creations on
Returns
A string of concatenated paths separated by spaces. Optimally a vector of strings would be returned but luabind causes occasional crashes with that.
GameState * Engine::getGameState ( const std::string &  name) const

Retrieves a game state.

Parameters
nameThe game state's name
Returns
The game state with name or nullptr if no game state with this name exists.
int Engine::getResolutionHeight ( ) const

Returns the width of the games window.

Returns
int Engine::getResolutionWidth ( ) const

Returns the width of the games window.

Returns
void Engine::init ( )

Initializes the engine.

This sets up basic data structures for the different engine parts (input, graphics, physics, etc.) and then calls System::init() on all systems.

bool Engine::isSystemTimedShutdown ( System &  system) const

Returns whether the specified system has already been set for a timed shutdown.

Parameters
systemThe system to check for
Returns
void Engine::load ( std::string  filename)

Loads a savegame.

Parameters
filenameThe file to load
EntityId Engine::loadCreation ( std::string  file,
EntityManager &  entityManager 
)

Loads a creation from file.

Parameters
fileThe file to load from
entityManagerThe entity manager that will manage the loaded entity
Returns
entityId
luabind::scope Engine::luaBindings ( )
static
void Engine::save ( std::string  filename)

Creates a savegame.

Parameters
filenameThe file to save
void Engine::saveCreation ( EntityId  entityId,
const EntityManager &  entityManager,
std::string  name,
std::string  type 
) const

Saves a creation to file.

Parameters
entityIdThe entity which represents the creation to save
entityManagerThe entity manager that manages the entity
nameThe name of the file
typeThe type of creation. This also becomes the file extension.
void Engine::screenShot ( std::string  path)

Takes a screenshot.

Parameters
pathThe path and filename relative to exe
void Engine::setCurrentGameState ( GameState *  gameState)

Sets the current game state.

The game state will be activated at the beginning of the next frame.

gameState must not be null. It's passed by pointer as a convenience for the Lua bindings (which can't handle references well).

Parameters
gameStateThe new game state
void Engine::shutdown ( )

Shuts the engine down.

This calls System::shutdown() on all systems and then destroys the data structures created in Engine::init().

const std::string & Engine::thriveVersion ( ) const

Gets the current version of thrive as a string.

The version is loaded from thriveversion.ver file. It returns as "unknown" if that file was not found

Returns
versionString
void Engine::timedSystemShutdown ( System &  system,
int  milliseconds 
)

Keeps a system alive after being shut down for a specified amount of time.

Note that this causes update to be called for the specified duration so be careful to ensure that the system is not enabled or it will get update calls twice.

Parameters
systemThe system to keep updated
millisecondsThe number of milliseconds to keep the system updated for
EntityId Engine::transferEntityGameState ( EntityId  oldEntityId,
EntityManager *  oldEntityManager,
GameState *  newGameState 
)

Transfers an entity from one gamestate to another.

Parameters
oldEntityIdThe id of the entity to transfer in the old entitymanager
oldEntityManagerThe old entitymanager which is currently handling the entity
newGameStateThe new gamestate to transfer the entity to
void Engine::update ( int  milliseconds)

Renders a single frame.

Before calling update() the first time, you need to call Engine::init().

Parameters
millisecondsThe number of milliseconds to advance. For real-time, this is the number of milliseconds since the last frame.

The documentation for this class was generated from the following files: