Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::EngineKern Class Reference

Owns the engine runtime and provides access to engine subsystems. More...

#include <Engine.h>

Collaboration diagram for Engine::EngineKern:

Public Member Functions

 EngineKern ()
 Creates an uninitialized engine instance.
 ~EngineKern ()
 Destroys the engine object after run() has completed cleanup.
void loadEngineConfig ()
 Loads the engine config and checks whether it exists.
void run (GameModule &module)
 Starts the engine, runs the main loop, then shuts subsystems down.
Assets::RuntimeMaterialLease registerRuntimeMaterial (Asset::MeshPath materialPath, std::unique_ptr< Assets::Material > material)
 Registers a material created at runtime and not loaded from a static asset file.
void unregisterRuntimeMaterial (Assets::MaterialHandle handle)
 Unloads a material previously created with registerRuntimeMaterial().
void setFreezeCulling (bool freeze) const
 Enables or disables renderer culling freeze for debug inspection.
bool isFreezeCulling () const
 Returns whether renderer culling updates are frozen.
double getDeltaTimeSeconds () const
 Returns the duration of the previous frame in seconds.
double getGlobalTimeSeconds () const
 Returns engine simulation time in seconds.
Core::ApplicationContext * getContext () const
 Returns the Vulkan application context.
uint32_t getRenderableSceneObjectCount () const
 Counts ECS entities with static mesh render data.
Rendering::Renderer * getRenderer () const
 Returns the renderer subsystem.
Input::XrInputHandler & getXrInputHandler () const
 Returns the XR input handler.
Input::InputManager * getInputManager () const
 Returns the input action manager.
Input::XrRig & getXrRig () const
 Returns resolved XR rig poses.
Core::TimerManager * getTimerManager () const
 Returns the engine timer manager.
Rendering::Headset * getHeadset () const
 Returns the active XR headset wrapper.
World::WindField & getWindField ()
 Returns mutable wind-field state used by wind-aware components.
const World::WindField & getWindField () const
 Returns read-only wind-field state used by wind-aware components.
Entities::EntityContainer & getPersistentEntities ()
 Returns entities that persist independently of the active scene.
const Entities::EntityContainer & getPersistentEntities () const
 Returns read-only access to entities that persist independently of the active scene.
const std::unique_ptr< Core::SceneManager > & getSceneManager () const
 Returns the scene manager.
template<typename T>
void loadScene ()
 Queues a scene change after the current frame completes.
Physics::CollisionProfileRegistry * getCollisionProfileRegistry () const
 Returns the active collision profile registry.

Private Member Functions

void createInputManager ()
 Manages all kinds of inputs the engine has. Has subclasses for device specific implementations.
void createTimerManager ()
 Creates the manager for timing by seconds. It is not time accurate. Is a minimum threshold where we wait for the time which has passed to be greater than x and then execute event.
void createVulkanDebugMessenger ()
void completeFrameAsync (VkFence graphicsFence, bool presentMirror)
 Runs on background thread: waits for GPU fence, ends XR frame, presents mirror This allows CPU work to overlap with GPU execution of the previous frame.
void createStartupScene () const
 Creates the initial scene the engine loads before an actual level is loaded.
void initVulkan ()
 Initialisation of all vulkan related resources.
void tryCreateApplicationContext ()
 will try to create a window and if there is no openxr runtime detected it will wait 5 seconds and try to find one again
void calculateFrameTime (double &lastFrameTimeMilliseconds)
 Calculates the delta time.
void fixLoadingAssets () const
 When assets have been requested but are not loaded yet the static mesh data is in a limbo where it has no asset yet but a path. This function fixes this issue by checking each frame if the asset is loaded already and if it is it sets it.
void processResourceLoadingPipelines ()
 Collects and processes the pipelines which have finished and dispatches the new steps. Asset loading.
void update (double &gameTime)
 Function which causes all objects to tick.
void updateAudioListener ()
 Pushes the headset pose into the audio engine's HRTF listener each frame.
void captureRenderdocFrame ()
 Captures a frame for render doc if the define RENDERDOC_ENABLED is set.
bool isMirrorViewMinimized () const
 Checks the glfw window attributes if the window is minimized.
void mainLoop ()
 Main engine loop where the rendering and game steps happen.
void cleanup ()
 Cleanup of pointers for vulkan and subsystems.
