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

The main Editor class, inheriting from Engine and providing editor-specific functionality and UI. More...

#include <Editor.hpp>

Inheritance diagram for vex::Editor:
vex::Engine

Classes

struct  CopiedObjectData

Public Member Functions

 Editor (const char *title, int width, int height, GameInfo gInfo, const std::string &projectBinaryPath)
 Constructs the Editor.
void render () override
 Overrides the Engine's render function to inject the Editor UI logic (dockspace, viewport, tools).
void update (float deltaTime) override
 Overrides the Engine's update function to handle editor-specific logic.
void processEvent (const SDL_Event &event, float deltaTime) override
 Overrides the Engine's processEvent function to handle editor-specific events (e.g., gizmo interaction, camera movement).
void setFullscreen (bool enabled, bool exclusive=false) override
 Overrides the Engine's setFullscreen function to disable auto fullscreen by gameModule.
void requestSceneReload (const std::string &scenePath)
 Requests a scene reload with a specific path. The reload is typically executed in the main update loop.
std::string getProjectBinaryPath () const
 Gets the path to the project's binary directory.
AssetBrowsergetAssetBrowser () const
 Gets a pointer to the AssetBrowser instance.
const BrowserIconsGetEditorIcons () const
 Gets the collection of icons used within the editor's UI.
EditorPropertiesgetEditorProperties ()
 Gets a pointer to the mutable editor properties.
ProjectPropertiesgetProjectProperties ()
 Gets a pointer to the mutable project properties.
void HandleMeshDrop (const std::string &filepath, vex::Entity parent=vex::NULL_ENTITY)
 Handles the dropping of a mesh asset.
void OnHotReload ()
 Handler for post-hot-reload operations.
void refreshForObject () override
 Overrides the base Engine function to trigger a frame and refresh.
void ProcessEditorShortcuts ()
 Processes editor shortcuts.
void CopySelectedObject ()
 Copies the selected object to the clipboard.
void PasteObjectToScene ()
 Pastes the object from the clipboard to the scene.
void DuplicateSelectedObject ()
 Duplicates the selected object in the scene.
void DeleteSelectedObject ()
 Deletes the selected object from the scene.
void Undo ()
 Undoes the last action performed in the editor.
void Redo ()
 Redoes the last undone action in the editor.
bool IsEditor () override
 Returns true if the engine is running in editor mode.
void ShowConsole ()
 Shows the debug console.
Public Member Functions inherited from vex::Engine
 Engine (const char *title, int width, int height, GameInfo gInfo)
 Constructor for the Engine class.
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.
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 beginGame ()
 Internal virtual function for handling stuff right at the beginning of the game but after initialization of the engine.
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.

Private Member Functions

void drawEditorLayout (const SceneRenderData &data, glm::uvec2 &outNewResolution)
 Helper to draw the ImGUI dockspace and viewport window for the editor.
void drawGizmo (const glm::vec2 &viewportPos, const glm::vec2 &viewportSize)
 Draws the ImGuizmo for the currently selected object.
void loadAssetIcons ()
 Loads the texture icons used for the Asset Browser and other UI elements.
float raySphereIntersect (const glm::vec3 &rayOrigin, const glm::vec3 &rayDir, const glm::vec3 &sphereCenter, float sphereRadius)
 Performs a ray-sphere intersection test.
float rayTriangleIntersect (const glm::vec3 &rayOrigin, const glm::vec3 &rayDir, const glm::vec3 &v0, const glm::vec3 &v1, const glm::vec3 &v2)
 Performs a ray-triangle intersection test (using the Möller–Trumbore algorithm).
void ExtractObjectByEntity (vex::Entity entity, std::pair< bool, vex::GameObject * > &selectedObject)
 Retrieves the GameObject corresponding to a given entity ID and updates the selected object pair.
void SaveConfig (const EditorProperties &data, const std::string &filename)
 Saves the current EditorProperties configuration to a JSON file.
void LoadConfig (EditorProperties &data, const std::string &filename)
 Loads the EditorProperties configuration from a JSON file.
void SaveProjectConfig (const ProjectProperties &data, const std::string &filename)
 Saves the current ProjectProperties configuration to a JSON file.
