NAP
Public Member Functions | List of all members
BaseApp Class Reference

#include <app.h>

Public Member Functions

 BaseApp (nap::Core &core)
 
virtual ~BaseApp ()=default
 
 BaseApp (BaseApp &)=delete
 
BaseAppoperator= (const BaseApp &)=delete
 
 BaseApp (BaseApp &&)=delete
 
BaseAppoperator= (BaseApp &&)=delete
 
virtual bool init (utility::ErrorState &error)
 
virtual void update (double deltaTime)
 
virtual void render ()
 
virtual bool shutdownRequested ()
 
virtual int shutdown ()
 
void quit ()
 
const nap::CoregetCore () const
 
nap::CoregetCore ()
 
bool shouldQuit () const
 
void capFramerate (bool value)
 
void setFramerate (float framerate)
 
float getRequestedFramerate () const
 
float getActualFramerate () const
 
bool framerateCapped () const
 

Description

Acts as a blueprint for all NAP applications. This class does not receive any input events. Every application holds a reference to a Core object. The init, update, render and shutdown functions are called from within the main loop by the AppRunner.

Constructor & Destructor Documentation

◆ BaseApp() [1/3]

BaseApp ( nap::Core core)

◆ ~BaseApp()

virtual ~BaseApp ( )
virtualdefault

◆ BaseApp() [2/3]

BaseApp ( BaseApp )
delete

Copy is not allowed

◆ BaseApp() [3/3]

BaseApp ( BaseApp &&  )
delete

Move is not allowed

Member Function Documentation

◆ capFramerate()

void capFramerate ( bool  value)

Turns limiting the execution speed of the application on / off. This causes the application to sleep in between calls when execution speed exceeds the set framerate. The final execution speed may vary from platform to platform, based on the accuracy of the timers, but will always be less than the given framerate.

Parameters
valueif the framerate is capped

◆ framerateCapped()

bool framerateCapped ( ) const

Returns if the execution speed of the application is limited.

Returns
if the framerate is capped

◆ getActualFramerate()

float getActualFramerate ( ) const

Returns the actual (average) execution speed of the application, in frames per second, as measured by core.

Returns
the actual framerate.

◆ getCore() [1/2]

nap::Core& getCore ( )
Returns
nap Core

◆ getCore() [2/2]

const nap::Core& getCore ( ) const
Returns
nap Core const

◆ getRequestedFramerate()

float getRequestedFramerate ( ) const

Returns the requested framerate. This is not the same as the actual framerate. Use Core::getFramerate() to get the actual framerate.

Returns
the requested framerate

◆ init()

virtual bool init ( utility::ErrorState error)
virtual

Initialize your application. Occurs after all the modules have been loaded and services have been initialized. If this call is unsuccessful the application will not continue execution

Parameters
errorcontains the error when initialization fails
Returns
if initialization was successful

◆ operator=() [1/2]

BaseApp& operator= ( BaseApp &&  )
delete

◆ operator=() [2/2]

BaseApp& operator= ( const BaseApp )
delete

◆ quit()

void quit ( )

Call this from your app to terminate the application and exit the main loop.

◆ render()

virtual void render ( )
virtual

Render your application. This is called after update at the end of the loop

◆ setFramerate()

void setFramerate ( float  framerate)

Limit execution speed of the application to the given framerate. This causes the application to sleep in between calls when execution speed exceeds the set framerate. The final execution speed may vary from platform to platform, based on the accuracy of the timers, but will always be less than the given framerate. The requested framerate has no effect when the framerate is not capped.

Parameters
frameratethe requested application framerate.

◆ shouldQuit()

bool shouldQuit ( ) const
Returns
if the application received a quit event

◆ shutdown()

virtual int shutdown ( )
virtual

Called when the app is shutting down after quit() has been called Use this to clear application specific data. This is called before all the services are closed and the app exits return the application exit code, 0 (success) by default

◆ shutdownRequested()

virtual bool shutdownRequested ( )
virtual

Called by the event handler when it receives an external event to quit the running application By default this calls quit() with the return value of this call, which causes the application to stop running You can override it to ignore the event or perform specific logic (such as saving a file) before the app is shutdown()

Returns
if the application should quit, true by default

◆ update()

virtual void update ( double  deltaTime)
virtual

Update your application. This is called after calling update for all registered services but before render

Parameters
deltaTimethe time in seconds between calls