void initStartupScene ()
void createAssetManager ()
void createPhysicsWorld ()
 PHYSICS.
void destroyPhysicsWorld ()
void createAudioEngine ()
 AUDIO.
void destroyAudioEngine ()

Static Private Member Functions

static void processMirrorWindowEvents ()
 processes glfw window events like key presses or window events
static void physicsFrameUpdate ()
 Steps the physics simulation and synchronizes physics body transforms with the ECS. Called once per frame from update().

Private Attributes

Debugger debugger_
double gameTime_ = 0.0f
double deltaTimeSeconds_ = 0.0
int64_t lastPredictedDisplayTime_ = 0
 Predicted display time of the previous XR frame, used to derive simulation delta time from the runtime's display clock instead of the wall clock.
std::unique_ptr< Core::AssetManager > assetManager_ = nullptr
std::unique_ptr< Core::AssetRegistry > assetRegistry_ = nullptr
GameModule * module_ = nullptr
std::unique_ptr< Input::InputManager > inputManager_
uint64_t frameCounter_ = 0
std::unique_ptr< Core::ApplicationContext > applicationContext_
std::unique_ptr< Rendering::MirrorView > mirrorView_
std::unique_ptr< Rendering::Headset > headset_
std::unique_ptr< Rendering::Renderer > renderer_
std::unique_ptr< Debug::UI::ImGuiManager > imguiManager_
std::future< void > frameCompletionFuture_
std::atomic< bool > previousFrameXrComplete_ {true}
int forceSyncFramesRemaining_ = 0
std::unique_ptr< NamedThreadPool > xrFrameThreadPool_
std::unique_ptr< Core::TimerManager > timerManager_
std::unique_ptr< Core::SceneManager > sceneManager_ = nullptr
std::unique_ptr< Core::PhysicsEngine > physicsEngine_ = nullptr
std::unique_ptr< Physics::CollisionProfileRegistry > collisionProfileRegistry_ = nullptr
std::unique_ptr< Core::AudioEngine > audioEngine_ = nullptr
World::WindField windField_
Entities::EntityContainer persistentEntities_

Detailed Description

Owns the engine runtime and provides access to engine subsystems.

Create one instance in the application entry point, register it with Engine::EngineManager, then call Engine::EngineKern::run() with a game module.

Definition at line 67 of file Engine.h.

Constructor & Destructor Documentation

◆ EngineKern()

Engine::EngineKern::EngineKern ( )

Creates an uninitialized engine instance.

◆ ~EngineKern()

Engine::EngineKern::~EngineKern ( )

Destroys the engine object after run() has completed cleanup.

Member Function Documentation

◆ calculateFrameTime()

void Engine::EngineKern::calculateFrameTime ( double & lastFrameTimeMilliseconds)
private

Calculates the delta time.

Parameters
lastFrameTimeMillisecondshow long did the last frame take to render

◆ captureRenderdocFrame()

void Engine::EngineKern::captureRenderdocFrame ( )
private

Captures a frame for render doc if the define RENDERDOC_ENABLED is set.

◆ cleanup()

void Engine::EngineKern::cleanup ( )
private

Cleanup of pointers for vulkan and subsystems.

◆ completeFrameAsync()

void Engine::EngineKern::completeFrameAsync ( VkFence graphicsFence,
bool presentMirror )
private

Runs on background thread: waits for GPU fence, ends XR frame, presents mirror This allows CPU work to overlap with GPU execution of the previous frame.

Parameters
graphicsFenceThe fence to wait on (from the frame that was just submitted)
presentMirrorWhether to present the mirror view after xrEndFrame

◆ createAssetManager()

void Engine::EngineKern::createAssetManager ( )
private

◆ createAudioEngine()

void Engine::EngineKern::createAudioEngine ( )
private

AUDIO.

◆ createInputManager()

void Engine::EngineKern::createInputManager ( )
private

Manages all kinds of inputs the engine has. Has subclasses for device specific implementations.

◆ createPhysicsWorld()

void Engine::EngineKern::createPhysicsWorld ( )
private

PHYSICS.

◆ createStartupScene()

void Engine::EngineKern::createStartupScene ( ) const
private

Creates the initial scene the engine loads before an actual level is loaded.

◆ createTimerManager()

void Engine::EngineKern::createTimerManager ( )
private

Creates the manager for timing by seconds. It is not time accurate. Is a minimum threshold where we wait for the time which has passed to be greater than x and then execute event.