void LoadProjectConfig (ProjectProperties &data, const std::string &filename)
 Loads the ProjectProperties configuration from a JSON file.
void PushCommand (ICommand *cmd)
 Pushes a command onto the undo stack and clears the redo stack.

Private Attributes

std::deque< std::unique_ptr< ICommand > > m_undoStack
std::deque< std::unique_ptr< ICommand > > m_redoStack
const size_t MAX_UNDO_STEPS = 50
struct vex::Editor::CopiedObjectData m_clipboard
bool m_gizmoWasUsing = false
glm::vec3 m_gizmoStartPos
glm::vec3 m_gizmoStartRot
glm::vec3 m_gizmoStartScale
bool m_isAssetBrowserFocused = false
glm::uvec2 m_viewportSize = {1280, 720}
std::unique_ptr< EditorCameraObjectm_camera
std::unique_ptr< EditorMenuBarm_editorMenuBar
std::pair< bool, GameObject * > m_selectedObject = {false, nullptr}
std::unique_ptr< AssetBrowserm_assetBrowser
BrowserIcons m_icons
std::string m_pendingSceneToLoad = ""
bool m_waitForGui = true
std::string m_projectBinaryPath
ImGuizmo::OPERATION m_currentGizmoOperation = ImGuizmo::TRANSLATE
ImGuizmo::MODE m_currentGizmoMode = ImGuizmo::WORLD
bool m_useSnap = false
float m_snapValue [3] = { 0.5f, 0.5f, 0.5f }
bool m_isHoveringGizmoUI = false
EditorProperties m_editorProperties
EditorProperties m_SavedEditorProperties
ProjectProperties m_projectProperties
ProjectProperties m_SavedProjectProperties
int m_fps = 0
bool m_refresh = false
bool showConsole = false

Additional Inherited Members

Static Public Member Functions inherited from vex::Engine
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 inherited from vex::Engine
 Engine (SkipInit)
 Alternative constructor for editor to skip default init code.
Protected Attributes inherited from vex::Engine
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

The main Editor class, inheriting from Engine and providing editor-specific functionality and UI.

Definition at line 32 of file Editor.hpp.

Constructor & Destructor Documentation

◆ Editor()

vex::Editor::Editor ( const char * title,
int width,
int height,
GameInfo gInfo,
const std::string & projectBinaryPath )

Constructs the Editor.

Parameters
constchar* title - The title of the editor window.
intwidth - Initial width of the editor window.
intheight - Initial height of the editor window.
GameInfogInfo - Game Info class containing version, name etc.
conststd::string& projectBinaryPath - Path to the project's binary directory.

Definition at line 36 of file Editor.cpp.

◆ ~Editor()

vex::Editor::~Editor ( )
inline

Definition at line 44 of file Editor.hpp.

Member Function Documentation

◆ CopySelectedObject()

void vex::Editor::CopySelectedObject ( )

Copies the selected object to the clipboard.

Definition at line 159 of file Editor.cpp.

◆ DeleteSelectedObject()

void vex::Editor::DeleteSelectedObject ( )

Deletes the selected object from the scene.

Definition at line 199 of file Editor.cpp.

◆ drawEditorLayout()

void vex::Editor::drawEditorLayout ( const SceneRenderData & data,
glm::uvec2 & outNewResolution )
private

Helper to draw the ImGUI dockspace and viewport window for the editor.

Parameters
constSceneRenderData& data - Data required for scene rendering.
glm::uvec2&outNewResolution - Output parameter for the new viewport resolution if it changed.

Definition at line 604 of file Editor.cpp.

◆ drawGizmo()

void vex::Editor::drawGizmo ( const glm::vec2 & viewportPos,
const glm::vec2 & viewportSize )
private

Draws the ImGuizmo for the currently selected object.

Parameters
constglm::vec2& viewportPos - The position of the viewport window.
constglm::vec2& viewportSize - The size of the viewport window.

Definition at line 408 of file Editor.cpp.

◆ DuplicateSelectedObject()

void vex::Editor::DuplicateSelectedObject ( )

Duplicates the selected object in the scene.

Definition at line 194 of file Editor.cpp.

◆ ExtractObjectByEntity()

void vex::Editor::ExtractObjectByEntity ( vex::Entity entity,
std::pair< bool, vex::GameObject * > & selectedObject )
private

