XII Release 0.1.0
Loading...
Searching...
No Matches
xiiGameApplication Class Reference

The base class for all typical game applications made with xiiEngine. More...

#include <GameApplication.h>

Inheritance diagram for xiiGameApplication:
[legend]

Public Types

using SUPER = xiiGameApplicationBase
 
- Public Types inherited from xiiGameApplicationBase
using SUPER = xiiApplication
 
- Public Types inherited from xiiApplication
enum class  Execution { Continue , Quit }
 Defines the possible return values for the xiiApplication::Run() function. More...
 

Public Member Functions

 xiiGameApplication (xiiStringView sAppName, xiiStringView sProjectPath={})
 sProjectPath may be empty, if FindProjectDirectory() is overridden.
 
virtual xiiString FindProjectDirectory () const override
 Implementation of xiiGameApplicationBase::FindProjectDirectory to define the 'project' special data directory.
 
void ReinitializeInputConfig ()
 Used at runtime (by the editor) to reload input maps. Forwards to Init_ConfigureInput()
 
xiiStringView GetAppProjectPath () const
 Returns the project path that was given to the constructor (or modified by an overridden implementation).
 
- Public Member Functions inherited from xiiGameApplicationBase
 xiiGameApplicationBase (xiiStringView sAppName)
 
void TakeProfilingCapture ()
 Does a profiling capture and writes it to disk at ':appdata'.
 
void TakeScreenshot ()
 Schedules a screenshot to be taken at the end of the frame.
 
void CaptureFrame ()
 Schedules a frame capture if the corresponding plugin is loaded.
 
void SetContinuousFrameCapture (bool bEnable)
 Controls if frame captures are taken continuously (without being persisted) or only on-demand.
 
bool GetContinousFrameCapture () const
 
virtual xiiResult GetAbsFrameCaptureOutputPath (xiiStringBuilder &ref_sOutputPath)
 Get the absolute base output path for frame captures.
 
void ActivateGameState (xiiWorld *pWorld, xiiStringView sStartPosition, const xiiTransform &startPositionOffset)
 Creates and activates the game state for this application.
 
void DeactivateGameState ()
 Deactivates and destroys the active game state.
 
xiiGameStateBaseGetActiveGameState () const
 Returns the currently active game state. Could be nullptr.
 
const xiiPlatformProfileGetPlatformProfile () const
 Returns the xiiPlatformProfile that has been loaded for this application.
 
virtual xiiApplication::Execution Run () override
 Main run function which is called periodically. This function must be overridden.
 
void RunOneFrame ()
 
xiiTime GetFrameTime () const
 
- Public Member Functions inherited from xiiApplication
 xiiApplication (xiiStringView sAppName)
 Constructor.
 
virtual ~xiiApplication ()
 Virtual destructor.
 
void SetApplicationName (xiiStringView sAppName)
 Changes the application name.
 
const xiiStringGetApplicationName () const
 Returns the application name.
 
virtual void AfterHighLevelSystemsShutdown ()
 Called after xiiStartup::ShutdownHighLevelSystems() has been executed.
 
virtual void AfterCoreSystemsShutdown ()
 This function is called after xiiStartup::ShutdownCoreSystems() has been called.
 
virtual void BeforeEnterBackground ()
 This function is called when an application is moved to the background.
 
virtual void BeforeEnterForeground ()
 This function is called whenever an application is resumed from background mode.
 
