VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
vex::Engine Class Reference

Class for interaction with engine systems. More...

#include <Engine.hpp>

Inheritance diagram for vex::Engine:
vex::DialogWindow vex::Editor vex::ProjectSelector

Public Member Functions

 Engine (const char *title, int width, int height, GameInfo gInfo)
 Constructor for the Engine class.
virtual bool IsEditor ()
 Returns true if the engine is running in editor mode.
void run (std::function< void()> onUpdateLoop=nullptr)
 Starts and runs the main game loop.
vex::Entity getCamera ()
 Function returning the entity of the camera.
void setResolutionMode (ResolutionMode mode)
 Sets the resolution mode and updates the resolution manager.
void setPaused (bool paused)
 Internal function for handling pausing and resuming the game.
bool isPaused () const
 Function returning the current state of the game.
ResolutionMode getResolutionMode () const
 Returns the current resolution mode.
ResolutionManagergetResolutionManager () const
 returns a pointer to the resolution manager.
void setInputMode (InputMode mode)
 Function allowing for changing input mode at runtime.
InputMode getInputMode () const
 Returns the current input mode.
void setEnvironmentSettings (environment settings)
 Applies new global environment settings (lighting, shading) to the interface.
environment getEnvironmentSettings ()
 Returns the current environment settings.
InterfacegetInterface ()
 Returns Interface, used internally.
std::shared_ptr< VirtualFileSystemgetFileSystem ()
 Returns std::shared_ptr of VirtualFileSystem.
vex::RegistrygetRegistry ()
 Returns a reference to vex::Registry.
PhysicsSystemgetPhysicsSystem ()
 Returns pointer to PhysicsSystem.
SceneManagergetSceneManager ()
 Returns pointer to SceneManager.
std::shared_ptr< VexUIcreateVexUI ()
 Creates and returns a shared pointer to a VexUI instance.
int GetCurrentFrame ()
 Returns current frame number.
void setRenderPhysicsDebug (bool value)
 Function to enable/disable rendering collision shapes.
virtual void setFullscreen (bool enabled, bool exclusive=false)
 Function to enable/disable fullscreen mode. with optional exclusive parameter.
bool isFullscreen ()
 Function to check if fullscreen mode is enabled.
std::vector< std::string > getLastLoadedScenes ()
 Function to get the last loaded scenes.
void prepareScenesForHotReload ()
 Prepares the engine for a hot-reload event.
virtual void processEvent (const SDL_Event &event, float deltaTime)
 Internal virtual function for handling window/keyboard events.
virtual void beginGame ()
 Internal virtual function for handling stuff right at the beginning of the game but after initialization of the engine.
virtual void update (float deltaTime)
 Internal function for handling updates; called every frame before rendering.
virtual void render ()
 Internal function that orchestrates the frame rendering process.
virtual void refreshForObject ()
 Internal virtual function for editor.
void quit ()
 Simply sets m_running to false, Effectivelly soft shuting down the engine.
void WaitForGpu ()
 Waits for the GPU to finish all pending operations.
void setFrameLimit (int fps)
 Sets the target frame rate limit.
int getFrameLimit () const
void setVSync (bool enabled)
 Toggles VSync (Vertical Synchronization).
bool getVSync () const
 Returns the current state of VSync.
float getDeltaTime () const
 Returns the time since last frame.
std::shared_ptr< AudioSystemgetAudioSystem () const
 Returns the audio system.

Static Public Member Functions

static const char * GetBuildHash ()
 returns engine hash generated during build process.
static int GetVersionMajor ()
 Returns the major version of the engine.
static int GetVersionMinor ()
 Returns the minor version of the engine.
static int GetVersionPatch ()
 Returns the patch version of the engine.
static const char * GetVersionString ()
 Returns the version string of the engine.

Protected Member Functions

 Engine (SkipInit)
 Alternative constructor for editor to skip default init code.

Protected Attributes

std::shared_ptr< Windowm_window
std::shared_ptr< VirtualFileSystemm_vfs
std::shared_ptr< AudioSystemm_audioSystem
std::unique_ptr< Interfacem_interface
std::unique_ptr< ResolutionManagerm_resolutionManager
std::unique_ptr< ImGUIWrapperm_imgui
std::unique_ptr< InputSystemm_inputSystem
std::unique_ptr< PhysicsSystemm_physicsSystem
std::unique_ptr< SceneManagerm_sceneManager
vex::Registry m_registry
bool m_running = true
bool m_paused = false
bool m_internally_paused = false
bool m_renderPhysicsDebug = false
int m_frame = 0
int m_targetFps = 0
bool m_vsyncEnabled = false
float m_deltaTime = 0.016f
GameInfo m_gameInfo
std::vector< std::string > lastLoadedScenes

Detailed Description

Class for interaction with engine systems.

Definition at line 47 of file Engine.hpp.

