GameEngine

The engine that drives the game.  The Singleton class GameEngine manages the Game itself.  It provides several sub-engines that outside objects have access to (through interfaces) that are responsible for different parts of the system.  GameEngine is the one single command and control center for running the game.  The application is only responsible for starting and stopping the GameEngine at application load and exit, and the GameEngine handles all other initialization and cleanup of Game and Map data and all sub-engines.

GameEngine only returns interfaces to the sub-engines by design.  This allows the actual implementations of the interfaces used internally by GameEngine to change dramatically without having to recompile the entire project.

Derived From

Singleton

Project

RulesCore

Include

GameEngine.h

Summary
The engine that drives the game.
Provides access to the PluginEngine.
Provides access to the RuleEngine.
Provides access to the ImageEngine.
Provides access to the GameObjectEngine.
Provides access to the DrawObjectEngine.
Provides access to the SoundEngine.
Provides access to the AnyEngine.
Provides access to the INetworkEngine interface, which may not exist if the game is not being played on a network.
Provides read-only access to the current Map.
Returns the index in the MapDatabase of the currently loaded Map.
Registers (or unregisters, if network parameter is empty) the given INetworkEngine interface as the current network.
Loads the Map at the given MapDatabase index into memory.
Starts the GameEngine.
Stops the GameEngine.
Loads a Game from disk.
Saves the currently played Game to disk.
The GameEngine constructor.
The GameEngine destructor.

Public

Summary
Provides access to the PluginEngine.
Provides access to the RuleEngine.
Provides access to the ImageEngine.
Provides access to the GameObjectEngine.
Provides access to the DrawObjectEngine.
Provides access to the SoundEngine.
Provides access to the AnyEngine.
Provides access to the INetworkEngine interface, which may not exist if the game is not being played on a network.
Provides read-only access to the current Map.
Returns the index in the MapDatabase of the currently loaded Map.
Registers (or unregisters, if network parameter is empty) the given INetworkEngine interface as the current network.
Loads the Map at the given MapDatabase index into memory.
Starts the GameEngine.
Stops the GameEngine.
Loads a Game from disk.
Saves the currently played Game to disk.

Functions

plugin

IPluginEngine &plugin() const

Provides access to the PluginEngine.  A calling object should use the PLUGIN macro as a shortcut to this function.

Returns

A reference to the IPluginEngine interface.

rule

IRuleEngine &rule() const

Provides access to the RuleEngine.  A calling object should use the RULE macro as a shortcut to this function.

Returns

A reference to the IRuleEngine interface.

image

IImageEngine &image() const

Provides access to the ImageEngine.  A calling object should use the IMAGE macro as a shortcut to this function.

Returns

A reference to the IImageEngine interface.

gameobject

IGameObjectEngine &gameobject() const

Provides access to the GameObjectEngine.  A calling object should use the GAMEOBJECT macro as a shortcut to this function.

Returns

A reference to the IGameObjectEngine interface.

drawobject

IDrawObjectEngine &drawobject() const

Provides access to the DrawObjectEngine.  A calling object should use the DRAWOBJECT macro as a shortcut to this function.

Returns

A reference to the IDrawObjectEngine interface.

sound

ISoundEngine &sound() const

Provides access to the SoundEngine.  A calling object should use the SOUND macro as a shortcut to this function.

Returns

A reference to the ISoundEngine interface.

any

IAnyEngine &any() const

Provides access to the AnyEngine.

Returns

A reference to the IAnyEngine interface.

network

NetworkEnginePtr &network() const

Provides access to the INetworkEngine interface, which may not exist if the game is not being played on a network.

Returns

A boost::shared_ptr to the INetworkEngine interface.  May be NULL.

map

const Map &map() const

Provides read-only access to the current Map.  A calling object should use the MAP macro as a shortcut to this function.

Returns

A const reference to the currently loaded Map.

mapIndex

wxInt32 mapIndex() const

Returns the index in the MapDatabase of the currently loaded Map.

Returns

The index in the MapDatabase of the currently loaded Map.  May be -1 if no Map is currently loaded.

RegisterNetwork

void RegisterNetwork(const NetworkEnginePtr &network)

Registers (or unregisters, if network parameter is empty) the given INetworkEngine interface as the current network.

Parameters

networkThe INetworkEngine to use as the current network.  May be empty to set no network.

LoadMap

void LoadMap(const wxInt32 index)

Loads the Map at the given MapDatabase index into memory.

Parameters