Retrieves the GameObject corresponding to a given entity ID and updates the selected object pair.

Parameters
vex::Entityentity - The entity ID to look up.
std::pair<bool,vex::GameObject*>&selectedObject - The pair to update with the selection status and pointer.

Definition at line 560 of file Editor.cpp.

◆ getAssetBrowser()

AssetBrowser * vex::Editor::getAssetBrowser ( ) const
inline

Gets a pointer to the AssetBrowser instance.

Returns
AssetBrowser* - Pointer to the AssetBrowser.

Definition at line 71 of file Editor.hpp.

◆ GetEditorIcons()

const BrowserIcons & vex::Editor::GetEditorIcons ( ) const
inline

Gets the collection of icons used within the editor's UI.

Returns
const BrowserIcons& - Reference to the icon collection.

Definition at line 75 of file Editor.hpp.

◆ getEditorProperties()

EditorProperties * vex::Editor::getEditorProperties ( )
inline

Gets a pointer to the mutable editor properties.

Returns
EditorProperties* - Pointer to the editor properties structure.

Definition at line 79 of file Editor.hpp.

◆ getProjectBinaryPath()

std::string vex::Editor::getProjectBinaryPath ( ) const
inline

Gets the path to the project's binary directory.

Returns
std::string - The project binary path.

Definition at line 67 of file Editor.hpp.

◆ getProjectProperties()

ProjectProperties * vex::Editor::getProjectProperties ( )
inline

Gets a pointer to the mutable project properties.

Returns
ProjectProperties* - Pointer to the project properties structure.

Definition at line 83 of file Editor.hpp.

◆ HandleMeshDrop()

void vex::Editor::HandleMeshDrop ( const std::string & filepath,
vex::Entity parent = vex::NULL_ENTITY )

Handles the dropping of a mesh asset.

Parameters
conststd::string& filepath - Path to the dropped mesh asset.
vex::Entityparent - Optional parent entity for the instantiated mesh.

Definition at line 572 of file Editor.cpp.

◆ IsEditor()

bool vex::Editor::IsEditor ( )
inlineoverridevirtual

Returns true if the engine is running in editor mode.

Reimplemented from vex::Engine.

Definition at line 121 of file Editor.hpp.

◆ loadAssetIcons()

void vex::Editor::loadAssetIcons ( )
private

Loads the texture icons used for the Asset Browser and other UI elements.

Definition at line 355 of file Editor.cpp.

◆ LoadConfig()

void vex::Editor::LoadConfig ( EditorProperties & data,
const std::string & filename )
inlineprivate

Loads the EditorProperties configuration from a JSON file.

Parameters
EditorProperties&data - The data structure to deserialize into.
conststd::string& filename - The path/filename of the JSON file.

Definition at line 191 of file Editor.hpp.

◆ LoadProjectConfig()

void vex::Editor::LoadProjectConfig ( ProjectProperties & data,
const std::string & filename )
inlineprivate

Loads the ProjectProperties configuration from a JSON file.

Parameters
ProjectProperties&data - The data structure to deserialize into.
conststd::string& filename - The path/filename of the JSON file.

Definition at line 223 of file Editor.hpp.

◆ OnHotReload()

void vex::Editor::OnHotReload ( )

Handler for post-hot-reload operations.

Definition at line 939 of file Editor.cpp.

◆ PasteObjectToScene()

void vex::Editor::PasteObjectToScene ( )

Pastes the object from the clipboard to the scene.

Definition at line 177 of file Editor.cpp.

◆ ProcessEditorShortcuts()

void vex::Editor::ProcessEditorShortcuts ( )

Processes editor shortcuts.

Definition at line 109 of file Editor.cpp.

◆ processEvent()

void vex::Editor::processEvent ( const SDL_Event & event,
float deltaTime )
overridevirtual

Overrides the Engine's processEvent function to handle editor-specific events (e.g., gizmo interaction, camera movement).

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

Reimplemented from vex::Engine.

Definition at line 287 of file Editor.cpp.

◆ PushCommand()

void vex::Editor::PushCommand ( ICommand * cmd)
inlineprivate

Pushes a command onto the undo stack and clears the redo stack.

