overview wiki api reference download
 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
PropertiesgetConfig () 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 RectanglegetViewport () 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)
AudioControllergetAudioController () const
AnimationControllergetAnimationController () const
PhysicsControllergetPhysicsController () const
AIControllergetAIController () const
ScriptControllergetScriptController () const
AudioListenergetAudioListener ()
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
GamepadgetGamepad (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 GamegetInstance ()
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

Flags used when clearing the active frame buffer targets.

The game states.


Constructor & Destructor Documentation

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:
flagsThe flags indicating which buffers to be cleared.
clearColorThe color value to clear to when the flags includes the color buffer.
clearDepthThe depth value to clear to when the flags includes the color buffer.
clearStencilThe 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:
flagsThe flags indicating which buffers to be cleared.
redThe red channel.
greenThe green channel.
blueThe blue channel.
alphaThe alpha channel.
clearDepthThe depth value to clear to when the flags includes the color buffer.
clearStencilThe stencil value to clear to when the flags includes the color buffer.

Clears all scheduled time events.

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

Shows or hides the virtual keyboard (if supported).

Parameters:
displaytrue when virtual keyboard needs to be displayed; false otherwise.

Exits the game.

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

Finalize callback that is called when the game on exits.

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:
evtThe gamepad event that occurred.
gamepadThe gamepad that generated the event.
virtual void gameplay::Game::gestureDragEvent ( int  x,
int  y 
) [virtual]

Gesture callback on Gesture::DRAG events.

Parameters:
xThe x-coordinate of the start of the drag event.
yThe 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:
xThe x-coordinate of the drop event.
yThe 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:
xThe x-coordinate of the long tap.
yThe y-coordinate of the long tap.
durationThe 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:
xThe centroid x-coordinate of the pinch.
yThe centroid y-coordinate of the pinch.
scaleThe scale of the pinch.
virtual void gameplay::Game::gestureSwipeEvent ( int  x,
int  y,
int  direction 
) [virtual]

Gesture callback on Gesture::SWIPE events.

Parameters:
xThe x-coordinate of the start of the swipe.
yThe y-coordinate of the start of the swipe.
directionThe 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:
xThe x-coordinate of the tap.
yThe 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:
pitchThe pitch angle returned (in degrees). Zero if hasAccelerometer() returns false.
rollThe roll angle returned (in degrees). Zero if hasAccelerometer() returns false.

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

Returns:
The AI controller for this game.

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:
argcThe number of command line arguments.
argvThe 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.

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

Returns:
The audio controller for this game.

Gets the audio listener for 3D audio.

Returns:
The audio listener for this game.

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:
indexThe index of the gamepad to retrieve.
preferPhysicaltrue 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.

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

Returns:
The physics controller for this game.

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:
accelXThe x-coordinate of the raw accelerometer data.
accelYThe y-coordinate of the raw accelerometer data.
accelZThe z-coordinate of the raw accelerometer data.
gyroXThe x-coordinate of the raw gyroscope data.
gyroYThe y-coordinate of the raw gyroscope data.
gyroZThe 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.

Determines whether the platform cursor is currently visible.

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

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.

Determines whether a specified gesture event is supported.

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

Parameters:
evtThe 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.

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:
evtThe key event that occurred.
keyIf 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:
urlURL 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:
evtThe mouse event that occurred.
xThe x position of the mouse in pixels. Left edge is zero.
yThe y position of the mouse in pixels. Top edge is zero.
wheelDeltaThe 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

Pauses the game after being run.

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:
evtThe 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:
elapsedTimeThe 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:
widthThe new game window width.
heightThe new game window height.

Resumes the game after being paused.

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:
timeOffsetThe number of game milliseconds in the future to schedule the event to be fired.
timeListenerThe TimeListener that will receive the event.
cookieThe 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:
timeOffsetThe number of game milliseconds in the future to schedule the event to be fired.
functionThe script function that will receive the event.
void gameplay::Game::setCursorVisible ( bool  visible) [inline]

Sets the visibility of the platform cursor.

Parameters:
visibletrue 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:
capturedtrue 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:
enabledtrue 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:
enabledtrue 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:
enabletrue 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:
evtThe touch event that occurred.
xThe x position of the touch in pixels. Left edge is zero.
yThe y position of the touch in pixels. Top edge is zero.
contactIndexThe order of occurrence for multiple touch contacts starting at zero.
See also:
Touch::TouchEvent

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:
evtThe 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:
elapsedTimeThe 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