Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
Public Member Functions | List of all members
HFCore::Game Class Referenceabstract

Interface used by the framework to drive the main loop. More...

#include <Game.h>

Public Member Functions

 Game ()
 Constructor.
 
virtual ~Game ()
 Destructor.
 
virtual void preInitLoad ()
 Called by the framework before the game's init() method is called. More...
 
virtual void preInitDraw (Graphics *g)
 Called by the framework before the game's init() method is called. More...
 
virtual void init ()
 Called by the framework after subsystems are initialized but before the initial game loading commences. More...
 
virtual void load ()
 Called after init(). More...
 
virtual void loadComplete ()
 Called after load() finishes running. More...
 
virtual void saveDataThread ()
 Called if game created saveThread using Environment::createGameSaveThread(). More...
 
virtual void update (fp32_hf dt)=0
 Called by the framework once for every iteration of the game loop, immediately before rendering takes place. More...
 
virtual void draw (Graphics *g)=0
 Called by the framework once for every iteration of the main loop. More...
 
virtual void fullscreenToggled (bool isFullscreen)
 Called by the framework after a fullscreen toggle takes place. More...
 
virtual void preShutdown ()
 Called by the framework after the main loop exits. More...
 
virtual void handleMouseAdded (int32_hf mouseId)
 Called by the framework when a new Mouse object becomes available. More...
 
virtual void handleMouseRemoved (int32_hf mouseId)
 Called by the framework when an existing Mouse object becomes unavailable. More...
 
virtual void handleTouchAdded (int32_hf touchId)
 Called by the framework when a new Touch object becomes available. More...
 
virtual void handleTouchRemoved (int32_hf touchId)
 Called by the framework when an existing Touch object becomes unavailable. More...
 
virtual void handleGamePadAdded (int32_hf gamePadId)
 Called by the framework when a new GamePad object becomes available. More...
 
virtual void handleGamePadRemoved (int32_hf gamePadId)
 Called by the framework when an existing GamePad object becomes unavailable. More...
 
virtual void windowShown (int32_hf windowID)
 Called by the framework when window is shown. More...
 
virtual void windowHidden (int32_hf windowID)
 Called by the framework when window is hidden. More...
 
virtual void windowExposed (int32_hf windowID)
 Called by the framework when window is exposed. More...
 
virtual void windowMoved (int32_hf windowID, int32_hf x, int32_hf y)
 Called by the framework when window moved. More...
 
virtual void windowResized (int32_hf windowID, int32_hf w, int32_hf h)
 Called by the framework when window is resized. More...
 
virtual void windowMinimized (int32_hf windowID)
 Called by the framework when window is minimized. More...
 
virtual void windowMaximized (int32_hf windowID)
 Called by the framework when window is maximized. More...
 
virtual void windowRestored (int32_hf windowID)
 Called by the framework when window is restored. More...
 
virtual void windowFocusLost (int32_hf windowID)
 Called when the window loses focus. More...
 
virtual void windowFocusGained (int32_hf windowID)
 Called when the window gains focus. More...
 
virtual void windowClosed (int32_hf windowID)
 Called when the window is closed. More...
 
virtual void appTerminating ()
 Called when the application is being terminated by the OS. (iOS and Android only) More...
 
virtual void appLowMemory ()
 Called when the application is low on memory, free memory if possible.(iOS and Android only) More...
 
virtual void appWillEnterBackground ()
 Called when the application is about to enter the background. (iOS and Android only) More...
 
virtual void appDidEnterBackground ()
 Called when the application did enter the background and may not get CPU for some time.(iOS and Android only) More...
 
virtual void appWillEnterForeground ()
 Called when the application is about to enter the foreground. (iOS and Android only) More...
 
virtual void appDidEnterForeground ()
 Called when the application is interactive. (iOS and Android only) More...
 
virtual void destroyRenderTextures ()
 Called by the framework when Render textures needs to be destroyed. More...
 
virtual void createRenderTextures ()
 Called by the framework when Render textures needs to be created/initialized. More...
 

Detailed Description

Interface used by the framework to drive the main loop.

Each game should implement the methods it needs from the Game interface.

#pragma once
#include "hffwk.h"
class GameMain : public HFCore::Game
{
public:
GameMain();
virtual ~GameMain();
// singleton:
static GameMain *instance();
static void destroy();
// implementation of HFCore::Game:
virtual void init();
virtual void update(fp32_hf dt);
virtual void draw(HFCore::Graphics *g);
// and the rest of methods needed..
private:
// singleton instance:
static GameMain *gInstance;
};

Definition at line 67 of file Game.h.

Member Function Documentation

◆ appDidEnterBackground()