Constructor & Destructor Documentation

◆ Engine() [1/2]

vex::Engine::Engine ( const char * title,
int width,
int height,
GameInfo gInfo )

Constructor for the Engine class.

Initializes the core systems in the following order:

  1. Window creation and ResolutionManager.
  2. Virtual File System (VFS) rooted at the executable directory.
  3. PhysicsSystem.
  4. Vulkan Interface (Renderer) and ImGui wrapper.
  5. InputSystem and SceneManager.
    Note
    Detects Wayland on Linux to enforce software VSync strategies if necessary.
    Parameters
    constchar* title - Title of the game window.
    intwidth - Initial width of the game window.
    intheight - Initial height of the game window.
    GameInfogInfo - Game Info struct containing versioning and metadata.

Definition at line 46 of file Engine.cpp.

◆ ~Engine()

vex::Engine::~Engine ( )

Definition at line 220 of file Engine.cpp.

◆ Engine() [2/2]

vex::Engine::Engine ( SkipInit )
protected

Alternative constructor for editor to skip default init code.

Definition at line 234 of file Engine.cpp.

Member Function Documentation

◆ beginGame()

void vex::Engine::beginGame ( )
virtual

Internal virtual function for handling stuff right at the beginning of the game but after initialization of the engine.

Definition at line 316 of file Engine.cpp.

◆ createVexUI()

std::shared_ptr< VexUI > vex::Engine::createVexUI ( )

Creates and returns a shared pointer to a VexUI instance.

Constructs a VexUI object linked to the current Vulkan context, VFS, and resource manager.

Returns
std::shared_ptr<VexUI> - A ready-to-use UI instance.

Definition at line 110 of file Engine.cpp.

◆ getAudioSystem()

std::shared_ptr< AudioSystem > vex::Engine::getAudioSystem ( ) const
inline

Returns the audio system.

Definition at line 235 of file Engine.hpp.

◆ GetBuildHash()

const char * vex::Engine::GetBuildHash ( )
static

returns engine hash generated during build process.

Definition at line 98 of file Engine.cpp.

◆ getCamera()

vex::Entity vex::Engine::getCamera ( )
inline

Function returning the entity of the camera.

Returns
vex::Entity - Entity of the camera.

Definition at line 93 of file Engine.hpp.

◆ GetCurrentFrame()

int vex::Engine::GetCurrentFrame ( )
inline

Returns current frame number.

Definition at line 161 of file Engine.hpp.

◆ getDeltaTime()

float vex::Engine::getDeltaTime ( ) const
inline

Returns the time since last frame.

Definition at line 232 of file Engine.hpp.

◆ getEnvironmentSettings()

environment vex::Engine::getEnvironmentSettings ( )

Returns the current environment settings.

Returns
environment - Current environment settings.

Definition at line 249 of file Engine.cpp.

◆ getFileSystem()

std::shared_ptr< VirtualFileSystem > vex::Engine::getFileSystem ( )
inline

Returns std::shared_ptr of VirtualFileSystem.

Definition at line 144 of file Engine.hpp.

◆ getFrameLimit()

int vex::Engine::getFrameLimit ( ) const
inline

Definition at line 223 of file Engine.hpp.

◆ getInputMode()

InputMode vex::Engine::getInputMode ( ) const
inline

Returns the current input mode.

Returns
InputMode - Current input mode.

Definition at line 130 of file Engine.hpp.

◆ getInterface()

Interface * vex::Engine::getInterface ( )

Returns Interface, used internally.

Definition at line 106 of file Engine.cpp.

◆ getLastLoadedScenes()

std::vector< std::string > vex::Engine::getLastLoadedScenes ( )
inline

Function to get the last loaded scenes.

Definition at line 176 of file Engine.hpp.

◆ getPhysicsSystem()

PhysicsSystem * vex::Engine::getPhysicsSystem ( )
inline

Returns pointer to PhysicsSystem.

Definition at line 150 of file Engine.hpp.

◆ getRegistry()

vex::Registry & vex::Engine::getRegistry ( )
inline

Returns a reference to vex::Registry.

Definition at line 147 of file Engine.hpp.

◆ getResolutionManager()

ResolutionManager * vex::Engine::getResolutionManager ( ) const
inline

returns a pointer to the resolution manager.

Returns
ResolutionManager* - Pointer to the resolution manager.

Definition at line 122 of file Engine.hpp.

◆ getResolutionMode()

ResolutionMode vex::Engine::getResolutionMode ( ) const
inline

Returns the current resolution mode.

Returns
ResolutionMode - Current resolution mode.

Definition at line 118 of file Engine.hpp.

◆ getSceneManager()

SceneManager * vex::Engine::getSceneManager ( )

Returns pointer to SceneManager.

Definition at line 102 of file Engine.cpp.

◆ GetVersionMajor()