void SetReturnCode (xiiInt32 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.
 
xiiInt32 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 (xiiUInt32 uiArgumentCount, const char **pArguments)
 Will set the command line arguments that were passed to the app by the OS. This is automatically called by XII_APPLICATION_ENTRY_POINT() and XII_CONSOLEAPP_ENTRY_POINT().
 
xiiUInt32 GetArgumentCount () const
 Returns the number of command line arguments that were passed to the application.
 
const char * GetArgument (xiiUInt32 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 RequestQuit ()
 Calling this function requests that the application quits after the current invocation of Run() finishes.
 
XII_ALWAYS_INLINE bool WasQuitRequested () const
 Returns whether RequestQuit() was called.
 

Static Public Member Functions

static xiiGameApplicationGetGameApplicationInstance ()
 Returns the xiiGameApplication singleton.
 
static xiiStringView GetActiveRenderer ()
 Returns the active renderer of the current app. Either the default or overridden via -render command line flag.
 
static void SetOverrideDefaultDeviceCreator (xiiDelegate< xiiSharedPtr< xiiGALDevice >(const xiiGALDeviceCreationDescription &)> creator)
 When the graphics device is created, by default the game application will pick a platform specific implementation. This function allows to override that by setting a custom function that creates a graphics device.
 
static xiiGameApplicationBaseGetGameApplicationBaseInstance ()
 Returns the xiiGameApplicationBase singleton.
 
- Static Public Member Functions inherited from xiiApplication
static xiiApplicationGetApplicationInstance ()
 Returns the one instance of xiiApplication that is available.
 

Static Public Attributes

static xiiCVarBool cvar_AppVSync
 
static xiiCVarBool cvar_AppShowFPS
 

Protected Member Functions

virtual void Init_ConfigureInput () override
 
virtual void Init_ConfigureAssetManagement () override
 
virtual void Init_LoadRequiredPlugins () override
 
virtual void Init_SetupDefaultResources () override
 
virtual void Init_SetupGraphicsDevice () override
 
virtual void Deinit_ShutdownGraphicsDevice () override
 
virtual bool IsGameUpdateEnabled () const override
 
virtual bool Run_ProcessApplicationInput () override
 
virtual void Run_AcquireImage () override
 This function can be used to acquire a new window from a swap-chain or do any other update operations on windows before the multi-threaded rendering and update phase starts.
 
virtual void Run_WorldUpdateAndRender () override
 
virtual void Run_PresentImage () override
 This function can be used to present the final image to a window. It is run at the end of the rendering phase. It can also be used to inspect the swap-chain e.g. for screenshot purposes before presenting.
 
virtual void Run_FinishFrame () override
 
void RenderFps ()
 
void RenderConsole ()
 
void UpdateWorldsAndExtractViews ()
 
- Protected Member Functions inherited from xiiGameApplicationBase
virtual void BeforeHighLevelSystemsShutdown () override
 This function is called after the application main loop has run for the last time, before engine deinitialization.
 
virtual void BeforeCoreSystemsShutdown () override
 This function is called after the application main loop has run for the last time, before engine deinitialization.
 
virtual void Deinit_UnloadPlugins ()
 
virtual void Deinit_ShutdownLogging ()
 
virtual void StoreScreenshot (xiiImage &&image, xiiStringView sContext={})
 Called with the result from taking a screenshot. The default implementation writes the image to disk at ':appdata/Screenshots'.
 
void ExecuteTakeScreenshot (xiiWindowOutputTargetBase *pOutputTarget, xiiStringView sContext={})
 
void ExecuteFrameCapture (xiiWindowHandle targetWindowHandle, xiiStringView sContext={})
 
virtual xiiUniquePtr< xiiGameStateBaseCreateGameState ()
 Creates a game state for the application to use.
 
virtual void ActivateGameStateAtStartup ()
 Allows to override whether a game state is created and activated at application startup.
 
virtual xiiResult BeforeCoreSystemsStartup () override
 This function is called before any kind of engine initialization is done.
 
virtual void AfterCoreSystemsStartup () override
 This function is called after basic engine initialization has been done.
 
virtual xiiString GetBaseDataDirectoryPath () const
 Returns the target of the 'base' data directory.
 
virtual xiiString GetProjectDataDirectoryPath () const
 Returns the target of the 'project' data directory.
 
virtual void ExecuteBaseInitFunctions ()
 Executes all 'BaseInit_' functions. Typically done very early, before core system startup.
 
virtual void BaseInit_ConfigureLogging ()
 
virtual void ExecuteInitFunctions ()
 Executes all 'Init_' functions. Typically done after core system startup.
 
virtual void Init_PlatformProfile_SetPreferred ()
 
virtual void Init_ConfigureTelemetry ()
 
virtual void Init_FileSystem_SetSpecialDirs ()
 
virtual void Init_FileSystem_ConfigureDataDirs ()
 
virtual void Init_LoadWorldModuleConfig ()
 
virtual void Init_LoadProjectPlugins ()
 
virtual void Init_PlatformProfile_LoadForRuntime ()
 
virtual void Init_ConfigureTags ()
 
virtual void Init_ConfigureCVars ()
 
virtual void Run_InputUpdate ()
 
virtual void Run_BeforeWorldUpdate ()
 
virtual void Run_AfterWorldUpdate ()
 
virtual void Run_UpdatePlugins ()
 
void UpdateFrameTime ()
 

Protected Attributes

xiiString m_sAppProjectPath
 Stores what is given to the constructor.
 
bool m_bIgnoreErrors = false
 
xiiSharedPtr< xiiDelegateTask< void > > m_pUpdateTask
 
bool m_bShowConsole = false
 
xiiUniquePtr< xiiQuakeConsolem_pConsole
 
bool m_bTakeScreenshot = false
 
xiiConsoleFunction< void()> m_ConFunc_TakeScreenshot
 expose TakeScreenshot() as a console function
 
bool m_bContinuousFrameCapture = false
 
bool m_bCaptureFrame = false
 
xiiConsoleFunction< void()> m_ConFunc_CaptureFrame
 expose CaptureFrame() as a console function
 
xiiUniquePtr< xiiGameStateBasem_pGameState
 
xiiPlatformProfile m_PlatformProfile
 
xiiEventSubscriptionID m_LogToConsoleID = 0
 
xiiEventSubscriptionID m_LogToVsID = 0
 
xiiEvent< const xiiGameApplicationStaticEvent & > m_StaticEvents
 
xiiTime m_FrameTime
 
- Protected Attributes inherited from xiiApplication
bool m_bWasQuitRequested = false
 

Static Protected Attributes

static xiiGameApplications_pGameApplicationInstance = nullptr
 
static xiiDelegate< xiiSharedPtr< xiiGALDevice >(const xiiGALDeviceCreationDescription &)> s_DefaultDeviceCreator
 
static xiiGameApplicationBases_pGameApplicationBaseInstance = nullptr
 

Additional Inherited Members

xiiCopyOnBroadcastEvent< const xiiGameApplicationExecutionEvent & > m_ExecutionEvents
 

Detailed Description

The base class for all typical game applications made with xiiEngine.

While xiiApplication is an abstraction for the operating system entry point, xiiGameApplication extends this to implement startup and tear down functionality of a typical game that uses the standard functionality of xiiEngine.

xiiGameApplication implements a lot of functionality needed by most games, such as setting up data directories, loading plugins, configuring the input system, etc.

For every such step a virtual function is called, allowing to override steps in custom applications.

The default implementation tries to do as much of this in a data-driven way. E.g. plugin and data directory configurations are read from DDL files. These can be configured by hand or using xiiEditor.

You are NOT supposed to implement game functionality by deriving from xiiGameApplication. Instead see xiiGameState.

xiiGameApplication will create exactly one xiiGameState by looping over all available xiiGameState types (through reflection) and picking the one whose DeterminePriority function returns the highest priority. That game state will live throughout the entire application life-time and will be stepped every frame.

Member Function Documentation

◆ Deinit_ShutdownGraphicsDevice()

void xiiGameApplication::Deinit_ShutdownGraphicsDevice ( )
overrideprotectedvirtual

◆ FindProjectDirectory()

xiiString xiiGameApplication::FindProjectDirectory ( ) const
overridevirtual

Implementation of xiiGameApplicationBase::FindProjectDirectory to define the 'project' special data directory.

The default implementation will try to resolve m_sAppProjectPath to an absolute path. m_sAppProjectPath can be absolute itself, relative to ">sdk/" or relative to xiiOSFile::GetApplicationDirectory(). m_sAppProjectPath must be set either via the xiiGameApplication constructor or manually set before project.

Alternatively, xiiGameApplication::FindProjectDirectory() must be overwritten.

Implements xiiGameApplicationBase.

Reimplemented in xiiEngineProcessGameApplication.

◆ Init_ConfigureAssetManagement()

void xiiGameApplication::Init_ConfigureAssetManagement ( )
overrideprotectedvirtual

Reimplemented from xiiGameApplicationBase.

◆ Init_ConfigureInput()

void xiiGameApplication::Init_ConfigureInput ( )
overrideprotectedvirtual

Reimplemented from xiiGameApplicationBase.

◆ Init_LoadRequiredPlugins()

void xiiGameApplication::Init_LoadRequiredPlugins ( )
overrideprotectedvirtual

Reimplemented from xiiGameApplicationBase.

◆ Init_SetupDefaultResources()

void xiiGameApplication::Init_SetupDefaultResources ( )
overrideprotectedvirtual
Todo
Loading Cubemap Texture

Reimplemented from xiiGameApplicationBase.

◆ Init_SetupGraphicsDevice()

void xiiGameApplication::Init_SetupGraphicsDevice ( )
overrideprotectedvirtual

◆ IsGameUpdateEnabled()

bool xiiGameApplication::IsGameUpdateEnabled ( ) const
overrideprotectedvirtual

Reimplemented from xiiGameApplicationBase.

◆ Run_AcquireImage()

void xiiGameApplication::Run_AcquireImage ( )
overrideprotectedvirtual

This function can be used to acquire a new window from a swap-chain or do any other update operations on windows before the multi-threaded rendering and update phase starts.

Reimplemented from xiiGameApplicationBase.

◆ Run_FinishFrame()

void xiiGameApplication::Run_FinishFrame ( )
overrideprotectedvirtual

Reimplemented from xiiGameApplicationBase.

◆ Run_PresentImage()

void xiiGameApplication::Run_PresentImage ( )
overrideprotectedvirtual

This function can be used to present the final image to a window. It is run at the end of the rendering phase. It can also be used to inspect the swap-chain e.g. for screenshot purposes before presenting.

Reimplemented from xiiGameApplicationBase.

◆ Run_ProcessApplicationInput()

bool xiiGameApplication::Run_ProcessApplicationInput ( )
overrideprotectedvirtual

Reimplemented from xiiGameApplicationBase.

◆ Run_WorldUpdateAndRender()

void xiiGameApplication::Run_WorldUpdateAndRender ( )
overrideprotectedvirtual

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