Definition at line 242 of file Editor.hpp.

◆ raySphereIntersect()

float vex::Editor::raySphereIntersect ( const glm::vec3 & rayOrigin,
const glm::vec3 & rayDir,
const glm::vec3 & sphereCenter,
float sphereRadius )
private

Performs a ray-sphere intersection test.

Parameters
constglm::vec3& rayOrigin - The origin point of the ray.
constglm::vec3& rayDir - The direction vector of the ray.
constglm::vec3& sphereCenter - The center point of the sphere.
floatsphereRadius - The radius of the sphere.
Returns
float - The distance to the intersection point, or infinity if no intersection.

Definition at line 523 of file Editor.cpp.

◆ rayTriangleIntersect()

float vex::Editor::rayTriangleIntersect ( const glm::vec3 & rayOrigin,
const glm::vec3 & rayDir,
const glm::vec3 & v0,
const glm::vec3 & v1,
const glm::vec3 & v2 )
private

Performs a ray-triangle intersection test (using the Möller–Trumbore algorithm).

Parameters
constglm::vec3& rayOrigin - The origin point of the ray.
constglm::vec3& rayDir - The direction vector of the ray.
constglm::vec3& v0 - The first vertex of the triangle.
constglm::vec3& v1 - The second vertex of the triangle.
constglm::vec3& v2 - The third vertex of the triangle.
Returns
float - The distance to the intersection point, or infinity if no intersection.

Definition at line 534 of file Editor.cpp.

◆ Redo()

void vex::Editor::Redo ( )

Redoes the last undone action in the editor.

Definition at line 152 of file Editor.cpp.

◆ refreshForObject()

void vex::Editor::refreshForObject ( )
inlineoverridevirtual

Overrides the base Engine function to trigger a frame and refresh.

Reimplemented from vex::Engine.

Definition at line 94 of file Editor.hpp.

◆ render()

void vex::Editor::render ( )
overridevirtual

Overrides the Engine's render function to inject the Editor UI logic (dockspace, viewport, tools).

Reimplemented from vex::Engine.

Definition at line 291 of file Editor.cpp.

◆ requestSceneReload()

void vex::Editor::requestSceneReload ( const std::string & scenePath)

Requests a scene reload with a specific path. The reload is typically executed in the main update loop.

Parameters
conststd::string& scenePath - The path to the scene file to load.

Definition at line 349 of file Editor.cpp.

◆ SaveConfig()

void vex::Editor::SaveConfig ( const EditorProperties & data,
const std::string & filename )
inlineprivate

Saves the current EditorProperties configuration to a JSON file.

Parameters
constEditorProperties& data - The data structure to serialize and save.
conststd::string& filename - The path/filename of the JSON file.

Definition at line 178 of file Editor.hpp.

◆ SaveProjectConfig()

void vex::Editor::SaveProjectConfig ( const ProjectProperties & data,
const std::string & filename )
inlineprivate

Saves the current ProjectProperties configuration to a JSON file.

Parameters
constProjectProperties& data - The data structure to serialize and save.
conststd::string& filename - The path/filename of the JSON file.

Definition at line 210 of file Editor.hpp.

◆ setFullscreen()

void vex::Editor::setFullscreen ( bool enabled,
bool exclusive = false )
inlineoverridevirtual

Overrides the Engine's setFullscreen function to disable auto fullscreen by gameModule.

Reimplemented from vex::Engine.

Definition at line 59 of file Editor.hpp.

◆ ShowConsole()

void vex::Editor::ShowConsole ( )
inline

Shows the debug console.

Definition at line 124 of file Editor.hpp.

◆ Undo()

void vex::Editor::Undo ( )

Undoes the last action performed in the editor.

Definition at line 145 of file Editor.cpp.

◆ update()

void vex::Editor::update ( float deltaTime)
overridevirtual

Overrides the Engine's update function to handle editor-specific logic.

Parameters
floatdeltaTime - Time since last frame.

Reimplemented from vex::Engine.

Definition at line 212 of file Editor.cpp.

Member Data Documentation

◆ m_assetBrowser

std::unique_ptr<AssetBrowser> vex::Editor::m_assetBrowser
private

Definition at line 266 of file Editor.hpp.

◆ m_camera