int vex::Engine::GetVersionMajor ( )
static

Returns the major version of the engine.

Definition at line 30 of file Engine.cpp.

◆ GetVersionMinor()

int vex::Engine::GetVersionMinor ( )
static

Returns the minor version of the engine.

Definition at line 34 of file Engine.cpp.

◆ GetVersionPatch()

int vex::Engine::GetVersionPatch ( )
static

Returns the patch version of the engine.

Definition at line 38 of file Engine.cpp.

◆ GetVersionString()

const char * vex::Engine::GetVersionString ( )
static

Returns the version string of the engine.

Definition at line 42 of file Engine.cpp.

◆ getVSync()

bool vex::Engine::getVSync ( ) const

Returns the current state of VSync.

Definition at line 216 of file Engine.cpp.

◆ IsEditor()

virtual bool vex::Engine::IsEditor ( )
inlinevirtual

Returns true if the engine is running in editor mode.

Reimplemented in vex::Editor.

Definition at line 80 of file Engine.hpp.

◆ isFullscreen()

bool vex::Engine::isFullscreen ( )

Function to check if fullscreen mode is enabled.

Definition at line 259 of file Engine.cpp.

◆ isPaused()

bool vex::Engine::isPaused ( ) const
inline

Function returning the current state of the game.

Returns
bool - Whether the game is paused or not.

Definition at line 114 of file Engine.hpp.

◆ prepareScenesForHotReload()

void vex::Engine::prepareScenesForHotReload ( )

Prepares the engine for a hot-reload event.

Snapshots the names of currently loaded scenes into lastLoadedScenes via SceneManager::GetAllSceneNames so they can be restored after the reload.

Definition at line 263 of file Engine.cpp.

◆ processEvent()

void vex::Engine::processEvent ( const SDL_Event & event,
float deltaTime )
virtual

Internal virtual function for handling window/keyboard events.

Delegates processing to the InputSystem.

Parameters
constSDL_Event& event - The SDL event to process.
floatdeltaTime - Time since last frame.

Reimplemented in vex::Editor.

Definition at line 267 of file Engine.cpp.

◆ quit()

void vex::Engine::quit ( )
inline

Simply sets m_running to false, Effectivelly soft shuting down the engine.

Definition at line 213 of file Engine.hpp.

◆ refreshForObject()

virtual void vex::Engine::refreshForObject ( )
inlinevirtual

Internal virtual function for editor.

Reimplemented in vex::Editor.

Definition at line 208 of file Engine.hpp.

◆ render()

void vex::Engine::render ( )
virtual

Internal function that orchestrates the frame rendering process.

  1. Acquires the current render resolution and Camera entity.
  2. Prepares SceneRenderData via the Vulkan Interface.
  3. If m_renderPhysicsDebug is enabled, populates debug lines for wireframe rendering.
  4. Calls Renderer::renderScene followed by UI composition and frame presentation.
    See also
    vex::Renderer
    Exceptions
    std::exception- If frame rendering fails, logging the error before handling.

Reimplemented in vex::DialogWindow, vex::Editor, and vex::ProjectSelector.

Definition at line 317 of file Engine.cpp.

◆ run()

void vex::Engine::run ( std::function< void()> onUpdateLoop = nullptr)

Starts and runs the main game loop.

Handles the lifecycle of the application, including:

  • Event polling (SDL_PollEvent) and dispatching.
  • Frame timing, delta time calculation, and frame limiting (FPS cap).
  • Handling application background/foreground states (SDL_EVENT_WILL_ENTER_BACKGROUND) to pause/resume rendering.
  • Triggering Update and Render cycles.
    Parameters
    std::function<void()>onUpdateLoop - Optional callback function, primarily used for hot-reload logic to inject code into the loop.

Definition at line 114 of file Engine.cpp.

◆ setEnvironmentSettings()

void vex::Engine::setEnvironmentSettings ( environment settings)

Applies new global environment settings (lighting, shading) to the interface.

Parameters
environmentsettings - The new environment configuration struct.

Definition at line 245 of file Engine.cpp.

◆ setFrameLimit()

void vex::Engine::setFrameLimit ( int fps)

Sets the target frame rate limit.

Uses SDL_Delay in the main loop to sleep if the frame completes faster than the target time.

Parameters
intfps - Target FPS. Pass 0 to disable the limit (unlimited FPS).

Definition at line 203 of file Engine.cpp.

◆ setFullscreen()

void vex::Engine::setFullscreen ( bool enabled,
bool exclusive = false )
virtual

Function to enable/disable fullscreen mode. with optional exclusive parameter.

Parameters
boolenabled - True to enable, false to disable.
boolexclusive - True to enable exclusive fullscreen mode, false to disable.

Reimplemented in vex::Editor.

Definition at line 253 of file Engine.cpp.

◆ setInputMode()

