#include <Game.h>
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 () |
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.
Flags used when clearing the active frame buffer targets.
The game states.
Constructor.
virtual gameplay::Game::~Game | ( | ) | [virtual] |
Destructor.
bool gameplay::Game::canExit | ( | ) | const [inline] |
Whether this game is allowed to exit programmatically.
void gameplay::Game::clear | ( | ClearFlags | flags, |
const Vector4 & | clearColor, | ||
float | clearDepth, | ||
int | clearStencil | ||
) |
Clears the specified resource buffers to the specified clear values.
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.
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).
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 | ( | ) |
virtual void gameplay::Game::gamepadEvent | ( | Gamepad::GamepadEvent | evt, |
Gamepad * | gamepad | ||
) | [virtual] |
virtual void gameplay::Game::gestureDragEvent | ( | int | x, |
int | y | ||
) | [virtual] |
Gesture callback on Gesture::DRAG events.
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.
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.
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.
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.
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 |
virtual void gameplay::Game::gestureTapEvent | ( | int | x, |
int | y | ||
) | [virtual] |
Gesture callback on Gesture::TAP events.
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().
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.
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.
AnimationController* gameplay::Game::getAnimationController | ( | ) | const [inline] |
Gets the animation controller for managing control of animations associated with the game.
void gameplay::Game::getArguments | ( | int * | argc, |
char *** | argv | ||
) | const |
Gets the command line arguments.
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)
AudioController* gameplay::Game::getAudioController | ( | ) | const [inline] |
Gets the audio controller for managing control of audio associated with the game.
Gets the audio listener for 3D audio.
Properties* gameplay::Game::getConfig | ( | ) | const |
Returns the game configuration object.
This method returns a Properties object containing the contents of the game.config file.
unsigned int gameplay::Game::getFrameRate | ( | ) | const [inline] |
Gets 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.
index | The index of the gamepad to retrieve. |
preferPhysical | true if you prefer return a physical if exist; false if only virtual. |
unsigned int gameplay::Game::getGamepadCount | ( | ) | const [inline] |
Gets the current 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.
unsigned int gameplay::Game::getHeight | ( | ) | const [inline] |
Gets the game window height.
static Game* gameplay::Game::getInstance | ( | ) | [static] |
Gets 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.
ScriptController* gameplay::Game::getScriptController | ( | ) | const [inline] |
Gets the script controller for managing control of Lua scripts associated with the 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().
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.
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.
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.
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.
Determines whether a specified gesture event is registered to receive event callbacks.
Determines whether a specified gesture event is supported.
Use Gesture::GESTURE_ANY_SUPPORTED to test if one or more gesture events are supported.
evt | The gesture event to test and see if it is supported. |
bool gameplay::Game::isInitialized | ( | ) | const [inline] |
Determines if the game has been initialized.
bool gameplay::Game::isMouseCaptured | ( | ) | [inline] |
Gets whether mouse input is currently captured.
bool gameplay::Game::isMultiSampling | ( | ) | const [inline] |
Is multi-sampling enabled.
bool gameplay::Game::isMultiTouch | ( | ) | const [inline] |
Is multi-touch mode enabled.
static bool gameplay::Game::isVsync | ( | ) | [static] |
Gets whether vertical sync is enabled for the game display.
virtual void gameplay::Game::keyEvent | ( | Keyboard::KeyEvent | evt, |
int | key | ||
) | [virtual] |
Keyboard callback on keyPress events.
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. |
bool gameplay::Game::launchURL | ( | const char * | url | ) | const |
Opens an URL in an external browser, if available.
url | URL to be opened. |
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.
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). |
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(..)
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.
elapsedTime | The elapsed game time. |
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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. |
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.
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.
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.