indexThe index in the MapDatabase of the map to load.

StartEngine

void StartEngine()

Starts the GameEngine.  First calls StopEngine to shut down anything currently happening.  Creates new Game and Map objects (though no map is loaded from the MapDatabase).  Sets the Access data to the newly created Game object.  Starts the PluginEngine.

StopEngine

void StopEngine()

Stops the GameEngine.  Resets the Game data in Access to empty.  Clears the current Game and Map objects and sets the current map index to -1.  Calls Stop on the DrawObjectEngine, ImageEngine, RuleEngine, and PluginEngine, in that order, to clear out any memory loaded from plugins.

LoadGame

void LoadGame(wxInt32 index,
bool incomplete,
const LoadCallbackFunc &func)

Loads a Game from disk.  Because a certain ordering of events must take place (i.e. the RuleSets must be loaded first, then the OpenGL window created, then the Game data be loaded), the developer can send a boost::function object as a callback function.  This callback function will be called when the RuleSet names for the game have been loaded from disk but before the actual Game data is loaded.  In this way, the calling function can do whatever RuleSet loading and OpenGL initialization is required before the Game data is loaded.  Once the Game is loaded, the proper Map for the Game is loaded via the MapDatabase.  Then the eventResetCamera Event is triggered to readjust the View, and finally, the RuleRestartGame IRule is executed to get things going again.

Parameters

indexThe index in the MapDatabase of the Game to load.
incompleteWhether the index is in the completed games database or the incomplete games database.
funcA boost::function object to callback during load.  May be empty.

SaveGame

void SaveGame()

Saves the currently played Game to disk.  If the Game’s State field is set to “Completed”, the Game is saved in the complete game database, otherwise it is saved in the incomplete game database.

Private

Summary
The GameEngine constructor.
The GameEngine destructor.

Constructors

GameEngine

GameEngine()

The GameEngine constructor.  Creates the private, static RuleEngine, DrawObjectEngine, ImageEngine, SoundEngine, and PluginEngine.  Seeds the random number generator with the current timestamp.

Destructors

~GameEngine

~GameEngine()

The GameEngine destructor.  Resets the private static RuleEngine, DrawObjectEngine, ImageEngine, SoundEngine, and PluginEngine.

IPluginEngine &plugin() const
Provides access to the PluginEngine.
The default implementation of the IPluginEngine interface.
IRuleEngine &rule() const
Provides access to the RuleEngine.
The default implementation of the IRuleEngine interface.
IImageEngine &image() const
Provides access to the ImageEngine.
The standard implementation of the IImageEngine interface.
IGameObjectEngine &gameobject() const
Provides access to the GameObjectEngine.
The default implementation of the IGameObjectEngine interface.
IDrawObjectEngine &drawobject() const
Provides access to the DrawObjectEngine.
The standard implementation of the IDrawObjectEngine interface.
ISoundEngine &sound() const
Provides access to the SoundEngine.
The default implementation of the ISoundEngine interface.
IAnyEngine &any() const
Provides access to the AnyEngine.
Needs documentation.
NetworkEnginePtr &network() const
Provides access to the INetworkEngine interface, which may not exist if the game is not being played on a network.
Needs documentation.
const Map &map() const
Provides read-only access to the current Map.
Still volatile.
wxInt32 mapIndex() const
Returns the index in the MapDatabase of the currently loaded Map.
Still volatile.
void RegisterNetwork(const NetworkEnginePtr &network)
Registers (or unregisters, if network parameter is empty) the given INetworkEngine interface as the current network.
void LoadMap(const wxInt32 index)
Loads the Map at the given MapDatabase index into memory.
void StartEngine()
Starts the GameEngine.
void StopEngine()
Stops the GameEngine.
void LoadGame(wxInt32 index,
bool incomplete,
const LoadCallbackFunc &func)
Loads a Game from disk.
Still volatile.
void SaveGame()
Saves the currently played Game to disk.
GameEngine()
The GameEngine constructor.
~GameEngine()
The GameEngine destructor.
A template class that provides an implementation of the Singleton pattern.
RulesCore is the HOSS of Cities3D.
The interface of the plugin engine.
The interface for the rule engine.
The interface of the image engine.
The interface of the IGameObject engine.
The interface of the IDrawObject engine.
The interface of the sound engine.
Needs documentation.
Allows derived classes read/write access to Game data.
A repository of all things rules-related.
A generic implementation of the Observer design pattern.
Restarts the game from a saved point on disk.
The interface for a single game rule.