Application class is the base class for Kanzi applications. More...
#include <kanzi/core.ui/application/application.hpp>
Public Member Functions | |
Application () | |
Constructs the application object. More... | |
void | initialize (const SystemProperties &systemProperties) |
Initializes the application to a consistent state. More... | |
void | initializeGL () |
Initializes the graphics language subsystem. More... | |
void | main (const SystemProperties &systemProperties) |
Application entry point. More... | |
void | resumeGL () |
Resumes the graphics language subsystem. More... | |
void | suspendGL () |
Suspends the graphics language subsystem. More... | |
void | uninitialize () |
Uninitializes the application. More... | |
void | uninitializeGL () |
Uninitializes the graphics language subsystem. More... | |
~Application () override | |
Destructs the application object. More... | |
State modifiers. | |
void | pause () |
Puts the application from the Running state to the Paused state. More... | |
void | resume () |
Resumes the application from the Paused state to the Running state. More... | |
void | quit () |
Quits the application. More... | |
Studio preview specific functions. | |
void | patchProject (uintmax_t byteCount, const byte *bytes) |
Applies a Kanzi Studio Preview patch. More... | |
Public Member Functions inherited from kanzi::Module | |
virtual void | destroy () |
virtual MetaclassContainer | getMetaclassesOverride () |
Module () | |
virtual void | registerDebugRenderingFunctions (DebugRenderRegistry &) |
Register the module debug rendering functions. More... | |
virtual void | registerMetadataOverride (ObjectFactory &) |
Register the rest of module metadata, such as loaders for types in module. More... | |
void | setDomain (Domain *domain) |
Set the domain. More... | |
Protected Member Functions | |
Initialization functions. | |
virtual void | initializeProperties (const SystemProperties &systemProperties) |
Loads the application properties, based on configuration file and command-line arguments. More... | |
virtual void | initializeSystem () |
Initializes profiling, event sources, and graphics output. More... | |
virtual void | initializeDomain () |
Initializes Kanzi Domain and loads a kzb file. More... | |
virtual void | initializeMainLoopTasks () |
Attaches the default tasks to the main loop scheduler. More... | |
void | applyMainLoopConfigs () |
Applies the frame limit and idle-suspension configurations from the application properties to the main loop scheduler, and attaches event handles and preconditions. More... | |
Input stage functions. | |
void | clearEventQueue () |
Clears the event queue. More... | |
void | gatherEvents () |
Gathers all input events into the event queue. More... | |
void | handleApplicationEvents () |
Executes the application-defined event handler on all events in the event queue. More... | |
virtual void | handleEvents (EventQueue &eventQueue) |
Executes the application-defined event handler on all events in the event queue. More... | |
void | handleGraphicsEvents () |
Executes the graphics subsystem event handler. More... | |
void | handleInputManagerEvents () |
Executes the input subsystem event handler. More... | |
User stage functions. | |
void | loadStartupKzb () |
Loads the kzb file that is specified by KzuEngine::m_newBinaryName. More... | |
void | progressDeploymentQueue () |
Processes the deployment queue for asynchronous loading tasks. More... | |
void | updateRenderer (chrono::nanoseconds deltaTime) |
Advances renderer clock with time delta, and attaches active graphics output to it. More... | |
Layout stage functions. | |
void | adjustRenderingArea () |
Sets the rendering area on the graphics output based on the size, orientation, and metrics. More... | |
void | layout () |
Lays out the node tree. More... | |
void | extract () |
Extracts the node tree. More... | |
Animate stage functions. | |
void | tickAnimations (chrono::nanoseconds deltaTime) |
Ticks all the active animations. More... | |
Render stage functions. | |
virtual void | render () |
Renders the node tree. More... | |
void | renderPerformanceInfo () |
Renders the Performance HUD. More... | |
void | clearAllRenderBuffers (ColorRGBA clearColor) |
Clears all render buffers. More... | |
Present stage functions. | |
void | present () |
Updates the graphics output buffer with the rendered node tree. More... | |
Callbacks. | |
} | |
virtual void | onStartup () |
Callback for the startup logic. More... | |
virtual void | onShutdown () |
Callback for the shutdown logic. More... | |
virtual void | onConfigure (ApplicationProperties &configuration) |
Callback for configuring the application properties. More... | |
virtual void | onProjectLoaded () |
Callback for initializations that use data from a kzb file. More... | |
virtual void | onUpdate (chrono::nanoseconds deltaTime) |
Callback for the update logic. More... | |
virtual void | onPointerInputEvent (const PointerEvent &pointerEvent) |
Callback for handling of input events from a pointing device, such as a mouse or touch screen. More... | |
virtual void | onKeyInputEvent (const KeyEvent &keyEvent) |
Callback for handling input events from keyboard. More... | |
virtual optional< chrono::nanoseconds > | onSuspend (chrono::nanoseconds remainingFrameAllotment) |
Callback for determining the duration of suspension in a main loop frame. More... | |
virtual void | onPause () |
Kanzi calls this callback when the application main loop enters the Paused state. More... | |
virtual void | onResume () |
Kanzi calls this callback when the application main loop returns from the Paused to the Running state. More... | |
virtual void | onResumeCheck () |
Kanzi calls this callback for the event handling logic when the application main loop is in the Paused state. More... | |
Overrides. | |
virtual void | mainOverride (const SystemProperties &systemProperties) |
Override function for main(). 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 | progressDeploymentQueueOverride () |
Override function for progressDeploymentQueue(). More... | |
Protected Member Functions inherited from kanzi::Module | |
virtual | ~Module ()=default |
Destructor. More... | |
Protected Attributes | |
ApplicationProperties | m_applicationProperties |
Application properties. More... | |
KzuEngine * | m_engine |
Kanzi Engine instance. More... | |
EventQueue | m_eventQueue |
The event queue for user input and window events. More... | |
MainLoopScheduler | m_mainLoopScheduler |
Main loop scheduler. More... | |
unique_ptr< PerformanceInfo > | m_performanceInfo |
Performance HUD information. More... | |
bool | m_projectLoaded |
Flag to be set when project has been loaded. More... | |
SystemProperties | m_systemProperties |
Container of command line parameters of the program. More... | |
Protected Attributes inherited from kanzi::Module | |
Domain * | m_domain |
The domain this module is registered to. More... | |
Friends | |
class | PreviewApplication |
Accessors and mutators. | |
Domain * | getDomain () const |
Access domain. More... | |
Renderer3D * | getRenderer3D () const |
Access the renderer. More... | |
Node2DSharedPtr | getRoot () const |
Access the root node. More... | |
ScreenSharedPtr | getScreen () const |
Access the Screen node. More... | |
void | setScreen (ScreenSharedPtr screen) |
Sets the Screen node. More... | |
const MainLoopScheduler & | getMainLoopScheduler () const |
Access the associated MainLoopScheduler. More... | |
MainLoopScheduler & | getMainLoopScheduler () |
Access the associated MainLoopScheduler. More... | |
ResourceManager * | getResourceManager () const |
Access resource manager. More... | |
InputManager * | getInputManager () const |
Access input manager. More... | |
detail::MessageDispatcher * | getMessageDispatcher () const |
Access message dispatcher. More... | |
float | getFramesPerSecond () const |
Access framerate information. More... | |
size_t | getGraphicsOutputCount () const |
Access graphics output count. More... | |
GraphicsOutputSharedPtr | getGraphicsOutput (size_t index=0) const |
Access graphics outputs. More... | |
template<typename Interface > | |
shared_ptr< Interface > | getGraphicsOutput (size_t index) const |
Query graphics output interfaces. 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 to domain and register its event handle with main loop scheduler. More... | |
void | removeEventSource (size_t index=0) |
Remove event source. More... | |
MainLoopState | getState () const |
Access application state. More... | |
ApplicationProperties | getApplicationProperties () const |
Access application properties. More... | |
ApplicationProperties::PerformanceInfoLevel | getPerformanceInfoLevel () const |
Gets the Performance HUD information level. More... | |
void | setPerformanceInfoLevel (ApplicationProperties::PerformanceInfoLevel level) |
Sets the Performance HUD information level. More... | |
void | loadFontEngine (ApplicationProperties::FontEngine fontEngine) |
Loads the font engine for the font manager. More... | |
void | setAllowIndefiniteSleep (bool enabled) |
Sets or resets the flag that allows indefinite sleep. More... | |
void | logStartupProfilingData () const |
Logs startup profiling data. More... | |
StartupProfilerRegistry & | getStartupProfilerRegistry () const |
Gets the startup profiler registry. More... | |
virtual bool | isToolPresent () const |
Indicates whether application is running in the Kanzi Studio Preview. More... | |
void | logGraphicsInformation () |
Log graphics information based on application properties. More... | |
KzuEngine * | getEngine () const |
Access Kanzi Engine. More... | |
PerformanceInfo & | acquirePerformanceInfo () |
Acquire performance information object. More... | |
Additional Inherited Members | |
Public Types inherited from kanzi::Module | |
typedef vector< const Metaclass * > | MetaclassContainer |
typedef MetaclassContainer::iterator | MetaclassIterator |
Application class is the base class for Kanzi applications.
It implements the Kanzi main loop with help of MainLoopScheduler.
You can customize your application by overriding the virtual functions of the Application class.
You can also customize the main loop using the MainLoopScheduler, which you can access with getMainLoopScheduler(). The MainLoopScheduler lets you add or modify the tasks and stages of the main loop. Kanzi adds the default main loop tasks to the respective stages inside initializeMainLoopTasks().
This diagram shows the overall application control flow. Green items are virtual functions. Gray items are main loop stages. Dotted items are main loop callbacks.
|
explicit |
Constructs the application object.
|
override |
Destructs the application object.
void kanzi::Application::initialize | ( | const SystemProperties & | systemProperties | ) |
Initializes the application to a consistent state.
After constructing the application, this is the first function that the application framework calls. This function tries to read the file application.cfg. Do not call this function before the file system of the operating system has been initialized.
To change the default behavior, override initializeOverride().
systemProperties | Command line parameters of the program. |
void kanzi::Application::initializeGL | ( | ) |
Initializes the graphics language subsystem.
The application framework calls this function before entering the program main loop, but after the application framework activates a GL context. It initializes OpenGL-related subsystems.
To change the default behavior, override initializeGLOverride().
void kanzi::Application::resumeGL | ( | ) |
Resumes the graphics language subsystem.
If you call suspendGL() during suspension, the application framework calls this function during application resume. This function deploys GPU resources that were undeployed during suspendGL().
To change the default behavior, override resumeGLOverride().
void kanzi::Application::main | ( | const SystemProperties & | systemProperties | ) |
Application entry point.
This high-level function implements the default initialization and the main loop. The application framework calls this function, except on callbacks-only systems.
To change the default behavior, override mainOverride().
systemProperties | Command line parameters of the program. |
void kanzi::Application::uninitialize | ( | ) |
Uninitializes the application.
This is the last function that the application framework calls before destruction.
To change the default behavior, override uninitializeOverride().
void kanzi::Application::uninitializeGL | ( | ) |
Uninitializes the graphics language subsystem.
The application framework calls this function after exiting the program main loop, but before it deactivates a GL context. It undeploys all GPU resources.
To change the default behavior, override uninitializeGLOverride().
void kanzi::Application::suspendGL | ( | ) |
Suspends the graphics language subsystem.
The application framework calls this function 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.
To change the default behavior, override suspendGLOverride().
void kanzi::Application::pause | ( | ) |
Puts the application from the Running state to the Paused state.
void kanzi::Application::resume | ( | ) |
Resumes the application from the Paused state to the Running state.
void kanzi::Application::quit | ( | ) |
Quits the application.
Domain* kanzi::Application::getDomain | ( | ) | const |
Access domain.
Renderer3D* kanzi::Application::getRenderer3D | ( | ) | const |
Access the renderer.
Node2DSharedPtr kanzi::Application::getRoot | ( | ) | const |
Access the root node.
ScreenSharedPtr kanzi::Application::getScreen | ( | ) | const |
void kanzi::Application::setScreen | ( | ScreenSharedPtr | screen | ) |
const MainLoopScheduler& kanzi::Application::getMainLoopScheduler | ( | ) | const |
Access the associated MainLoopScheduler.
MainLoopScheduler& kanzi::Application::getMainLoopScheduler | ( | ) |
Access the associated MainLoopScheduler.
ResourceManager* kanzi::Application::getResourceManager | ( | ) | const |
Access resource manager.
InputManager* kanzi::Application::getInputManager | ( | ) | const |
Access input manager.
detail::MessageDispatcher* kanzi::Application::getMessageDispatcher | ( | ) | const |
Access message dispatcher.
float kanzi::Application::getFramesPerSecond | ( | ) | const |
Access framerate information.
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. |
|
inline |
Query graphics output interfaces.
Interface | Interface of the graphics output to query. |
index | Index of the graphics output to query. |
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 to domain and register its event handle with main loop scheduler.
To attach event source to domain without registering event handle, use Domain::appendEventSource(). To register event handle with main loop scheduler without attaching to domain, use MainLoopScheduler::setInputEventHandle().
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. |
MainLoopState kanzi::Application::getState | ( | ) | const |
Access application state.
ApplicationProperties kanzi::Application::getApplicationProperties | ( | ) | const |
Access application properties.
|
inline |
Gets the Performance HUD information level.
If the Performance HUD information level is not ApplicationProperties::PerformanceInfoLevelDisabled, Kanzi draws the Performance HUD after calling onPostRender().
|
inline |
Sets the Performance HUD information level.
This is equal to the application configuration ApplicationProperties::PerformanceInfoLevel option.
level | - To turn off the Performance HUD, use ApplicationProperties::PerformanceInfoLevelDisabled (0). The default value.
|
void kanzi::Application::loadFontEngine | ( | ApplicationProperties::FontEngine | fontEngine | ) |
Loads the font engine for the font manager.
fontEngine | The font engine that the font manager uses. |
|
inline |
Sets or resets the flag that allows indefinite sleep.
enabled | - To enable indefinite sleep, set to true.
|
void kanzi::Application::patchProject | ( | uintmax_t | byteCount, |
const byte * | bytes | ||
) |
Applies a Kanzi Studio Preview patch.
Kanzi Studio Preview uses this function internally.
byteCount | Size of kzb file. |
bytes | Pointer to the contents of the kzb file. |
|
protectedvirtual |
Loads the application properties, based on configuration file and command-line arguments.
systemProperties | Command line parameters of the program. |
|
protectedvirtual |
Initializes profiling, event sources, and graphics output.
|
protectedvirtual |
Initializes Kanzi Domain and loads a kzb file.
|
inlineprotectedvirtual |
Attaches the default tasks to the main loop scheduler.
|
protected |
Applies the frame limit and idle-suspension configurations from the application properties to the main loop scheduler, and attaches event handles and preconditions.
|
protected |
Clears the event queue.
|
protected |
Gathers all input events into the event queue.
|
protected |
Executes the application-defined event handler on all events in the event queue.
|
protectedvirtual |
Executes the application-defined event handler on all events in the event queue.
eventQueue | Reference to the event queue for user input and window events. |
|
protected |
Executes the graphics subsystem event handler.
|
protected |
Executes the input subsystem event handler.
|
protected |
Loads the kzb file that is specified by KzuEngine::m_newBinaryName.
Instantiates and attaches the startup Screen node from the loaded kzb file. If a startup kzb file is not set, or the startup Screen node is not set, creates the default Screen node. Kanzi calls this function automatically at application startup.
|
protected |
Processes the deployment queue for asynchronous loading tasks.
By default this function processes every frame a single item from the deployment queue of background loading tasks.
To change the default behavior, override progressDeploymentQueueOverride().
|
protected |
Advances renderer clock with time delta, and attaches active graphics output to it.
deltaTime | Time in nanoseconds elapsed since the previous frame. |
|
protected |
Sets the rendering area on the graphics output based on the size, orientation, and metrics.
|
protected |
Lays out the node tree.
|
protected |
Extracts the node tree.
|
protected |
Ticks all the active animations.
deltaTime | Time in nanoseconds since the previous frame. |
|
protectedvirtual |
Renders the node tree.
|
protected |
Renders the Performance HUD.
|
protected |
Clears all render buffers.
|
protected |
Updates the graphics output buffer with the rendered node tree.
|
protectedvirtual |
Callback for the startup logic.
Kanzi calls this function immediately after the application initialization.
|
protectedvirtual |
Callback for the shutdown logic.
Kanzi calls this function immediately before the application un-initialization.
|
protectedvirtual |
Callback for configuring the application properties.
Kanzi calls this callback before it reads the application.cfg and before it initializes the graphics subsystem.
configuration | Allows modification of the application properties. |
Reimplemented in kanzi::ExampleApplication.
|
protectedvirtual |
Callback for initializations that use data from a kzb file.
Kanzi calls this function right after it loads a kzb file.
|
protectedvirtual |
Callback for the update logic.
Kanzi calls this function every frame in the User stage of the main loop.
deltaTime | Time in nanoseconds elapsed since the previous frame. |
|
protectedvirtual |
Callback for handling of input events from a pointing device, such as a mouse or touch screen.
Kanzi calls this function inside the Input stage of the main loop.
pointerEvent | Reference to the event. |
|
protectedvirtual |
Callback for handling input events from keyboard.
Kanzi calls this function inside the Input stage of the main loop.
keyEvent | Reference to the event. |
Reimplemented in kanzi::ExampleApplication.
|
protectedvirtual |
Callback for determining the duration of suspension in a main loop frame.
Kanzi calls this function when the main loop decides to enter suspension.
remainingFrameAllotment | Time remaining in the current frame based on the configured frame limit and time elapsed since its start. |
|
protectedvirtual |
Kanzi calls this callback when the application main loop enters the Paused state.
|
protectedvirtual |
Kanzi calls this callback when the application main loop returns from the Paused to the Running state.
|
protectedvirtual |
Kanzi calls this callback for the event handling logic when the application main loop is in the Paused state.
|
protectedvirtual |
|
protectedvirtual |
Override function for initialize().
systemProperties | Command line parameters of the program. |
|
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 progressDeploymentQueue().
|
protected |
Logs startup profiling data.
|
inlineprotected |
Gets the startup profiler registry.
|
inlineprotectedvirtual |
Indicates whether application is running in the Kanzi Studio Preview.
|
protected |
Log graphics information based on application properties.
|
protected |
Access Kanzi Engine.
|
protected |
Acquire performance information object.
If performance information object does not exist, this function creates it.
|
friend |
|
protected |
The event queue for user input and window events.
|
protected |
Container of command line parameters of the program.
|
protected |
Application properties.
|
protected |
Kanzi Engine instance.
|
protected |
Performance HUD information.
|
protected |
Flag to be set when project has been loaded.
|
protected |
Main loop scheduler.