TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Game::GameApplication Class Reference

#include <tb_game_application.hpp>

Inheritance diagram for TurtleBrains::Game::GameApplication:
TurtleBrains::Application::RealtimeApplication TurtleBrains::Core::Noncopyable

Public Member Functions

 GameApplication (const tbApplication::WindowMode &windowMode=tbApplication::WindowMode::Windowed, const tbGraphics::PixelSpace &windowWidth=0, const tbGraphics::PixelSpace &windowHeight=0, const bool verticalSync=true, const bool allowWindowResize=false, Application::ApplicationHandlerInterface *applicationHandler=nullptr)
 
 GameApplication (const tbApplication::WindowProperties &windowProperties, const bool allowWindowResize=false, Application::ApplicationHandlerInterface *applicationHandler=nullptr)
 
 ~GameApplication (void)
 
void RunGame (GameScene &gameScene)
 
- Public Member Functions inherited from TurtleBrains::Application::RealtimeApplication
 RealtimeApplication (ApplicationHandlerInterface &applicationHandler)
 
virtual ~RealtimeApplication (void)
 
void Open (void)
 
void Run (void)
 
void Close (void)
 
void SetWindowMenu (const ApplicationMenu &menu)
 
void SetContextMenu (const ApplicationMenu &menu)
 
void SetWindowStatus (const ApplicationStatus &status)
 
void SetWindowTitle (const tbCore::tbString &windowTitle)
 
WindowProperties GetWindowProperties (void)
 
void SetWindowProperties (const WindowProperties &windowProperties)
 
void ShowMouseCursor (bool showMouse)
 
void OpenDialog (const ApplicationDialog &dialog)
 
void CloseDialog (const ApplicationDialog &dialog)
 
bool OkayMessageBox (const tbCore::tbString &title, const tbCore::tbString &message)
 
bool OkayCancelMessageBox (const tbCore::tbString &title, const tbCore::tbString &message)
 
bool OpenFileDialog (tbCore::tbString &fileToOpen, const tbCore::tbString &fileExtension)
 
bool SaveFileDialog (tbCore::tbString &fileToSave, const tbCore::tbString &fileExtension)
 

Static Public Member Functions

static void MarkForClose (void)
 
static bool IsGameActive (void)
 
static int GetFrameRate (void)
 

Detailed Description

the GameApplication will create a basic ApplicationHandler and RealtimeApplication, and get the game state machine running. Simply create an instance of each of your game states and call RunGame and let the GameApplication handle the rest.

Constructor & Destructor Documentation

TurtleBrains::Game::GameApplication::GameApplication ( const tbApplication::WindowMode &  windowMode = tbApplication::WindowMode::Windowed,
const tbGraphics::PixelSpace windowWidth = 0,
const tbGraphics::PixelSpace windowHeight = 0,
const bool  verticalSync = true,
const bool  allowWindowResize = false,
Application::ApplicationHandlerInterface applicationHandler = nullptr 
)
explicit

Constructs the GameApplication object, opens the RealTime window with the size of 1280x720 by default or uses the parameters passed in. An error condition will be triggered if there is already a GameApplication instance in existence or if there were any trouble opening the real time application window. Also adds itself as an error handler that will popup a message box with the error contents.

Parameters
applicationHandlerA custom application handler to be called during certain handled events. This will be called when the internal handler gets called for MOST functions but not all. The internal handler will still take priority and deal with most things directly, but when it is possible it will attempt to pass responsibility to the custom handler specified here.
Note
Not all handler functions will be called on the provided application handler; This is primarily to avoid conflicts and to avoid a requirement to implement the same logic. Currently functions not called are: CanWindowResize(), CollectWindowProperties().
TurtleBrains::Game::GameApplication::GameApplication ( const tbApplication::WindowProperties windowProperties,
const bool  allowWindowResize = false,
Application::ApplicationHandlerInterface applicationHandler = nullptr 
)
explicit
TurtleBrains::Game::GameApplication::~GameApplication ( void  )

Destroys the GameApplication object and removes itself from the list of error handlers.

Member Function Documentation

static int TurtleBrains::Game::GameApplication::GetFrameRate ( void  )
static

Returns what the framerate has been running at for the last second.

Note
If you try to compute this within a GameScene it will not work because the deltaTime is capped to 10fps when the frames are taking longer. This will not suffer from the same issues and will be able to measure framerates slower than 10fps.
Only works when you are using a GameApplication to run the game (common).
static bool TurtleBrains::Game::GameApplication::IsGameActive ( void  )
static

Checks to see if the GameApplication is the currently active application that the operating system is running, meaning input and other things should be processed.

static void TurtleBrains::Game::GameApplication::MarkForClose ( void  )
static

Provides a way to shutdown the game, which will occur after the frame is completed.

void TurtleBrains::Game::GameApplication::RunGame ( GameScene gameScene)

Begins running the real-time message pump for the window, starts first with the TurtleBrains introduction scene (in release builds) and then sets the provided gameScene as the active scene.

Parameters
gameSceneThe first scene of the game to be active, usually a splash or title screen before the gameplay begins.