Engine Class Reference

The interface between the platform and the game itself. More...

#include <Engine.h>

Collaboration diagram for Engine:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Engine (AbstractPlatform *pPlatform, AbstractRenderer *pRenderer, AbstractAudioSystem *pAudio)
 The engine is created by the platform.
 ~Engine ()
 The Engine destructor releases the resource cache, game and any registered screens.
AbstractPlatformGetPlatform () const
AbstractRendererGetRenderer () const
AbstractAudioSystemGetAudio () const
ResourceCacheGetResourceCache () const
GameGetGame () const
int GetUpdateRate () const
bool Initialize ()
 Prepared the engine for stepping.
void Step ()
 Updates & Renders the currently active screen and dialog.
void SetModalDialog (ModalDialogPtr pDialog)
 Sets a modal dialog that consumes all input and update events.
void PrintFPS ()
void PrintMouseCoordinates ()
void ActivateScreen (const std::string &screenName)
 Sets a screen with the given id as the active one.
void RegisterScreen (const std::string &screenName, BaseScreen *pScreen)
 Registers a screen under a given id.
void RegisterMouseListener (AbstractMouseListener *pListener)
 Registers a mouse listener with the engine, this listener will receive all input events unless a modal dialog is active.
void UnregisterMouseListener (AbstractMouseListener *pListener)
 Unregisters a listener.
void RegisterKeyListener (AbstractKeyListener *pListener)
 Registers a key listener with the engine, this listener will receive all input events unless a modal dialog is active.
void UnregisterKeyListener (AbstractKeyListener *pListener)
 Unregisters a listener.
void OnMouseMove (const MouseEvent &e)
 This function should be called by the platform when a mouse move message is detected and passed a MouseEvent structure which contains the new location of the mouse cursor.
void OnMouseButtonPressed (const MouseEvent &e)
 This function should be called by the platform when a mouse button pressed message is detected and passed a MouseEvent structure which contains the button that was pressed.
void OnMouseButtonReleased (const MouseEvent &e)
 This function should be called by the platform when a mouse button released message is detected and passed a MouseEvent structure which contains the button that was released.
void OnKeyPressed (const KeyEvent &e)
 This function should be called by the platform when a key pressed message is detected and passed a KeyEvent structure which contains the key that was pressed.
void OnKeyReleased (const KeyEvent &e)
 This function should be called by the platform when a key released message is detected and passed a KeyEvent structure which contains the key that was released.

Detailed Description

The interface between the platform and the game itself.

The purpose of the engine class is to provide a standard interface between the platform and the game. No platform specific code should be present in the engine class meaning it can be ported vertbaitim. The platform is responsible for creating, initializing, updating and destroying the engine class. The engine is responsible for keeping track of the various components, such as UI, Sound, Renderer and the game itself. In the case of the Renderer and Sound the Engine requires that the platform creates and provides them. This is so platform-dependent implementations can be used.

The engine is the primary input hub for all of the other components. The platform receives key and mouse events which it passes on to the engine, the engine then distributes these input signals to registered input listeners (usually UI components or the game). The engine also keeps track of the game screens and renders/updates the currently active one.


Constructor & Destructor Documentation

Engine::Engine ( AbstractPlatform pPlatform,
AbstractRenderer pRenderer,
AbstractAudioSystem pAudio 
) [inline]

The engine is created by the platform.

When the engine is created the platform must provide pointers to itself, the renderer and the audio system to use, allowing platform-dependent implementations of those components. The constructor then keeps pointers to them and initializes all of the other variables in the class.

Parameters:
pPlatform A pointer to the creating platform.
pRenderer A pointer to a generic renderer, created and maintained by the platform but usable by the engine (and sub components).
pAudio A pointer to a generic audio system, created and maintained by the platform but usable by the engine (and sub components).
See also:
AbstractPlatform
AbstractRenderer
AbstractAudioSystem

Member Function Documentation

void Engine::ActivateScreen ( const std::string &  screenName  ) 

Sets a screen with the given id as the active one.

When a new screen is activated the Deactivate function is first called on the old screen before the Activate function is called on the new one. This allows any clean-up and initialization such as registering/unregistring key or mouse listeners. If a screen with the screenName provided doesn't exist this function does nothing.

Parameters:
The name/id of the screen to activate.
See also:
BaseScreen
bool Engine::Initialize (  ) 

Prepared the engine for stepping.

This function needs to be called by the platform before the engine is stepped. The function begins by initializing the resource cache and opening any resource files (identified in the resource_files.txt file). It can fail if too much resource memory is specified in the settings file provided by the platform. The next step is to initializing the Game and available screens, again any of these operations may fail. Finally the splash screen is set as the active screen.

