Application class. More...
#include <kanzi/core.ui/application/application.hpp>
Public Types | |
enum | State { Uninitialized, Running, Sleeping, Quitting, Error } |
Enumeration for different application states. More... | |
Public Types inherited from kanzi::Module | |
typedef vector< const Metaclass * > | MetaclassContainer |
typedef MetaclassContainer::iterator | MetaclassIterator |
Public Member Functions | |
Application () | |
Constructs the application object. More... | |
virtual | ~Application () |
Destructs the application object. More... | |
void | initialize (const SystemProperties &systemProperties) |
Initializes the application to a consistent state. More... | |
void | uninitialize () |
Uninitializes the application. More... | |
void | initializeGL () |
Initializes the graphics language subsystem. More... | |
void | uninitializeGL () |
Uninitializes the graphics language subsystem. More... | |
void | suspendGL () |
Suspends the graphics language subsystem. More... | |
void | resumeGL () |
Resumes the graphics language subsystem. More... | |
Domain * | getDomain () const |
Access domain. More... | |
Renderer3D * | getRenderer3D () const |
Access the renderer. More... | |
Node2DSharedPtr | getRoot () const |
Access root node. More... | |
ScreenSharedPtr | getScreen () const |
Access screen. More... | |
void | setScreen (ScreenSharedPtr screen) |
Set screen. More... | |
KzuTaskScheduler * | getTaskScheduler () const |
Access engine task scheduler. More... | |
void | queueTaskExecuteOnce (string_view taskName, Scheduler::Task task) |
Queue a task to be executed once by the internal task scheduler. More... | |
ResourceManager * | getResourceManager () const |
Access resource manager. More... | |
InputManager * | getInputManager () const |
Access input manager. More... | |
KzuBinaryLoader * | getBinaryLoader () const |
Access binary loader. More... | |
KzuMessageDispatcher * | getMessageDispatcher () const |
Access message dispatcher. More... | |
float | getFramesPerSecond () const |
Access FPS info. More... | |
virtual void | projectReloaded () |
size_t | getGraphicsOutputCount () const |
Access graphics output count. More... | |
GraphicsOutputSharedPtr | getGraphicsOutput (size_t index=0) const |
Access graphics outputs. More... | |
void | appendGraphicsOutput (GraphicsOutputSharedPtr graphicsOutput) |
Attach graphics output. More... | |
void | removeGraphicsOutput (size_t index=0) |
Remove graphics output. More... | |
size_t | getEventSourceCount () const |
Access event source count. More... | |
EventSourceSharedPtr | getEventSource (size_t index=0) const |
Access event sources. More... | |
void | appendEventSource (EventSourceSharedPtr eventSource) |
Attach event source. More... | |
void | removeEventSource (size_t index=0) |
Remove event source. More... | |
State | getState () |
Access application state. More... | |
chrono::microseconds | getLastFrameTime () const |
Gets time taken to render last frame. More... | |
ApplicationProperties | getApplicationProperties () const |
Access application properties. More... | |
void | main (const SystemProperties &systemProperties) |
Application entry point. More... | |
void | run () |
Application main loop. More... | |
void | update (chrono::milliseconds deltaTime) |
Updates application logic. More... | |
void | render () |
Renders the root layer. More... | |
void | suspend () |
Suspends the thread for the remainder of the frame. More... | |
void | yield () |
Irrevocably suspends the thread for the remainder of the frame. More... | |
void | progressDeploymentQueue () |
Processes the deployment queue for asynchronous loading tasks. More... | |
void | sleep () |
Puts the application to sleep as soon as possible. More... | |
void | wakeup () |
Wakes up the application from sleep as soon as possible. More... | |
void | quit () |
Quits the application as soon as possible. More... | |
void | beginFrame (const GraphicsOutput &graphicsOutput) |
void | renderFrame1 (const GraphicsOutput &graphicsOutput, bool toolPresent, const RenderPassSharedPtr &debugComposer) |
void | renderFrame2 () |
void | renderFrame3 () |
void | postRender (const GraphicsOutput &graphicsOutput) |
void | endFrame () |
void | update1 (chrono::milliseconds deltaTime, const GraphicsOutput &graphicsOutput, kzBool) |
void | update2 (chrono::milliseconds deltaTime, const GraphicsOutput &graphicsOutput, kzBool toolPresent, kzBool centerViewport) |
void | executePendingChanges (kzBool toolPresent) |
void | projectReloaded (bool isToolPresent) |
void | initializeProject (kzBool toolPresent) |
void | initializeProjectTask (kzBool toolPresent) |
void | reloadProject (kzUint byteCount, const byte *bytes, bool isToolPresent) |
void | reloadProjectFromFile (kzString binaryPath, bool isToolPresent) |
void | reloadProjectFromFileResource (kzString resourceFile, bool isToolPresent) |
void | initializeGLContext () |
void | uninitializeGLContext () |
ApplicationProperties::PerformanceInfoLevel | getPerformanceInfoLevel () const |
Gets performance info level. More... | |
void | setPerformanceInfoLevel (ApplicationProperties::PerformanceInfoLevel level) |
Sets performance info level. More... | |
StopWatch & | getStopWatch () |
Gets default main loop timer. More... | |
void | setAllowIndefiniteSleep (bool enabled) |
Sets or resets flag for allowing indefinite sleep. More... | |
bool | isRenderRequired () const |
Returns whether an immediate redraw is needed. More... | |
Public Member Functions inherited from kanzi::Module | |
Module () | |
virtual MetaclassContainer | getMetaclassesOverride () |
virtual void | destroy () |
virtual void | registerMetadataOverride (ObjectFactory &) |
void | setDomain (Domain *domain) |
Set the domain. More... | |
Protected Member Functions | |
virtual void | onStartup () |
Function callback for application start. More... | |
virtual void | onShutdown () |
Function callback for application end. More... | |
virtual void | onProjectLoaded () |
Function callback for initialization that is using the .KZB data. This function is called right after the .KZB binaries have been loaded. More... | |
virtual void | onConfigure (ApplicationProperties &configuration) |
User-defined configuration. More... | |
virtual void | onUpdate (chrono::milliseconds deltaTime) |
Function callback for updating logic. More... | |
virtual void | onPreRender () |
Function callback for rendering. This function is called for every frame before any other rendering function. More... | |
virtual void | onPostRender () |
Function callback for rendering. This function is called for every frame after the root layer has been rendered. More... | |
virtual void | onPointerInputEvent (const KzsInputEventPointer *inputData) |
Event callback for pointing device (e.g. mouse or touch screen) input events. More... | |
virtual void | onKeyInputEvent (const KzsInputEventKey *inputData) |
Event callback for keyboard input events. More... | |
virtual void | onIdle () |
Event callback for idle loop. More... | |
virtual void | onSleep () |
Event callback for application sleep. More... | |
virtual void | onWakeup () |
Event callback for application wakeup. More... | |
virtual void | initializeOverride (const SystemProperties &systemProperties) |
Override function for initialize(). More... | |
virtual void | uninitializeOverride () |
Override function for uninitialize(). More... | |
virtual void | initializeGLOverride () |
Override function for initializeGL(). More... | |
virtual void | uninitializeGLOverride () |
Override function for uninitializeGL(). More... | |
virtual void | suspendGLOverride () |
Override function for suspendGL(). More... | |
virtual void | resumeGLOverride () |
Override function for resumeGL(). More... | |
virtual void | mainOverride (const SystemProperties &systemProperties) |
Override function for main(). More... | |
virtual void | updateOverride (chrono::milliseconds deltaTime) |
Override function for update(). More... | |
virtual void | renderOverride () |
Override function for render(). More... | |
virtual void | suspendOverride () |
Override function for suspend(). More... | |
virtual void | yieldOverride () |
Override function for yield(). More... | |
virtual void | sleepOverride () |
Override function for sleep(). More... | |
virtual void | wakeupOverride () |
Override function for wakeup(). More... | |
virtual void | onProjectInitialized () |
virtual void | progressDeploymentQueueOverride () |
Override function for progressDeploymentQueue(). More... | |
virtual void | initializeProperties (const SystemProperties &systemProperties) |
virtual void | initializeEngine () |
virtual void | initializeSystem () |
void | projectInitialized () |
void | projectLoaded () |
void | logStartupProfilingData () const |
To log startup profiling data, use logStartupProfilingData(). More... | |
StartupProfilerRegistry & | getStartupProfilerRegistry () const |
To get startup profiler registry use, getStartupProfilerRegistry(). More... | |
virtual void | renderEngine () |
virtual void | handleEvents (const KzsEventQueue *eventQueue) |
virtual bool | isToolPresent () const |
virtual void | runOverride () |
Override function for run(). More... | |
void | idle () |
void | idleLoop () |
void | loadPlugins () |
void | logGraphicsInformation () |
Log graphics information based on application properties. More... | |
KzuEngine * | getEngine () const |
Access engine. More... | |
PerformanceInfo & | acquirePerformanceInfo () |
Acquire performance info object. More... | |
optional< chrono::milliseconds > | getProposedSleepTime (chrono::milliseconds deltaTime) |
Gets the time main thread can sleep in milliseconds, supposing given duration would have passed from the start of the frame. More... | |
chrono::milliseconds | getProposedSleepTimePostRender (chrono::milliseconds deltaTime) |
Gets the time the main thread can sleep after rendering. More... | |
Protected Member Functions inherited from kanzi::Module | |
virtual | ~Module () |
Protected Attributes | |
vector< EventSourceSharedPtr > | m_eventSources |
Container for event sources. More... | |
vector< GraphicsOutputSharedPtr > | m_graphicsOutputs |
Container for graphics outputs. More... | |
State | m_state |
Current state of the application. More... | |
SystemProperties | m_systemProperties |
System properties. More... | |
ApplicationProperties | m_applicationProperties |
Application properties. More... | |
KzcMemoryManager * | m_systemMemoryManager |
System memory manager (legacy). More... | |
KzsEventQueue * | m_eventQueue |
The event queue for user input and window events. More... | |
KzsEventQueue * | m_eventQueueBuffer |
Temporary event queue used for combining similar events. More... | |
KzuEngine * | m_engine |
Engine instance. More... | |
Scheduler | m_scheduler |
Execution scheduler. More... | |
unique_ptr< PerformanceInfo > | m_performanceInfo |
Performance info. More... | |
bool | m_projectLoaded |
Flag to be set when project has been loaded. More... | |
SuspensionManager | m_suspensionManager |
Suspension manager for main loop. More... | |
FPSConstraints | m_fpsConstraints |
FPS constraints for main loop. More... | |
Protected Attributes inherited from kanzi::Module | |
Domain * | m_domain |
The domain this module is registered to. More... | |
Friends | |
class | PreviewApplication |
Application class.
Base class for application logic.
Enumeration for different application states.
|
explicit |
Constructs the application object.
|
virtual |
Destructs the application object.
void kanzi::Application::initialize | ( | const SystemProperties & | systemProperties | ) |
Initializes the application to a consistent state.
This is the first function called by the application framework after constructing the application. This function tries to read the file application.cfg and shouldn't be called before the file system of the operating system has been initialized.
The default behavior can be changed by overriding initializeOverride().
systemProperties | Command line parameters of the program. |
void kanzi::Application::uninitialize | ( | ) |
Uninitializes the application.
This is the last function called by the application framework before destruction.
The default behavior can be changed by overriding uninitializeOverride().
void kanzi::Application::initializeGL | ( | ) |
Initializes the graphics language subsystem.
This function is called by the application framework before entering the program main loop, but after a GL context has been activated. It initializes OpenGL-related subsystems.
The default behavior can be changed by overriding initializeGLOverride().
void kanzi::Application::uninitializeGL | ( | ) |
Uninitializes the graphics language subsystem.
This function is called by the application framework after exiting the program main loop, but before a GL context has been deactivated. It undeploys all GPU resources.
The default behavior can be changed by overriding uninitializeGLOverride().
void kanzi::Application::suspendGL | ( | ) |
Suspends the graphics language subsystem.
This function is called by the application framework during application suspension, on systems where the graphics language resources are not guaranteed to be retained until the application resumes. It undeploys all GPU resources and reschedules them for redeployment.
When your applications suspends, the GPU resources not stored in a .kzb file become invalid. Destroy these resources and recreate them on resume. Make sure that after recreating a resource the pointers are correct. Kanzi automatically restores all other resources.
The default behavior can be changed by overriding suspendGLOverride().
void kanzi::Application::resumeGL | ( | ) |
Resumes the graphics language subsystem.
This function is called by the application framework during application resume, if suspendGL() was called during suspension. It deploys GPU resources that were undeployed during suspendGL().
The default behavior can be changed by overriding resumeGLOverride().
Domain* kanzi::Application::getDomain | ( | ) | const |
Access domain.
Renderer3D* kanzi::Application::getRenderer3D | ( | ) | const |
Access the renderer.
Node2DSharedPtr kanzi::Application::getRoot | ( | ) | const |
Access root node.
ScreenSharedPtr kanzi::Application::getScreen | ( | ) | const |
Access screen.
void kanzi::Application::setScreen | ( | ScreenSharedPtr | screen | ) |
Set screen.
KzuTaskScheduler* kanzi::Application::getTaskScheduler | ( | ) | const |
Access engine task scheduler.
void kanzi::Application::queueTaskExecuteOnce | ( | string_view | taskName, |
Scheduler::Task | task | ||
) |
Queue a task to be executed once by the internal task scheduler.
taskName | Task name, must be unique. |
task | Task to execute. |
ResourceManager* kanzi::Application::getResourceManager | ( | ) | const |
Access resource manager.
InputManager* kanzi::Application::getInputManager | ( | ) | const |
Access input manager.
KzuBinaryLoader* kanzi::Application::getBinaryLoader | ( | ) | const |
Access binary loader.
KzuMessageDispatcher* kanzi::Application::getMessageDispatcher | ( | ) | const |
Access message dispatcher.
float kanzi::Application::getFramesPerSecond | ( | ) | const |
Access FPS info.
|
virtual |
size_t kanzi::Application::getGraphicsOutputCount | ( | ) | const |
Access graphics output count.
GraphicsOutputSharedPtr kanzi::Application::getGraphicsOutput | ( | size_t | index = 0 | ) | const |
Access graphics outputs.
index | Index of the graphics output to access. |
void kanzi::Application::appendGraphicsOutput | ( | GraphicsOutputSharedPtr | graphicsOutput | ) |
Attach graphics output.
graphicsOutput | Shared pointer to the graphics output to attach. |
void kanzi::Application::removeGraphicsOutput | ( | size_t | index = 0 | ) |
Remove graphics output.
index | Index of the graphics output to remove. |
size_t kanzi::Application::getEventSourceCount | ( | ) | const |
Access event source count.
EventSourceSharedPtr kanzi::Application::getEventSource | ( | size_t | index = 0 | ) | const |
Access event sources.
index | Index of the event source to access. |
void kanzi::Application::appendEventSource | ( | EventSourceSharedPtr | eventSource | ) |
Attach event source.
eventSource | Shared pointer to the event source to attach. |
void kanzi::Application::removeEventSource | ( | size_t | index = 0 | ) |
Remove event source.
index | Index of the event source to remove. |
State kanzi::Application::getState | ( | ) |
Access application state.
chrono::microseconds kanzi::Application::getLastFrameTime | ( | ) | const |
Gets time taken to render last frame.
ApplicationProperties kanzi::Application::getApplicationProperties | ( | ) | const |
Access application properties.
void kanzi::Application::main | ( | const SystemProperties & | systemProperties | ) |
Application entry point.
This high-level function implements the default initialization and main loop. It is called by the application framework, except on callbacks-only systems.
The default behavior can be changed by overriding mainOverride().
systemProperties | Command line parameters of the program. |
void kanzi::Application::run | ( | ) |
Application main loop.
Does not return while application is in Running state.
void kanzi::Application::update | ( | chrono::milliseconds | deltaTime | ) |
Updates application logic.
This function is called once per frame during normal operation. It refreshes the application state and prepares the scene for rendering.
The default behavior can be changed by overriding updateOverride().
deltaTime | The time elapsed since the previous call to update(). |
void kanzi::Application::render | ( | ) |
Renders the root layer.
This function is called after update once per frame during normal operation. It renders the current scene.
The default behavior can be changed by overriding renderOverride().
void kanzi::Application::suspend | ( | ) |
Suspends the thread for the remainder of the frame.
May suspend indefinitely, if there is no reason to update. Will return when there is input or a queued task available.
void kanzi::Application::yield | ( | ) |
Irrevocably suspends the thread for the remainder of the frame.
void kanzi::Application::progressDeploymentQueue | ( | ) |
Processes the deployment queue for asynchronous loading tasks.
By default this function processes a single item from the deployment queue of background loading tasks every frame.
You can change the default behavior of the function by overriding the progressDeploymentQueueOverride() function.
void kanzi::Application::sleep | ( | ) |
Puts the application to sleep as soon as possible.
void kanzi::Application::wakeup | ( | ) |
Wakes up the application from sleep as soon as possible.
void kanzi::Application::quit | ( | ) |
Quits the application as soon as possible.
void kanzi::Application::beginFrame | ( | const GraphicsOutput & | graphicsOutput | ) |
void kanzi::Application::renderFrame1 | ( | const GraphicsOutput & | graphicsOutput, |
bool | toolPresent, | ||
const RenderPassSharedPtr & | debugComposer | ||
) |
void kanzi::Application::renderFrame2 | ( | ) |
void kanzi::Application::renderFrame3 | ( | ) |
void kanzi::Application::postRender | ( | const GraphicsOutput & | graphicsOutput | ) |
void kanzi::Application::endFrame | ( | ) |
void kanzi::Application::update1 | ( | chrono::milliseconds | deltaTime, |
const GraphicsOutput & | graphicsOutput, | ||
kzBool | |||
) |
void kanzi::Application::update2 | ( | chrono::milliseconds | deltaTime, |
const GraphicsOutput & | graphicsOutput, | ||
kzBool | toolPresent, | ||
kzBool | centerViewport | ||
) |
void kanzi::Application::executePendingChanges | ( | kzBool | toolPresent | ) |
void kanzi::Application::projectReloaded | ( | bool | isToolPresent | ) |
void kanzi::Application::initializeProject | ( | kzBool | toolPresent | ) |
void kanzi::Application::initializeProjectTask | ( | kzBool | toolPresent | ) |
void kanzi::Application::reloadProjectFromFile | ( | kzString | binaryPath, |
bool | isToolPresent | ||
) |
void kanzi::Application::reloadProjectFromFileResource | ( | kzString | resourceFile, |
bool | isToolPresent | ||
) |
void kanzi::Application::initializeGLContext | ( | ) |
void kanzi::Application::uninitializeGLContext | ( | ) |
|
inline |
Gets performance info level.
If performance info is not #PerformanceInfoDisabled, textual information HUD will be drawn after onPostRender has been called.
|
inline |
Sets performance info level.
Equal to application configuration has "PerformanceInfoLevel" option. Setting the level to #PerformanceInfoDisabled (0) will turn off the display (default). Setting the level to #PerformanceInfoFPS (1) will display framerate. Setting the level to #PerformanceInfoFull (2) will display additional information about rendering batches.
StopWatch& kanzi::Application::getStopWatch | ( | ) |
Gets default main loop timer.
|
inline |
Sets or resets flag for allowing indefinite sleep.
enabled | True to enable indefinite sleep, false to always wake up in frame time. |
bool kanzi::Application::isRenderRequired | ( | ) | const |
Returns whether an immediate redraw is needed.
|
protectedvirtual |
Function callback for application start.
|
protectedvirtual |
Function callback for application end.
|
protectedvirtual |
Function callback for initialization that is using the .KZB data. This function is called right after the .KZB binaries have been loaded.
|
protectedvirtual |
User-defined configuration.
This callback is called before the application.cfg is read, and before the graphics subsystem is initialized.
configuration | Allows modification of the application properties. |
Reimplemented in kanzi::ExampleApplication.
|
protectedvirtual |
Function callback for updating logic.
This function is called for every frame.
deltaTime | The delta time passed to update(). By default this is the time elapsed since the previous frame in milliseconds. |
|
protectedvirtual |
Function callback for rendering. This function is called for every frame before any other rendering function.
|
protectedvirtual |
Function callback for rendering. This function is called for every frame after the root layer has been rendered.
|
protectedvirtual |
Event callback for pointing device (e.g. mouse or touch screen) input events.
|
protectedvirtual |
Event callback for keyboard input events.
Reimplemented in kanzi::ExampleApplication.
|
protectedvirtual |
Event callback for idle loop.
|
protectedvirtual |
Event callback for application sleep.
|
protectedvirtual |
Event callback for application wakeup.
|
protectedvirtual |
Override function for initialize().
|
protectedvirtual |
Override function for uninitialize().
|
protectedvirtual |
Override function for initializeGL().
|
protectedvirtual |
Override function for uninitializeGL().
|
protectedvirtual |
Override function for suspendGL().
|
protectedvirtual |
Override function for resumeGL().
|
protectedvirtual |
Override function for main().
|
protectedvirtual |
Override function for update().
|
protectedvirtual |
Override function for render().
|
protectedvirtual |
Override function for suspend().
|
protectedvirtual |
Override function for yield().
|
protectedvirtual |
Override function for sleep().
|
protectedvirtual |
Override function for wakeup().
|
protectedvirtual |
|
protectedvirtual |
Override function for progressDeploymentQueue().
|
protectedvirtual |
|
protectedvirtual |
|
protectedvirtual |
|
protected |
|
protected |
|
protected |
To log startup profiling data, use logStartupProfilingData().
|
inlineprotected |
To get startup profiler registry use, getStartupProfilerRegistry().
|
protectedvirtual |
|
protectedvirtual |
|
inlineprotectedvirtual |
|
protectedvirtual |
Override function for run().
|
protected |
|
protected |
|
protected |
|
protected |
Log graphics information based on application properties.
|
protected |
Access engine.
|
protected |
Acquire performance info object.
Will create the object if it does not exist.
|
protected |
Gets the time main thread can sleep in milliseconds, supposing given duration would have passed from the start of the frame.
The time passed is used to determine the remaining sleep time of this frame, for example when some time has elapsed in animations.
deltaTime | Time passed since the frame started. |
|
protected |
Gets the time the main thread can sleep after rendering.
Time spent since beginning of the frame is given so the time spent in rendering can be determined.
|
friend |
|
protected |
Container for event sources.
|
protected |
Container for graphics outputs.
|
protected |
Current state of the application.
|
protected |
System properties.
|
protected |
Application properties.
|
protected |
System memory manager (legacy).
|
protected |
The event queue for user input and window events.
|
protected |
Temporary event queue used for combining similar events.
|
protected |
Engine instance.
|
protected |
Execution scheduler.
|
protected |
Performance info.
|
protected |
Flag to be set when project has been loaded.
|
protected |
Suspension manager for main loop.
|
protected |
FPS constraints for main loop.