std::unique_ptr<EditorCameraObject> vex::Editor::m_camera
private

Definition at line 263 of file Editor.hpp.

◆ m_currentGizmoMode

ImGuizmo::MODE vex::Editor::m_currentGizmoMode = ImGuizmo::WORLD
private

Definition at line 275 of file Editor.hpp.

◆ m_currentGizmoOperation

ImGuizmo::OPERATION vex::Editor::m_currentGizmoOperation = ImGuizmo::TRANSLATE
private

Definition at line 274 of file Editor.hpp.

◆ m_editorMenuBar

std::unique_ptr<EditorMenuBar> vex::Editor::m_editorMenuBar
private

Definition at line 264 of file Editor.hpp.

◆ m_editorProperties

EditorProperties vex::Editor::m_editorProperties
private

Definition at line 281 of file Editor.hpp.

◆ m_fps

int vex::Editor::m_fps = 0
private

Definition at line 287 of file Editor.hpp.

◆ m_gizmoStartPos

glm::vec3 vex::Editor::m_gizmoStartPos
private

Definition at line 256 of file Editor.hpp.

◆ m_gizmoStartRot

glm::vec3 vex::Editor::m_gizmoStartRot
private

Definition at line 257 of file Editor.hpp.

◆ m_gizmoStartScale

glm::vec3 vex::Editor::m_gizmoStartScale
private

Definition at line 258 of file Editor.hpp.

◆ m_gizmoWasUsing

bool vex::Editor::m_gizmoWasUsing = false
private

Definition at line 255 of file Editor.hpp.

◆ m_icons

BrowserIcons vex::Editor::m_icons
private

Definition at line 267 of file Editor.hpp.

◆ m_isAssetBrowserFocused

bool vex::Editor::m_isAssetBrowserFocused = false
private

Definition at line 260 of file Editor.hpp.

◆ m_isHoveringGizmoUI

bool vex::Editor::m_isHoveringGizmoUI = false
private

Definition at line 279 of file Editor.hpp.

◆ m_pendingSceneToLoad

std::string vex::Editor::m_pendingSceneToLoad = ""
private

Definition at line 269 of file Editor.hpp.

◆ m_projectBinaryPath

std::string vex::Editor::m_projectBinaryPath
private

Definition at line 272 of file Editor.hpp.

◆ m_projectProperties

ProjectProperties vex::Editor::m_projectProperties
private

Definition at line 284 of file Editor.hpp.

◆ m_redoStack

std::deque<std::unique_ptr<ICommand> > vex::Editor::m_redoStack
private

Definition at line 238 of file Editor.hpp.

◆ m_refresh

bool vex::Editor::m_refresh = false
private

Definition at line 289 of file Editor.hpp.

◆ m_SavedEditorProperties

EditorProperties vex::Editor::m_SavedEditorProperties
private

Definition at line 282 of file Editor.hpp.

◆ m_SavedProjectProperties

ProjectProperties vex::Editor::m_SavedProjectProperties
private

Definition at line 285 of file Editor.hpp.

◆ m_selectedObject

std::pair<bool, GameObject*> vex::Editor::m_selectedObject = {false, nullptr}
private

Definition at line 265 of file Editor.hpp.

◆ m_snapValue

float vex::Editor::m_snapValue[3] = { 0.5f, 0.5f, 0.5f }
private

Definition at line 277 of file Editor.hpp.

◆ m_undoStack

std::deque<std::unique_ptr<ICommand> > vex::Editor::m_undoStack
private

Definition at line 237 of file Editor.hpp.

◆ m_useSnap

bool vex::Editor::m_useSnap = false
private

Definition at line 276 of file Editor.hpp.

◆ m_viewportSize

glm::uvec2 vex::Editor::m_viewportSize = {1280, 720}
private

Definition at line 262 of file Editor.hpp.

◆ m_waitForGui

bool vex::Editor::m_waitForGui = true
private

Definition at line 270 of file Editor.hpp.

◆ MAX_UNDO_STEPS

const size_t vex::Editor::MAX_UNDO_STEPS = 50
private

Definition at line 239 of file Editor.hpp.

◆ showConsole

bool vex::Editor::showConsole = false
private

Definition at line 290 of file Editor.hpp.


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