◆ createVulkanDebugMessenger()

void Engine::EngineKern::createVulkanDebugMessenger ( )
private

◆ destroyAudioEngine()

void Engine::EngineKern::destroyAudioEngine ( )
private

◆ destroyPhysicsWorld()

void Engine::EngineKern::destroyPhysicsWorld ( )
private

◆ fixLoadingAssets()

void Engine::EngineKern::fixLoadingAssets ( ) const
private

When assets have been requested but are not loaded yet the static mesh data is in a limbo where it has no asset yet but a path. This function fixes this issue by checking each frame if the asset is loaded already and if it is it sets it.

◆ getCollisionProfileRegistry()

Physics::CollisionProfileRegistry * Engine::EngineKern::getCollisionProfileRegistry ( ) const
inlinenodiscard

Returns the active collision profile registry.

Returns
Registry owned by the engine, or null before collision profile initialization and after cleanup.

Definition at line 370 of file Engine.h.

References collisionProfileRegistry_.

◆ getContext()

Core::ApplicationContext * Engine::EngineKern::getContext ( ) const
inlinenodiscard

Returns the Vulkan application context.

Returns
Context pointer owned by the engine, or null before Vulkan initialization and after cleanup.

Definition at line 137 of file Engine.h.

References applicationContext_.

◆ getDeltaTimeSeconds()

double Engine::EngineKern::getDeltaTimeSeconds ( ) const
nodiscard

Returns the duration of the previous frame in seconds.

◆ getGlobalTimeSeconds()

double Engine::EngineKern::getGlobalTimeSeconds ( ) const
nodiscard

Returns engine simulation time in seconds.

◆ getHeadset()

Rendering::Headset * Engine::EngineKern::getHeadset ( ) const
inlinenodiscard

Returns the active XR headset wrapper.

Returns
Headset owned by the engine, or null before Vulkan/XR initialization and after cleanup.

Definition at line 206 of file Engine.h.

References headset_.

◆ getInputManager()

Input::InputManager * Engine::EngineKern::getInputManager ( ) const
inlinenodiscard

Returns the input action manager.

Returns
Input manager owned by the engine, or null before input initialization and after cleanup.

Definition at line 188 of file Engine.h.

References inputManager_.

◆ getPersistentEntities() [1/2]

Entities::EntityContainer & Engine::EngineKern::getPersistentEntities ( )
inlinenodiscard

Returns entities that persist independently of the active scene.

Definition at line 221 of file Engine.h.

References persistentEntities_.

◆ getPersistentEntities() [2/2]

const Entities::EntityContainer & Engine::EngineKern::getPersistentEntities ( ) const
inlinenodiscard

Returns read-only access to entities that persist independently of the active scene.

Definition at line 226 of file Engine.h.

References persistentEntities_.

◆ getRenderableSceneObjectCount()

uint32_t Engine::EngineKern::getRenderableSceneObjectCount ( ) const
nodiscard

Counts ECS entities with static mesh render data.

◆ getRenderer()

Rendering::Renderer * Engine::EngineKern::getRenderer ( ) const
nodiscard

Returns the renderer subsystem.

Returns
Renderer pointer owned by the engine, or null before renderer initialization and after cleanup.

◆ getSceneManager()

const std::unique_ptr< Core::SceneManager > & Engine::EngineKern::getSceneManager ( ) const
inlinenodiscard

Returns the scene manager.

Returns
Reference to the owning scene manager pointer. The contained pointer is null before scene initialization and after cleanup.

Definition at line 294 of file Engine.h.

References sceneManager_.

◆ getTimerManager()

Core::TimerManager * Engine::EngineKern::getTimerManager ( ) const
inlinenodiscard

Returns the engine timer manager.

Returns
Timer manager owned by the engine, or null before run() initializes timers and after cleanup.

Definition at line 200 of file Engine.h.

References timerManager_.

◆ getWindField() [1/2]

World::WindField & Engine::EngineKern::getWindField ( )
inlinenodiscard

Returns mutable wind-field state used by wind-aware components.

Definition at line 211 of file Engine.h.

References windField_.

◆ getWindField() [2/2]

const World::WindField & Engine::EngineKern::getWindField ( ) const
inlinenodiscard

Returns read-only wind-field state used by wind-aware components.