virtual void HFCore::Game::appDidEnterBackground ( )
inlinevirtual

Called when the application did enter the background and may not get CPU for some time.(iOS and Android only)

Note
Called on iOS in applicationDidEnterBackground().
Called on Android in onPause().

Definition at line 326 of file Game.h.

◆ appDidEnterForeground()

virtual void HFCore::Game::appDidEnterForeground ( )
inlinevirtual

Called when the application is interactive. (iOS and Android only)

Note
Called on iOS in applicationDidBecomeActive().
Called on Android in onResume().

Definition at line 344 of file Game.h.

◆ appLowMemory()

virtual void HFCore::Game::appLowMemory ( )
inlinevirtual

Called when the application is low on memory, free memory if possible.(iOS and Android only)

Note
Called on iOS in applicationDidReceiveMemoryWarning().
Called on Android in onLowMemory().

Definition at line 308 of file Game.h.

◆ appTerminating()

virtual void HFCore::Game::appTerminating ( )
inlinevirtual

Called when the application is being terminated by the OS. (iOS and Android only)

Note
Called on iOS in applicationWillTerminate().
Called on Android in onDestroy().

Definition at line 299 of file Game.h.

◆ appWillEnterBackground()

virtual void HFCore::Game::appWillEnterBackground ( )
inlinevirtual

Called when the application is about to enter the background. (iOS and Android only)

Note
Called on iOS in applicationWillResignActive().
Called on Android in onPause().

Definition at line 317 of file Game.h.

◆ appWillEnterForeground()

virtual void HFCore::Game::appWillEnterForeground ( )
inlinevirtual

Called when the application is about to enter the foreground. (iOS and Android only)

Note
Called on iOS in applicationWillEnterForeground().
Called on Android in onResume().

Definition at line 335 of file Game.h.

◆ createRenderTextures()

virtual void HFCore::Game::createRenderTextures ( )
inlinevirtual

Called by the framework when Render textures needs to be created/initialized.

Create/init render textures here.

Definition at line 360 of file Game.h.

◆ destroyRenderTextures()

virtual void HFCore::Game::destroyRenderTextures ( )
inlinevirtual

Called by the framework when Render textures needs to be destroyed.

Destroy any render textures here.

Definition at line 352 of file Game.h.

◆ draw()

virtual void HFCore::Game::draw ( Graphics g)
pure virtual

Called by the framework once for every iteration of the main loop.

Implementations should draw themselves using the Graphics object on every call to this method

Parameters
gPointer to Graphics object.

◆ fullscreenToggled()

virtual void HFCore::Game::fullscreenToggled ( bool  isFullscreen)
inlinevirtual

Called by the framework after a fullscreen toggle takes place.

Parameters
isFullscreentrue if fullscreen, false if windowed.

Definition at line 160 of file Game.h.

◆ handleGamePadAdded()

virtual void HFCore::Game::handleGamePadAdded ( int32_hf  gamePadId)
inlinevirtual

Called by the framework when a new GamePad object becomes available.

Parameters
gamePadIdID of the GamePad.

Definition at line 202 of file Game.h.

◆ handleGamePadRemoved()

virtual void HFCore::Game::handleGamePadRemoved ( int32_hf  gamePadId)
inlinevirtual

Called by the framework when an existing GamePad object becomes unavailable.

Parameters
gamePadIdID of the GamePad.

Definition at line 209 of file Game.h.

◆ handleMouseAdded()

virtual void HFCore::Game::handleMouseAdded ( int32_hf  mouseId)
inlinevirtual

Called by the framework when a new Mouse object becomes available.

Parameters
mouseIdID of the Mouse.

Definition at line 174 of file Game.h.

◆ handleMouseRemoved()

virtual void HFCore::Game::handleMouseRemoved ( int32_hf  mouseId)
inlinevirtual

Called by the framework when an existing Mouse object becomes unavailable.

Parameters
mouseIdID of the Mouse.

Definition at line 181 of file Game.h.

◆ handleTouchAdded()

virtual void HFCore::Game::handleTouchAdded ( int32_hf  touchId)
inlinevirtual

Called by the framework when a new Touch object becomes available.

Parameters
touchIdID of the Touch object.

Definition at line 188 of file Game.h.

◆ handleTouchRemoved()

virtual void HFCore::Game::handleTouchRemoved ( int32_hf  touchId)
inlinevirtual

Called by the framework when an existing Touch object becomes unavailable.

Parameters
touchIdID of the Touch object.

Definition at line 195 of file Game.h.

◆ init()

virtual void HFCore::Game::init ( )
inlinevirtual

Called by the framework after subsystems are initialized but before the initial game loading commences.