void vex::Engine::setInputMode ( InputMode mode)
inline

Function allowing for changing input mode at runtime.

Parameters
InputModemode - Enum storing input modes.

Definition at line 126 of file Engine.hpp.

◆ setPaused()

void vex::Engine::setPaused ( bool paused)
inline

Internal function for handling pausing and resuming the game.

Parameters
boolpaused - Whether the game should be paused or resumed.

Definition at line 110 of file Engine.hpp.

◆ setRenderPhysicsDebug()

void vex::Engine::setRenderPhysicsDebug ( bool value)
inline

Function to enable/disable rendering collision shapes.

Parameters
boolvalue - True to enable, false to disable.

Definition at line 165 of file Engine.hpp.

◆ setResolutionMode()

void vex::Engine::setResolutionMode ( ResolutionMode mode)

Sets the resolution mode and updates the resolution manager.

Parameters
ResolutionModemode - The new resolution mode (e.g., NATIVE, PS1_SHARP).

Definition at line 238 of file Engine.cpp.

◆ setVSync()

void vex::Engine::setVSync ( bool enabled)

Toggles VSync (Vertical Synchronization).

Definition at line 207 of file Engine.cpp.

◆ update()

void vex::Engine::update ( float deltaTime)
virtual

Internal function for handling updates; called every frame before rendering.

Updates the InputSystem, initializes/updates dynamic UiComponents, and steps the SceneManager and PhysicsSystem. Skips scene and physics updates if the engine is paused (m_paused or m_internally_paused).

Parameters
floatdeltaTime - Time elapsed since the last frame in seconds.

Reimplemented in vex::Editor.

Definition at line 271 of file Engine.cpp.

◆ WaitForGpu()

void vex::Engine::WaitForGpu ( )

Waits for the GPU to finish all pending operations.

Essential to call before destroying resources (e.g., during shutdown or scene transitions) to prevent Vulkan validation errors or crashes.

Definition at line 197 of file Engine.cpp.

Member Data Documentation

◆ lastLoadedScenes

std::vector<std::string> vex::Engine::lastLoadedScenes
protected

Definition at line 271 of file Engine.hpp.

◆ m_audioSystem

std::shared_ptr<AudioSystem> vex::Engine::m_audioSystem
protected

Definition at line 244 of file Engine.hpp.

◆ m_deltaTime

float vex::Engine::m_deltaTime = 0.016f
protected

Definition at line 264 of file Engine.hpp.

◆ m_frame

int vex::Engine::m_frame = 0
protected

Definition at line 259 of file Engine.hpp.

◆ m_gameInfo

GameInfo vex::Engine::m_gameInfo
protected

Definition at line 270 of file Engine.hpp.

◆ m_imgui

std::unique_ptr<ImGUIWrapper> vex::Engine::m_imgui
protected

Definition at line 248 of file Engine.hpp.

◆ m_inputSystem

std::unique_ptr<InputSystem> vex::Engine::m_inputSystem
protected

Definition at line 249 of file Engine.hpp.

◆ m_interface

std::unique_ptr<Interface> vex::Engine::m_interface
protected

Definition at line 246 of file Engine.hpp.

◆ m_internally_paused

bool vex::Engine::m_internally_paused = false
protected

Definition at line 257 of file Engine.hpp.

◆ m_paused

bool vex::Engine::m_paused = false
protected

Definition at line 256 of file Engine.hpp.

◆ m_physicsSystem

std::unique_ptr<PhysicsSystem> vex::Engine::m_physicsSystem
protected

Definition at line 250 of file Engine.hpp.

◆ m_registry

vex::Registry vex::Engine::m_registry
protected

Definition at line 253 of file Engine.hpp.

◆ m_renderPhysicsDebug

bool vex::Engine::m_renderPhysicsDebug = false
protected

Definition at line 258 of file Engine.hpp.

◆ m_resolutionManager

std::unique_ptr<ResolutionManager> vex::Engine::m_resolutionManager
protected

Definition at line 247 of file Engine.hpp.

◆ m_running

bool vex::Engine::m_running = true
protected

Definition at line 255 of file Engine.hpp.

◆ m_sceneManager

std::unique_ptr<SceneManager> vex::Engine::m_sceneManager
protected

Definition at line 251 of file Engine.hpp.

◆ m_targetFps

int vex::Engine::m_targetFps = 0
protected

Definition at line 261 of file Engine.hpp.

◆ m_vfs

std::shared_ptr<VirtualFileSystem> vex::Engine::m_vfs
protected

Definition at line 243 of file Engine.hpp.

◆ m_vsyncEnabled

bool vex::Engine::m_vsyncEnabled = false
protected

Definition at line 262 of file Engine.hpp.

◆ m_window

std::shared_ptr<Window> vex::Engine::m_window
protected

Definition at line 242 of file Engine.hpp.


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