Definition at line 216 of file Engine.h.

References windField_.

◆ getXrInputHandler()

Input::XrInputHandler & Engine::EngineKern::getXrInputHandler ( ) const
inlinenodiscard

Returns the XR input handler.

Returns
XR input handler owned by the engine, or null before input initialization and after cleanup.

Definition at line 182 of file Engine.h.

References inputManager_.

◆ getXrRig()

Input::XrRig & Engine::EngineKern::getXrRig ( ) const
inlinenodiscard

Returns resolved XR rig poses.

Returns
XR rig owned by the engine, or null before input initialization and after cleanup.

Definition at line 194 of file Engine.h.

References inputManager_.

◆ initStartupScene()

void Engine::EngineKern::initStartupScene ( )
private

◆ initVulkan()

void Engine::EngineKern::initVulkan ( )
private

Initialisation of all vulkan related resources.

◆ isFreezeCulling()

bool Engine::EngineKern::isFreezeCulling ( ) const
nodiscard

Returns whether renderer culling updates are frozen.

◆ isMirrorViewMinimized()

bool Engine::EngineKern::isMirrorViewMinimized ( ) const
nodiscardprivate

Checks the glfw window attributes if the window is minimized.

Returns
true when the window is minimized

◆ loadEngineConfig()

void Engine::EngineKern::loadEngineConfig ( )

Loads the engine config and checks whether it exists.

◆ loadScene()

template<typename T>
void Engine::EngineKern::loadScene ( )
inline

Queues a scene change after the current frame completes.

Template Parameters
TScene type to construct. Must derive from Engine::Entities::Scene.

Definition at line 362 of file Engine.h.

References sceneManager_.

◆ mainLoop()

void Engine::EngineKern::mainLoop ( )
private

Main engine loop where the rendering and game steps happen.

◆ physicsFrameUpdate()

void Engine::EngineKern::physicsFrameUpdate ( )
staticprivate

Steps the physics simulation and synchronizes physics body transforms with the ECS. Called once per frame from update().

◆ processMirrorWindowEvents()

void Engine::EngineKern::processMirrorWindowEvents ( )
staticprivate

processes glfw window events like key presses or window events

◆ processResourceLoadingPipelines()

void Engine::EngineKern::processResourceLoadingPipelines ( )
private

Collects and processes the pipelines which have finished and dispatches the new steps. Asset loading.

◆ registerRuntimeMaterial()

Assets::RuntimeMaterialLease Engine::EngineKern::registerRuntimeMaterial ( Asset::MeshPath materialPath,
std::unique_ptr< Assets::Material > material )
nodiscard

Registers a material created at runtime and not loaded from a static asset file.

Parameters
materialPathLogical material path used as the registry key.
materialMaterial owned by the registry after this call.
Returns
Handle for the registered material, or an invalid handle when the registry or material is null.

◆ run()

void Engine::EngineKern::run ( GameModule & module)

Starts the engine, runs the main loop, then shuts subsystems down.

Parameters
moduleNon-null game module owned by the caller for the duration of the run.

◆ setFreezeCulling()

void Engine::EngineKern::setFreezeCulling ( bool freeze) const

Enables or disables renderer culling freeze for debug inspection.

Parameters
freezeTrue to keep the current culling result, false to resume normal culling updates.

◆ tryCreateApplicationContext()

void Engine::EngineKern::tryCreateApplicationContext ( )
private

will try to create a window and if there is no openxr runtime detected it will wait 5 seconds and try to find one again

◆ unregisterRuntimeMaterial()

void Engine::EngineKern::unregisterRuntimeMaterial ( Assets::MaterialHandle handle)

Unloads a material previously created with registerRuntimeMaterial().

Parameters
handleRuntime material handle to unload.

◆ update()

void Engine::EngineKern::update ( double & gameTime)
private

Function which causes all objects to tick.

Parameters
gameTimetotal time since the start of the game

◆ updateAudioListener()

void Engine::EngineKern::updateAudioListener ( )
private

Pushes the headset pose into the audio engine's HRTF listener each frame.

Member Data Documentation

◆ applicationContext_

std::unique_ptr<Core::ApplicationContext> Engine::EngineKern::applicationContext_
private

Definition at line 231 of file Engine.h.

Referenced by getContext().

◆ assetManager_

std::unique_ptr<Core::AssetManager> Engine::EngineKern::assetManager_ = nullptr
private