This is where the bare-bones initialization tasks (e.g. creating the loading screen) should be performed.

Definition at line 109 of file Game.h.

◆ load()

virtual void HFCore::Game::load ( )
inlinevirtual

Called after init().

This is where the game should do the more beefy initialization work (e.g. heavy resource loading, heavy graphics setup). this call runs in a separate thread, so be careful what you do here.

Definition at line 119 of file Game.h.

◆ loadComplete()

virtual void HFCore::Game::loadComplete ( )
inlinevirtual

Called after load() finishes running.

This call runs in the main thread.

Definition at line 126 of file Game.h.

◆ preInitDraw()

virtual void HFCore::Game::preInitDraw ( Graphics g)
inlinevirtual

Called by the framework before the game's init() method is called.

This gives the game an opportunity to draw something to the screen that will be displayed until the first call to draw(), which will take place after the init() call.

Parameters
gPointer to Graphics object.

Definition at line 100 of file Game.h.

◆ preInitLoad()

virtual void HFCore::Game::preInitLoad ( )
inlinevirtual

Called by the framework before the game's init() method is called.

This gives the game an opportunity to load the resources for preInitDraw().

Definition at line 87 of file Game.h.

◆ preShutdown()

virtual void HFCore::Game::preShutdown ( )
inlinevirtual

Called by the framework after the main loop exits.

Perform any cleanup operations it needs to at shutdown.

Definition at line 167 of file Game.h.

◆ saveDataThread()

virtual void HFCore::Game::saveDataThread ( )
inlinevirtual

Called if game created saveThread using Environment::createGameSaveThread().

Good place to save game data here.

Definition at line 134 of file Game.h.

◆ update()

virtual void HFCore::Game::update ( fp32_hf  dt)
pure virtual

Called by the framework once for every iteration of the game loop, immediately before rendering takes place.

Parameters
dtAmount of time that's passed since the last call.

◆ windowClosed()

virtual void HFCore::Game::windowClosed ( int32_hf  windowID)
inlinevirtual

Called when the window is closed.

Parameters
windowIDID of the Window.

Definition at line 290 of file Game.h.

◆ windowExposed()

virtual void HFCore::Game::windowExposed ( int32_hf  windowID)
inlinevirtual

Called by the framework when window is exposed.

Parameters
windowIDID of the Window.

Definition at line 230 of file Game.h.

◆ windowFocusGained()

virtual void HFCore::Game::windowFocusGained ( int32_hf  windowID)
inlinevirtual

Called when the window gains focus.

Parameters
windowIDID of the Window.

Definition at line 283 of file Game.h.

◆ windowFocusLost()

virtual void HFCore::Game::windowFocusLost ( int32_hf  windowID)
inlinevirtual

Called when the window loses focus.

Parameters
windowIDID of the Window.

Definition at line 276 of file Game.h.

◆ windowHidden()

virtual void HFCore::Game::windowHidden ( int32_hf  windowID)
inlinevirtual

Called by the framework when window is hidden.

Parameters
windowIDID of the Window.

Definition at line 223 of file Game.h.

◆ windowMaximized()

virtual void HFCore::Game::windowMaximized ( int32_hf  windowID)
inlinevirtual

Called by the framework when window is maximized.

Parameters
windowIDID of the Window.

Definition at line 262 of file Game.h.

◆ windowMinimized()

virtual void HFCore::Game::windowMinimized ( int32_hf  windowID)
inlinevirtual

Called by the framework when window is minimized.

Parameters
windowIDID of the Window.

Definition at line 255 of file Game.h.

◆ windowMoved()

virtual void HFCore::Game::windowMoved ( int32_hf  windowID,
int32_hf  x,
int32_hf  y 
)
inlinevirtual

Called by the framework when window moved.

Parameters
windowIDID of the Window.
xNew window position on X axis.
yNew window position on Y axis.

Definition at line 239 of file Game.h.

◆ windowResized()

virtual void HFCore::Game::windowResized ( int32_hf  windowID,
int32_hf  w,
int32_hf  h 
)
inlinevirtual

Called by the framework when window is resized.

Parameters
windowIDID of the Window.
wNew width of the window.
hNew height of the window.

Definition at line 248 of file Game.h.

◆ windowRestored()

virtual void HFCore::Game::windowRestored ( int32_hf  windowID)
inlinevirtual

Called by the framework when window is restored.

Parameters
windowIDID of the Window.

Definition at line 269 of file Game.h.

◆ windowShown()

virtual void HFCore::Game::windowShown ( int32_hf  windowID)
inlinevirtual

Called by the framework when window is shown.

Parameters
windowIDID of the Window.

Definition at line 216 of file Game.h.


The documentation for this class was generated from the following file: