ezEngine  Release 25.03
ezApplication Class Referenceabstract

Base class to be used by applications based on ezEngine. More...

#include <Application.h>

Inheritance diagram for ezApplication:

Public Member Functions

 ezApplication (ezStringView sAppName)
 Constructor.
 
virtual ~ezApplication ()
 Virtual destructor.
 
void SetApplicationName (ezStringView sAppName)
 Changes the application name.
 
const ezStringGetApplicationName () const
 Returns the application name.
 
virtual ezResult BeforeCoreSystemsStartup ()
 This function is called before any kind of engine initialization is done. More...
 
virtual void AfterCoreSystemsStartup ()
 This function is called after basic engine initialization has been done. More...
 
virtual void BeforeHighLevelSystemsShutdown ()
 This function is called after the application main loop has run for the last time, before engine deinitialization. More...
 
virtual void AfterHighLevelSystemsShutdown ()
 Called after ezStartup::ShutdownHighLevelSystems() has been executed.
 
virtual void BeforeCoreSystemsShutdown ()
 This function is called after the application main loop has run for the last time, before engine deinitialization. More...
 
virtual void AfterCoreSystemsShutdown ()
 This function is called after ezStartup::ShutdownCoreSystems() has been called. More...
 
virtual void BeforeEnterBackground ()
 This function is called when an application is moved to the background. More...
 
virtual void BeforeEnterForeground ()
 This function is called whenever an application is resumed from background mode. More...
 
virtual void Run ()=0
 Main run function which is called periodically. This function must be overridden. More...
 
void SetReturnCode (ezInt32 iReturnCode)
 Sets the value that the application will return to the OS. You can call this function at any point during execution to update the return value of the application. Default is zero.
 
ezInt32 GetReturnCode () const
 Returns the currently set value that the application will return to the OS.
 
virtual const char * TranslateReturnCode () const
 If the return code is not zero, this function might be called to get a string to print the error code in human readable form.
 
void SetCommandLineArguments (ezUInt32 uiArgumentCount, const char **pArguments)
 Will set the command line arguments that were passed to the app by the OS. This is automatically called by EZ_APPLICATION_ENTRY_POINT().
 
ezUInt32 GetArgumentCount () const
 Returns the number of command line arguments that were passed to the application. More...
 
const char * GetArgument (ezUInt32 uiArgument) const
 Returns one of the command line arguments that was passed to the application.
 
const char ** GetArgumentsArray () const
 Returns the complete array of command line arguments that were passed to the application.
 
void EnableMemoryLeakReporting (bool bEnable)
 
bool IsMemoryLeakReportingEnabled () const
 
virtual void RequestApplicationQuit ()
 Calling this function requests that the application quits after the current invocation of Run() finishes. More...
 
EZ_ALWAYS_INLINE bool ShouldApplicationQuit () const
 Returns whether RequestQuit() was called.
 

Static Public Member Functions

static ezApplicationGetApplicationInstance ()
 Returns the one instance of ezApplication that is available.
 

Protected Attributes

bool m_bWasQuitRequested = false
 

Friends

EZ_FOUNDATION_DLL_FRIEND void ezRun (ezApplication *pApplicationInstance)
 Platform independent run function for main loop based systems (e.g. Win32, ..) More...
 
EZ_FOUNDATION_DLL_FRIEND ezResult ezRun_Startup (ezApplication *pApplicationInstance)
 [internal] Called by ezRun()
 
EZ_FOUNDATION_DLL_FRIEND void ezRun_MainLoop (ezApplication *pApplicationInstance)
 [internal] Called by ezRun()
 
EZ_FOUNDATION_DLL_FRIEND void ezRun_Shutdown (ezApplication *pApplicationInstance)
 [internal] Called by ezRun()
 

Detailed Description

Base class to be used by applications based on ezEngine.

The platform abstraction layer will ensure that the correct functions are called independent of the basic main loop structure (traditional or event-based). Derive an application specific class from ezApplication and implement at least the abstract Run() function. Additional virtual functions allow to hook into specific events to run application specific code at the correct times.

Finally pass the name of your derived class to the macro EZ_APPLICATION_ENTRY_POINT(). Those are used to abstract away the platform specific code to run an application.

A simple example how to get started is as follows:

class ezSampleApp : public ezApplication
{
public:
virtual void AfterCoreSystemsStartup() override
{
// Setup Filesystem, Logging, etc.
}
virtual void BeforeCoreSystemsShutdown() override
{
// Close log file, etc.
}
virtual void Run() override
{
// Run will be called repeatedly, until RequestApplicationQuit() has been called (at any time in the frame).
}
};
EZ_APPLICATION_ENTRY_POINT(ezSampleApp);

Member Function Documentation

◆ AfterCoreSystemsShutdown()

virtual void ezApplication::AfterCoreSystemsShutdown ( )
inlinevirtual

This function is called after ezStartup::ShutdownCoreSystems() has been called.

It is unlikely that there is any kind of deinitialization left, that can still be run at this point.

◆ AfterCoreSystemsStartup()