Definition at line 148 of file Engine.h.

◆ assetRegistry_

std::unique_ptr<Core::AssetRegistry> Engine::EngineKern::assetRegistry_ = nullptr
private

Definition at line 149 of file Engine.h.

◆ audioEngine_

std::unique_ptr<Core::AudioEngine> Engine::EngineKern::audioEngine_ = nullptr
private

Definition at line 386 of file Engine.h.

◆ collisionProfileRegistry_

std::unique_ptr<Physics::CollisionProfileRegistry> Engine::EngineKern::collisionProfileRegistry_ = nullptr
private

Definition at line 381 of file Engine.h.

Referenced by getCollisionProfileRegistry().

◆ debugger_

Debugger Engine::EngineKern::debugger_
private

Definition at line 119 of file Engine.h.

◆ deltaTimeSeconds_

double Engine::EngineKern::deltaTimeSeconds_ = 0.0
private

Definition at line 140 of file Engine.h.

◆ forceSyncFramesRemaining_

int Engine::EngineKern::forceSyncFramesRemaining_ = 0
private

Definition at line 247 of file Engine.h.

◆ frameCompletionFuture_

std::future<void> Engine::EngineKern::frameCompletionFuture_
private

Definition at line 239 of file Engine.h.

◆ frameCounter_

uint64_t Engine::EngineKern::frameCounter_ = 0
private

Definition at line 155 of file Engine.h.

◆ gameTime_

double Engine::EngineKern::gameTime_ = 0.0f
private

Definition at line 120 of file Engine.h.

◆ headset_

std::unique_ptr<Rendering::Headset> Engine::EngineKern::headset_
private

Definition at line 233 of file Engine.h.

Referenced by getHeadset().

◆ imguiManager_

std::unique_ptr<Debug::UI::ImGuiManager> Engine::EngineKern::imguiManager_
private

Definition at line 235 of file Engine.h.

◆ inputManager_

std::unique_ptr<Input::InputManager> Engine::EngineKern::inputManager_
private

Definition at line 154 of file Engine.h.

Referenced by getInputManager(), getXrInputHandler(), and getXrRig().

◆ lastPredictedDisplayTime_

int64_t Engine::EngineKern::lastPredictedDisplayTime_ = 0
private

Predicted display time of the previous XR frame, used to derive simulation delta time from the runtime's display clock instead of the wall clock.

Definition at line 146 of file Engine.h.

◆ mirrorView_

std::unique_ptr<Rendering::MirrorView> Engine::EngineKern::mirrorView_
private

Definition at line 232 of file Engine.h.

◆ module_

GameModule* Engine::EngineKern::module_ = nullptr
private

Definition at line 152 of file Engine.h.

◆ persistentEntities_

Entities::EntityContainer Engine::EngineKern::persistentEntities_
private

Definition at line 389 of file Engine.h.

Referenced by getPersistentEntities(), and getPersistentEntities().

◆ physicsEngine_

std::unique_ptr<Core::PhysicsEngine> Engine::EngineKern::physicsEngine_ = nullptr
private

Definition at line 380 of file Engine.h.

◆ previousFrameXrComplete_

std::atomic<bool> Engine::EngineKern::previousFrameXrComplete_ {true}
private

Definition at line 240 of file Engine.h.

◆ renderer_

std::unique_ptr<Rendering::Renderer> Engine::EngineKern::renderer_
private

Definition at line 234 of file Engine.h.

◆ sceneManager_

std::unique_ptr<Core::SceneManager> Engine::EngineKern::sceneManager_ = nullptr
private

Definition at line 373 of file Engine.h.

Referenced by getSceneManager(), and loadScene().

◆ timerManager_

std::unique_ptr<Core::TimerManager> Engine::EngineKern::timerManager_
private

Definition at line 252 of file Engine.h.

Referenced by getTimerManager().

◆ windField_

World::WindField Engine::EngineKern::windField_
private

Definition at line 388 of file Engine.h.

Referenced by getWindField(), and getWindField().

◆ xrFrameThreadPool_

std::unique_ptr<NamedThreadPool> Engine::EngineKern::xrFrameThreadPool_
private

Definition at line 250 of file Engine.h.


The documentation for this class was generated from the following file:
  • /workspace/magerbeton/gl3-vulkan/code/Engine/include/Engine/Core/Engine.h