|  | overview |  | wiki |  | api reference |  | download

- Main Page
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Functions Variables Typedefs Enumerations Enumerator
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
gameplay::Game Class Reference

`#include <Game.h>`

List of all members.

## Classes

struct | ShutdownListener
class | TimeEvent

## Public Types

enum | State { UNINITIALIZED, RUNNING, PAUSED }
enum | ClearFlags { CLEAR_COLOR = GL_COLOR_BUFFER_BIT, CLEAR_DEPTH = GL_DEPTH_BUFFER_BIT, CLEAR_STENCIL = GL_STENCIL_BUFFER_BIT, CLEAR_COLOR_DEPTH = CLEAR_COLOR | CLEAR_DEPTH, CLEAR_COLOR_STENCIL = CLEAR_COLOR | CLEAR_STENCIL, CLEAR_DEPTH_STENCIL = CLEAR_DEPTH | CLEAR_STENCIL, CLEAR_COLOR_DEPTH_STENCIL = CLEAR_COLOR | CLEAR_DEPTH | CLEAR_STENCIL }

## Public Member Functions

| Game ()
virtual | ~Game ()
State | getState () const
bool | isInitialized () const
Properties * | getConfig () const
int | run ()
void | pause ()
void | resume ()
void | exit ()
void | frame ()
unsigned int | getFrameRate () const
unsigned int | getWidth () const
unsigned int | getHeight () const
float | getAspectRatio () const
const Rectangle & | getViewport () const
void | setViewport (const Rectangle &viewport)
void | clear (ClearFlags flags, const Vector4 &clearColor, float clearDepth, int clearStencil)
void | clear (ClearFlags flags, float red, float green, float blue, float alpha, float clearDepth, int clearStencil)
AudioController * | getAudioController () const
AnimationController * | getAnimationController () const
PhysicsController * | getPhysicsController () const
AIController * | getAIController () const
ScriptController * | getScriptController () const
AudioListener * | getAudioListener ()
void | displayKeyboard (bool display)
virtual void | keyEvent (Keyboard::KeyEvent evt, int key)
virtual void | touchEvent (Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
virtual bool | mouseEvent (Mouse::MouseEvent evt, int x, int y, int wheelDelta)
virtual void | resizeEvent (unsigned int width, unsigned int height)
bool | hasMouse ()
bool | isMouseCaptured ()
void | setMouseCaptured (bool captured)
void | setCursorVisible (bool visible)
bool | isCursorVisible ()
bool | isGestureSupported (Gesture::GestureEvent evt)
void | registerGesture (Gesture::GestureEvent evt)
void | unregisterGesture (Gesture::GestureEvent evt)
bool | isGestureRegistered (Gesture::GestureEvent evt)
virtual void | gestureSwipeEvent (int x, int y, int direction)
virtual void | gesturePinchEvent (int x, int y, float scale)
virtual void | gestureLongTapEvent (int x, int y, float duration)
virtual void | gestureTapEvent (int x, int y)
virtual void | gestureDragEvent (int x, int y)
virtual void | gestureDropEvent (int x, int y)
virtual void | gamepadEvent (Gamepad::GamepadEvent evt, Gamepad *gamepad)
unsigned int | getGamepadCount () const
Gamepad * | getGamepad (unsigned int index, bool preferPhysical=true) const
void | setMultiSampling (bool enabled)
bool | isMultiSampling () const
void | setMultiTouch (bool enabled)
bool | isMultiTouch () const
bool | canExit () const
bool | hasAccelerometer () const
void | getAccelerometerValues (float *pitch, float *roll)
void | getSensorValues (float *accelX, float *accelY, float *accelZ, float *gyroX, float *gyroY, float *gyroZ)
void | getArguments (int *argc, char ***argv) const
void | schedule (float timeOffset, TimeListener *timeListener, void *cookie=0)
void | schedule (float timeOffset, const char *function)
void | clearSchedule ()
bool | launchURL (const char *url) const

## Static Public Member Functions

static Game * | getInstance ()
static bool | isVsync ()
static void | setVsync (bool enable)
static double | getAbsoluteTime ()
static double | getGameTime ()

## Protected Member Functions

virtual void | initialize ()
virtual void | finalize ()
virtual void | update (float elapsedTime)
virtual void | render (float elapsedTime)
template<class T >
void | renderOnce (T *instance, void(T::*method)(void *), void *cookie)
void | renderOnce (const char *function)
void | updateOnce ()

## Detailed Description

Defines the base class your game will extend for game initialization, logic and platform delegates.

This represents a running cross-platform game application and provides an abstraction to most typical platform functionality and events.

See also:
  http://gameplay3d.github.io/GamePlay/docs/file-formats.html#wiki-Game_Config

## Member Enumeration Documentation

enum gameplay::Game::ClearFlags

Flags used when clearing the active frame buffer targets.

enum gameplay::Game::State

The game states.

## Constructor & Destructor Documentation

gameplay::Game::Game | ( |  | ) |

Constructor.

virtual gameplay::Game::~Game | ( |  | ) | `[virtual]`

Destructor.

## Member Function Documentation

bool gameplay::Game::canExit | ( |  | ) | const`[inline]`

Whether this game is allowed to exit programmatically.

Returns:
  true if a programmatic exit is allowed.

void gameplay::Game::clear | ( | ClearFlags | flags,
|  | const Vector4 & | clearColor,
|  | float | clearDepth,
|  | int | clearStencil
| ) |  |

Clears the specified resource buffers to the specified clear values.

Parameters:

  flags | The flags indicating which buffers to be cleared.
  clearColor | The color value to clear to when the flags includes the color buffer.
  clearDepth | The depth value to clear to when the flags includes the color buffer.
  clearStencil | The stencil value to clear to when the flags includes the color buffer.

void gameplay::Game::clear | ( | ClearFlags | flags,
|  | float | red,
|  | float | green,
|  | float | blue,
|  | float | alpha,
|  | float | clearDepth,
|  | int | clearStencil
| ) |  |

Clears the specified resource buffers to the specified clear values.

Parameters:

  flags | The flags indicating which buffers to be cleared.
  red | The red channel.
  green | The green channel.
  blue | The blue channel.
  alpha | The alpha channel.
  clearDepth | The depth value to clear to when the flags includes the color buffer.
  clearStencil | The stencil value to clear to when the flags includes the color buffer.

void gameplay::Game::clearSchedule | ( |  | ) |

Clears all scheduled time events.

void gameplay::Game::displayKeyboard | ( | bool | display | ) | `[inline]`

Shows or hides the virtual keyboard (if supported).

Parameters:

  display | true when virtual keyboard needs to be displayed; false otherwise.

void gameplay::Game::exit | ( |  | ) |

Exits the game.

virtual void gameplay::Game::finalize | ( |  | ) | `[protected, virtual]`

Finalize callback that is called when the game on exits.

void gameplay::Game::frame | ( |  | ) |

Platform frame delegate.

This is called every frame from the platform. This in turn calls back on the user implemented game methods: update() then render()

virtual void gameplay::Game::gamepadEvent | ( | Gamepad::GamepadEvent | evt,
|  | Gamepad * | gamepad
| ) |  | `[virtual]`

Gamepad callback on gamepad events. Override to receive Gamepad::CONNECTED_EVENT and Gamepad::DISCONNECTED_EVENT, and store the Gamepad* in order to poll it from update().

Parameters:

  evt | The gamepad event that occurred.
  gamepad | The gamepad that generated the event.

virtual void gameplay::Game::gestureDragEvent | ( | int | x,
|  | int | y
| ) |  | `[virtual]`

Gesture callback on Gesture::DRAG events.

Parameters:

  x | The x-coordinate of the start of the drag event.
  y | The y-coordinate of the start of the drag event.

virtual void gameplay::Game::gestureDropEvent | ( | int | x,
|  | int | y
| ) |  | `[virtual]`

Gesture callback on Gesture::DROP events.

Parameters:

  x | The x-coordinate of the drop event.
  y | The y-coordinate of the drop event.

virtual void gameplay::Game::gestureLongTapEvent | ( | int | x,
|  | int | y,
|  | float | duration
| ) |  | `[virtual]`

Gesture callback on Gesture::LONG_TAP events.

Parameters:

  x | The x-coordinate of the long tap.
  y | The y-coordinate of the long tap.
  duration | The duration of the long tap in ms.

virtual void gameplay::Game::gesturePinchEvent | ( | int | x,
|  | int | y,
|  | float | scale
| ) |  | `[virtual]`

Gesture callback on Gesture::PINCH events.

Parameters:

  x | The centroid x-coordinate of the pinch.
  y | The centroid y-coordinate of the pinch.
  scale | The scale of the pinch.

virtual void gameplay::Game::gestureSwipeEvent | ( | int | x,
|  | int | y,
|  | int | direction
| ) |  | `[virtual]`

Gesture callback on Gesture::SWIPE events.

Parameters:

  x | The x-coordinate of the start of the swipe.
  y | The y-coordinate of the start of the swipe.
  direction | The direction of the swipe

See also:
  Gesture::SWIPE_DIRECTION_UP
  Gesture::SWIPE_DIRECTION_DOWN
  Gesture::SWIPE_DIRECTION_LEFT
  Gesture::SWIPE_DIRECTION_RIGHT

virtual void gameplay::Game::gestureTapEvent | ( | int | x,
|  | int | y
| ) |  | `[virtual]`

Gesture callback on Gesture::TAP events.

Parameters:

  x | The x-coordinate of the tap.
  y | The y-coordinate of the tap.

static double gameplay::Game::getAbsoluteTime | ( |  | ) | `[static]`

Gets the total absolute running time (in milliseconds) since Game::run().

Returns:
  The total absolute running time (in milliseconds).

void gameplay::Game::getAccelerometerValues | ( | float * | pitch,
|  | float * | roll
| ) |  | `[inline]`

Gets the current accelerometer values for use as an indication of device orientation. Despite its name, implementations are at liberty to combine accelerometer data with data from other sensors as well, such as the gyros. This method is best used to obtain an indication of device orientation; it does not necessarily distinguish between acceleration and rotation rate.

Parameters:

  pitch | The pitch angle returned (in degrees). Zero if hasAccelerometer() returns false.
  roll | The roll angle returned (in degrees). Zero if hasAccelerometer() returns false.

AIController* gameplay::Game::getAIController | ( |  | ) | const`[inline]`

Gets the AI controller for managing control of artificial intelligence associated with the game.

Returns:
  The AI controller for this game.

AnimationController* gameplay::Game::getAnimationController | ( |  | ) | const`[inline]`

Gets the animation controller for managing control of animations associated with the game.

Returns:
  The animation controller for this game.

void gameplay::Game::getArguments | ( | int * | argc,
|  | char *** | argv
| ) |  | const

Gets the command line arguments.

Parameters:

  argc | The number of command line arguments.
  argv | The array of command line arguments.

float gameplay::Game::getAspectRatio | ( |  | ) | const`[inline]`

Gets the aspect ratio of the window. (width / height)

Returns:
  The aspect ratio of the window.

AudioController* gameplay::Game::getAudioController | ( |  | ) | const`[inline]`

Gets the audio controller for managing control of audio associated with the game.

Returns:
  The audio controller for this game.

AudioListener* gameplay::Game::getAudioListener | ( |  | ) |

Gets the audio listener for 3D audio.

Returns:
  The audio listener for this game.

Properties* gameplay::Game::getConfig | ( |  | ) | const

Returns the game configuration object.

This method returns a Properties object containing the contents of the game.config file.

Returns:
  The game configuration Properties object.

unsigned int gameplay::Game::getFrameRate | ( |  | ) | const`[inline]`

Gets the current frame rate.

Returns:
  The current frame rate.

Gamepad* gameplay::Game::getGamepad | ( | unsigned int | index,
|  | bool | preferPhysical = `true`
| ) |  | const`[inline]`

Gets the gamepad at the specified index.

The gamepad index can change when connected and disconnected so you cannot rely on this other than iterating through them all to display them or poll them.

The preferPhysical will bump over virtual gamepads if physical gamepads are connected and return the request index of the first or second physcial and then return back to the first virtual after.

Parameters:

  index | The index of the gamepad to retrieve.
  preferPhysical | true if you prefer return a physical if exist; false if only virtual.

Returns:
  The gamepad at the specified index.

unsigned int gameplay::Game::getGamepadCount | ( |  | ) | const`[inline]`

Gets the current number of gamepads currently connected to the system.

Returns:
  The number of gamepads currently connected to the system.

static double gameplay::Game::getGameTime | ( |  | ) | `[static]`

Gets the total game time (in milliseconds). This is the total accumulated game time (unpaused).

You would typically use things in your game that you want to stop when the game is paused. This includes things such as game physics and animation.

Returns:
  The total game time (in milliseconds).

unsigned int gameplay::Game::getHeight | ( |  | ) | const`[inline]`

Gets the game window height.

Returns:
  The game window height.

static Game* gameplay::Game::getInstance | ( |  | ) | `[static]`

Gets the single instance of the game.

Returns:
  The single instance of the game.

PhysicsController* gameplay::Game::getPhysicsController | ( |  | ) | const`[inline]`

Gets the physics controller for managing control of physics associated with the game.

Returns:
  The physics controller for this game.

ScriptController* gameplay::Game::getScriptController | ( |  | ) | const`[inline]`

Gets the script controller for managing control of Lua scripts associated with the game.

Returns:
  The script controller for this game.

void gameplay::Game::getSensorValues | ( | float * | accelX,
|  | float * | accelY,
|  | float * | accelZ,
|  | float * | gyroX,
|  | float * | gyroY,
|  | float * | gyroZ
| ) |  | `[inline]`

Gets sensor values (raw), if equipped, allowing a distinction between device acceleration and rotation rate. Returns zeros on platforms with no corresponding support. See also hasAccelerometer() and getAccelerometerValues().

Parameters:

  accelX | The x-coordinate of the raw accelerometer data.
  accelY | The y-coordinate of the raw accelerometer data.
  accelZ | The z-coordinate of the raw accelerometer data.
  gyroX | The x-coordinate of the raw gyroscope data.
  gyroY | The y-coordinate of the raw gyroscope data.
  gyroZ | The z-coordinate of the raw gyroscope data.

State gameplay::Game::getState | ( |  | ) | const`[inline]`

Gets the game state.

Returns:
  The current game state.

const Rectangle& gameplay::Game::getViewport | ( |  | ) | const`[inline]`

Gets the game current viewport.

The default viewport is Rectangle(0, 0, Game::getWidth(), Game::getHeight()).

unsigned int gameplay::Game::getWidth | ( |  | ) | const`[inline]`

Gets the game window width.

Returns:
  The game window width.

bool gameplay::Game::hasAccelerometer | ( |  | ) | const`[inline]`

Whether this game has accelerometer support.

bool gameplay::Game::hasMouse | ( |  | ) | `[inline]`

Gets whether the current platform supports mouse input.

Returns:
  true if a mouse is supported, false otherwise.

virtual void gameplay::Game::initialize | ( |  | ) | `[protected, virtual]`

Initialize callback that is called just before the first frame when the game starts.

bool gameplay::Game::isCursorVisible | ( |  | ) | `[inline]`

Determines whether the platform cursor is currently visible.

Returns:
  true if the platform cursor is visible, false otherwise.

bool gameplay::Game::isGestureRegistered | ( | Gesture::GestureEvent | evt | ) |

Determines whether a specified gesture event is registered to receive event callbacks.

Returns:
  true if the specified gesture event is registered; false of not registered.

bool gameplay::Game::isGestureSupported | ( | Gesture::GestureEvent | evt | ) |

Determines whether a specified gesture event is supported.

Use Gesture::GESTURE_ANY_SUPPORTED to test if one or more gesture events are supported.

Parameters:

  evt | The gesture event to test and see if it is supported.

Returns:
  true if the gesture tested is supported; false if not supported.

bool gameplay::Game::isInitialized | ( |  | ) | const`[inline]`

Determines if the game has been initialized.

Returns:
  true if the game initialization has completed, false otherwise.

bool gameplay::Game::isMouseCaptured | ( |  | ) | `[inline]`

Gets whether mouse input is currently captured.

Returns:
  is the mouse captured.

bool gameplay::Game::isMultiSampling | ( |  | ) | const`[inline]`

Is multi-sampling enabled.

Returns:
  true if multi-sampling is enabled.

bool gameplay::Game::isMultiTouch | ( |  | ) | const`[inline]`

Is multi-touch mode enabled.

Returns:
  true if multi-touch is enabled.

static bool gameplay::Game::isVsync | ( |  | ) | `[static]`

Gets whether vertical sync is enabled for the game display.

Returns:
  true if vsync is enabled; false if not.

virtual void gameplay::Game::keyEvent | ( | Keyboard::KeyEvent | evt,
|  | int | key
| ) |  | `[virtual]`

Keyboard callback on keyPress events.

Parameters:

  evt | The key event that occurred.
  key | If evt is KEY_PRESS or KEY_RELEASE then key is the key code from Keyboard::Key. If evt is KEY_CHAR then key is the unicode value of the character.

See also:
  Keyboard::KeyEvent
  Keyboard::Key

bool gameplay::Game::launchURL | ( | const char * | url | ) | const

Opens an URL in an external browser, if available.

Parameters:

  url | URL to be opened.

Returns:
  True if URL was opened successfully, false otherwise.

virtual bool gameplay::Game::mouseEvent | ( | Mouse::MouseEvent | evt,
|  | int | x,
|  | int | y,
|  | int | wheelDelta
| ) |  | `[virtual]`

Mouse callback on mouse events. If the game does not consume the mouse move event or left mouse click event then it is interpreted as a touch event instead.

Parameters:

  evt | The mouse event that occurred.
  x | The x position of the mouse in pixels. Left edge is zero.
  y | The y position of the mouse in pixels. Top edge is zero.
  wheelDelta | The number of mouse wheel ticks. Positive is up (forward), negative is down (backward).

Returns:
  True if the mouse event is consumed or false if it is not consumed.

See also:
  Mouse::MouseEvent

void gameplay::Game::pause | ( |  | ) |

Pauses the game after being run.

void gameplay::Game::registerGesture | ( | Gesture::GestureEvent | evt | ) |

Requests the game to register and start recognizing the specified gesture event.

Call with Gesture::GESTURE_ANY_SUPPORTED to recognize all supported gestures. Once a gesture is recognized the specific gesture event methods will begin to be called.

Registering for:

Gesture::GESTURE_SWIPE calls gestureSwipeEvent(..) Gesture::GESTURE_PINCH calls gesturePinchEvent(..) Gesture::GESTURE_TAP calls gestureTapEvent(..)

Parameters:

  evt | The gesture event to start recognizing for

virtual void gameplay::Game::render | ( | float | elapsedTime | ) | `[protected, virtual]`

Render callback for handling rendering routines.

Called just after update, once per frame when game is running. Ideal for all rendering code.

Parameters:

  elapsedTime | The elapsed game time.

template<class T >

void gameplay::Game::renderOnce | ( | T * | instance,
|  | void(T::*)(void *) | method,
|  | void * | cookie
| ) |  | `[protected]`

Renders a single frame once and then swaps it to the display.

This is useful for rendering splash screens.

void gameplay::Game::renderOnce | ( | const char * | function | ) | `[protected]`

Renders a single frame once and then swaps it to the display. This calls the given script function, which should take no parameters and return nothing (void).

This is useful for rendering splash screens.

virtual void gameplay::Game::resizeEvent | ( | unsigned int | width,
|  | unsigned int | height
| ) |  | `[virtual]`

Called when the game window has been resized.

This method is called once the game window is created with its initial size and then again any time the game window changes size.

Parameters:

  width | The new game window width.
  height | The new game window height.

void gameplay::Game::resume | ( |  | ) |

Resumes the game after being paused.

int gameplay::Game::run | ( |  | ) |

Called to initialize the game, and begin running the game.

Returns:
  Zero for normal termination, or non-zero if an error occurred.

void gameplay::Game::schedule | ( | float | timeOffset,
|  | TimeListener * | timeListener,
|  | void * | cookie = `0`
| ) |  |

Schedules a time event to be sent to the given TimeListener a given number of game milliseconds from now. Game time stops while the game is paused. A time offset of zero will fire the time event in the next frame.

Parameters:

  timeOffset | The number of game milliseconds in the future to schedule the event to be fired.
  timeListener | The TimeListener that will receive the event.
  cookie | The cookie data that the time event will contain.

void gameplay::Game::schedule | ( | float | timeOffset,
|  | const char * | function
| ) |  |

Schedules a time event to be sent to the given TimeListener a given number of game milliseconds from now. Game time stops while the game is paused. A time offset of zero will fire the time event in the next frame.

The given script function must take a single floating point number, which is the difference between the current game time and the target time (see TimeListener::timeEvent). The function will be executed in the context of the script envionrment that the schedule function was called from.

Parameters:

  timeOffset | The number of game milliseconds in the future to schedule the event to be fired.
  function | The script function that will receive the event.

void gameplay::Game::setCursorVisible | ( | bool | visible | ) | `[inline]`

Sets the visibility of the platform cursor.

Parameters:

  visible | true to show the platform cursor, false to hide it.

void gameplay::Game::setMouseCaptured | ( | bool | captured | ) | `[inline]`

Enables or disables mouse capture.

On platforms that support a mouse, when mouse capture is enabled, the platform cursor will be hidden and the mouse will be warped to the center of the screen. While mouse capture is enabled, all mouse move events will then be delivered as deltas instead of absolute positions.

Parameters:

  captured | true to enable mouse capture mode, false to disable it.

void gameplay::Game::setMultiSampling | ( | bool | enabled | ) | `[inline]`

Sets whether multi-sampling is to be enabled/disabled. Default is disabled.

Parameters:

  enabled | true sets multi-sampling to be enabled, false to be disabled.

void gameplay::Game::setMultiTouch | ( | bool | enabled | ) | `[inline]`

Sets multi-touch is to be enabled/disabled. Default is disabled.

Parameters:

  enabled | true sets multi-touch is enabled, false to be disabled.

void gameplay::Game::setViewport | ( | const Rectangle & | viewport | ) |

Sets the game current viewport.

The x, y, width and height of the viewport must all be positive.

viewport The custom viewport to be set on the game.

static void gameplay::Game::setVsync | ( | bool | enable | ) | `[static]`

Sets whether vertical sync is enabled for the game display.

Parameters:

  enable | true if vsync is enabled; false if not.

virtual void gameplay::Game::touchEvent | ( | Touch::TouchEvent | evt,
|  | int | x,
|  | int | y,
|  | unsigned int | contactIndex
| ) |  | `[virtual]`

Touch callback on touch events.

Parameters:

  evt | The touch event that occurred.
  x | The x position of the touch in pixels. Left edge is zero.
  y | The y position of the touch in pixels. Top edge is zero.
  contactIndex | The order of occurrence for multiple touch contacts starting at zero.

See also:
  Touch::TouchEvent

void gameplay::Game::unregisterGesture | ( | Gesture::GestureEvent | evt | ) |

Requests the game to unregister for and stop recognizing the specified gesture event.

Call with Gesture::GESTURE_ANY_SUPPORTED to unregister events from all supported gestures.

Parameters:

  evt | The gesture event to start recognizing for

virtual void gameplay::Game::update | ( | float | elapsedTime | ) | `[protected, virtual]`

Update callback for handling update routines.

Called just before render, once per frame when game is running. Ideal for non-render code and game logic such as input and animation.

Parameters:

  elapsedTime | The elapsed game time.

void gameplay::Game::updateOnce | ( |  | ) | `[protected]`

Updates the game's internal systems (audio, animation, physics) once.

Note: This does not call the user-defined Game::update() function.

This is useful for rendering animated splash screens.

All Classes Functions Variables Typedefs Enumerations Enumerator