virtual void ezApplication::AfterCoreSystemsStartup ( )
inlinevirtual

This function is called after basic engine initialization has been done.

ezApplication will automatically call ezStartup::StartupCoreSystems() to initialize the application. This function can be overridden to do additional application specific initialization. To startup entire subsystems, you should however use the features provided by ezStartup and ezSubSystem.

Reimplemented in ezGameApplicationBase, ezTexConv, ezFileserverApp, ezEngineProcessGameApplication, ezShaderCompilerApplication, and ezPlayerApplication.

◆ BeforeCoreSystemsShutdown()

virtual void ezApplication::BeforeCoreSystemsShutdown ( )
inlinevirtual

This function is called after the application main loop has run for the last time, before engine deinitialization.

Override this function to do application specific deinitialization that still requires a running engine. After this function returns ezStartup::ShutdownCoreSystems() is called and thus everything, including allocators, is shut down. To shut down entire subsystems, you should, however, use the features provided by ezStartup and ezSubSystem.

Reimplemented in ezGameApplicationBase, ezTexConv, ezFileserverApp, and ezEngineProcessGameApplication.

◆ BeforeCoreSystemsStartup()

ezResult ezApplication::BeforeCoreSystemsStartup ( )
virtual

This function is called before any kind of engine initialization is done.

Override this function to be able to configure subsystems, before they are initialized. After this function returns, ezStartup::StartupCoreSystems() is automatically called. If you need to set up custom allocators, this is the place to do this.

Reimplemented in ezGameApplicationBase, ezTexConv, ezFileserverApp, ezEngineProcessGameApplication, ezShaderCompilerApplication, and ezPlayerApplication.

◆ BeforeEnterBackground()

virtual void ezApplication::BeforeEnterBackground ( )
inlinevirtual

This function is called when an application is moved to the background.

On Windows that might simply mean that the main window lost the focus. On other devices this might mean that the application is not visible at all anymore and might even get shut down later. Override this function to be able to put the application into a proper sleep mode.

◆ BeforeEnterForeground()

virtual void ezApplication::BeforeEnterForeground ( )
inlinevirtual

This function is called whenever an application is resumed from background mode.

On Windows that might simply mean that the main window received focus again. On other devices this might mean that the application was suspended and is now active again. Override this function to reload the apps state or other resources, etc.

◆ BeforeHighLevelSystemsShutdown()

virtual void ezApplication::BeforeHighLevelSystemsShutdown ( )
inlinevirtual

This function is called after the application main loop has run for the last time, before engine deinitialization.

After this function call, ezApplication executes ezStartup::ShutdownHighLevelSystems().

Note
ezApplication does NOT call ezStartup::StartupHighLevelSystems() as it may be a window-less application. This is left to ezGameApplicationBase to do. However, it does make sure to shut down the high-level systems, in case they were started.

Reimplemented in ezGameApplicationBase.

◆ GetArgumentCount()

ezUInt32 ezApplication::GetArgumentCount ( ) const
inline

Returns the number of command line arguments that were passed to the application.

Note that the very first command line argument is typically the path to the application itself.

◆ RequestApplicationQuit()

void ezApplication::RequestApplicationQuit ( )
virtual

Calling this function requests that the application quits after the current invocation of Run() finishes.

Sets the m_bWasQuitRequested to true as an indicator for derived application objects to engage shutdown procedures. Can be overridden to implement custom behavior. There is no other logic associated with this function and flag so the respective derived application class has to implement logic to perform the actual quit when this function is called or m_bWasQuitRequested is set to true.

◆ Run()

virtual void ezApplication::Run ( )
pure virtual

Main run function which is called periodically. This function must be overridden.

Call RequestApplicationQuit() at any point to prevent Run() from being called again.

Implemented in ezGameApplicationBase, ezTexConv, ezFileserverApp, ezEngineProcessGameApplication, and ezShaderCompilerApplication.

Friends And Related Function Documentation

◆ ezRun

EZ_FOUNDATION_DLL_FRIEND void ezRun ( ezApplication pApplicationInstance)
friend

Platform independent run function for main loop based systems (e.g. Win32, ..)

This is automatically called by EZ_APPLICATION_ENTRY_POINT().

ezRun simply calls ezRun_Startup(), ezRun_MainLoop() and ezRun_Shutdown().


The documentation for this class was generated from the following files:
ezApplication::RequestApplicationQuit
virtual void RequestApplicationQuit()
Calling this function requests that the application quits after the current invocation of Run() finis...
Definition: Application.cpp:67
ezApplication
Base class to be used by applications based on ezEngine.
Definition: Application.h:64
ezApplication::Run
virtual void Run()=0
Main run function which is called periodically. This function must be overridden.
ezApplication::AfterCoreSystemsStartup
virtual void AfterCoreSystemsStartup()
This function is called after basic engine initialization has been done.
Definition: Application.h:93
ezApplication::BeforeCoreSystemsShutdown
virtual void BeforeCoreSystemsShutdown()
This function is called after the application main loop has run for the last time,...
Definition: Application.h:112