See also:
ResourceCache
Returns:
A boolean signifying success or failure. Failure may occur for any previously mentioned reason. Should one occur the application will exit.
void Engine::OnKeyPressed ( const KeyEvent e  ) 

This function should be called by the platform when a key pressed message is detected and passed a KeyEvent structure which contains the key that was pressed.

This function will then pass the event onto all registered key listeners, or the modal dialog should one be active.

Parameters:
A structure describing the input event.
void Engine::OnKeyReleased ( const KeyEvent e  ) 

This function should be called by the platform when a key released message is detected and passed a KeyEvent structure which contains the key that was released.

This function will then pass the event onto all registered key listeners, or the modal dialog should one be active.

Parameters:
A structure describing the input event.
void Engine::OnMouseButtonPressed ( const MouseEvent e  ) 

This function should be called by the platform when a mouse button pressed message is detected and passed a MouseEvent structure which contains the button that was pressed.

This function will then pass the event onto all registered mouse listeners, or the modal dialog should one be active.

Parameters:
A structure describing the input event.
void Engine::OnMouseButtonReleased ( const MouseEvent e  ) 

This function should be called by the platform when a mouse button released message is detected and passed a MouseEvent structure which contains the button that was released.

This function will then pass the event onto all registered mouse listeners, or the modal dialog should one be active.

Parameters:
A structure describing the input event.
void Engine::OnMouseMove ( const MouseEvent e  ) 

This function should be called by the platform when a mouse move message is detected and passed a MouseEvent structure which contains the new location of the mouse cursor.

This function will then pass the event onto all registered mouse listeners, or the modal dialog should one be active.

Parameters:
A structure describing the input event.
void Engine::RegisterKeyListener ( AbstractKeyListener pListener  ) 

Registers a key listener with the engine, this listener will receive all input events unless a modal dialog is active.

The registering object takes responsibility for the listener, i.e. it is responsible for it's deletion. The listener should be unregistered before it is deleted however.

Parameters:
A pointer to the listener to receive input events.
void Engine::RegisterMouseListener ( AbstractMouseListener pListener  ) 

Registers a mouse listener with the engine, this listener will receive all input events unless a modal dialog is active.

The registering object takes responsibility for the listener, i.e. it is responsible for it's deletion. The listener should be unregistered before it is deleted however.

Parameters:
A pointer to the listener to receive input events.
void Engine::RegisterScreen ( const std::string &  screenName,
BaseScreen pScreen 
)

Registers a screen under a given id.

This function can be called in order to assign a name to a base screen. This function needs to be called before ActivateScreen in order for ActivateScreen to have any effect. If a screen is already registered with the given screenName this function has no effect.

Parameters:
screenName The name/id of the screen to register.
pScreen A pointer to the BaseScreen that's assigned as the active screen upon activation, the engine takes responsibility for this object.
void Engine::SetModalDialog ( ModalDialogPtr  pDialog  )  [inline]

Sets a modal dialog that consumes all input and update events.

Once a modal dialog is set all mouse and key events are sent to it and none of the other active input listeners. The active screen is still rendered, although it is now no longer updated, instead the modal dialog is updated and also rendered. In order to disable the modal dialog the value of 0 can be passed to this function.

Parameters:
pDialog A pointer to the dialog to show or 0 to disable the dialog.
void Engine::Step (  ) 

Updates & Renders the currently active screen and dialog.

This function is called from the platform to update the active screen. The active screen only renders every update rate milliseconds, but it is rendered every call in order to provide better effects such as interpolation while keeping the game experience as even as possible across differently powered system. This function makes no call to update the game, this is instead left up to the GameScreen, this makes sure that the games is only updated when the game screen is and no dialog is present.

See also:
BaseScreen
GameScreen
void Engine::UnregisterKeyListener ( AbstractKeyListener pListener  ) 

Unregisters a listener.

After this function is called the listener will be removed at the end of the current step and no longer receive input signals.

Parameters:
pListener A pointer to the listener to unregister.
void Engine::UnregisterMouseListener ( AbstractMouseListener pListener  ) 

Unregisters a listener.

After this function is called the listener will be removed at the end of the current step and no longer receive input signals.

Parameters:
pListener A pointer to the listener to unregister.

The documentation for this class was generated from the following files:
 All Classes Functions Variables

Generated on Fri Nov 20 15:29:20 2009 for PhysTank by  doxygen 1.6.1