![]() |
vkmEngine 1.0.15
A C++ game engine · vkmengine.com
|
vkm_editor edits one project: its scenes, prefabs and assets, with a play session to try them. It is an ImGui shell registered as a System on SystemStage::Editor, owning the panels, the layout, the undo stack and scene I/O. Panels mutate through an EditorContext aggregate, never through each other.
The viewport's overlays - the tool strip on the left, the view bar top-right, the playbar between them and the navigation axes bottom-right - draw in a child that is exactly the scene's rect; the three strips share one design (beginOverlayStrip, ui/editor_widgets.h).
The editor runs on Dear ImGui's docking branch: the root window holds the menu bar, one dockspace and the status bar, and every panel is a window that docks, tabs or floats. Their names are in chrome/dock_layout.h, because a name is what the ini files a window's place under. Where they are and how big is ImGui's; nothing of the editor's stores a panel size, and the default layout's are constants in chrome/dock_layout.h. Multi-viewport is off.
| Panel | File | Description |
|---|---|---|
| Hierarchy | panels/hierarchy_panel.cpp | Every entity; drag a node onto another to reparent (cycle-safe) |
| Inspector | panels/inspector_panel.cpp | Component cards; prefab-instance overrides |
| Animation | panels/animation_panel.cpp | Transport, three-lane keyframe timeline, a table per track |
| Render Settings | panels/render_settings_panel.cpp | Floating window over RenderSettings (Window > Render Settings) |
| Material Editor | panels/material_editor_panel.cpp | The Material window: one material under a live preview |
| Terrain Editor | panels/terrain_editor_panel.cpp | The Terrain window: tools, brush, layers and plants (terrain.md) |
| Asset Browser | panels/asset_browser_panel.cpp | The Assets window: one library for every asset kind |
| Project Settings | panels/project_settings_panel.cpp | Floating window over project.json (File > Settings...) |
| Preferences | panels/preferences_panel.cpp | Floating editor settings window (Edit > Preferences, Ctrl+,) |
| Errors | panels/errors_panel.cpp | Recoverable engine failures (EngineErrorLog), newest first |
| Build | session/build_controller.cpp | The vkm command running or last run, and its output |
| Viewport Overlay | overlays/viewport_overlay.cpp | The axis navigation gizmo |
| Gizmo Overlay | overlays/gizmo_overlay.cpp | The transform gizmo's drawing and drag, and click-to-pick |
| Gizmo Drawing | overlays/gizmo_overlay_draw.cpp | Every draw*Gizmos body, plus the selection outline |
| Viewport Toolbar | overlays/viewport_toolbar.cpp | Tool strip (tool, space, snap) and view bar (shading, camera, projection, Frame All, Focus) |
| Playback Bar | overlays/playback_bar.cpp | Play / Pause / Step / Stop; frames and captions the viewport during a session |
| Start Screen | panels/start_screen.cpp | Shown when no project is open |
The chrome belongs to EditorSystem and sits around the layout:
| Chrome | File | Description |
|---|---|---|
| Menu Bar | chrome/editor_menu_bar.cpp | File / Edit / View / Window / Entity / Help; reads and writes EditorState, forwards scene-file intents to SceneIOController |
| Status Bar | chrome/editor_status_bar.cpp | Dirty dot, the selection's breadcrumb and position, the build banner |
| Dock Layout | chrome/dock_layout.cpp | Window names and the default layout |
Preferences, Render Settings and Project Settings open through beginToolWindow (ui/editor_dialogs.h), which never docks.
Scene-global settings are cards in the World inspector (the World row at the top of the hierarchy): Environment, Procedural Sky, Volumetric Fog and Physics (Scene::physics()). They are scene data. Render Settings, quality tuning rather than content, has its own window.
Camera, Gizmo (snap defaults), Display and Keybinds tabs over one Preferences struct on EditorState, saved in editor_user.json under userRoot() (per person, not per project) and applied every frame by EditorSystem::applyPreferences. Vsync, the frame cap and the window mode stand aside during a play session, where the game may set the window up its own way.
UI Scale (Display) multiplies the display's own content scale; everything the editor draws itself follows it through EditorStyle::px().
One way in: EditorState::openMaterial(handle), used by the Mesh card and the Asset Browser's tile and New verb. Shown and hidden with the Inspector (Ctrl+2).
Works on the selected entity. Play/Pause is a preview writing the runtime Animation::playing; what a shipped scene does is the card's Play On Start. Length (Animation::length) 0 means the last keyframe. Re-keying at an existing time replaces that keyframe.
The world does not step in Edit mode, so moving the playhead poses the entity through AnimationSystem::applyAnimation, the function the system samples with. Outside play that pose is the authored Transform, so it is recorded as one Scrub Animation step per gesture; in play it is not recorded.
A component card is an editComponentCard section, so it undoes, records prefab overrides and appears in Add Component. Controls over session state push no edit:
The identity header shows the entity's wire slot and which components replicate, or warns that it is off the wire and why (netSilence) (networking.md). Drawn only when the project replicates something and the entity carries some of it.
A card greys what the scene, not the author, writes. With Procedural Sky on, SkySystem drives the key light's rotation, colour and intensity, so that Light card says so and disables colour and intensity. Both find the light with findKeyLight, so they cannot disagree.
Where the engine can tell a component will do nothing, its card says so in place - EditorStyle::DANGER for "does nothing", EditorStyle::WARNING for "is not what you think". For example: a Collider with no Rigidbody (physics walks the Rigidbody storage, so nothing collides with it), a dynamic Rigidbody with no Collider, a UI element with no UICanvas above it or no UIElement beside it (warnNoUIElement), an active camera that is not the game's eye. The checks live with their cards in panels/inspector_panel.cpp; add one wherever a component can sit silently inert.
Every slider is sliderFloat / sliderInt and every combo beginCombo or comboList (ui/editor_widgets.h); nothing calls ImGui's directly, so a look changed there changes everywhere.
propDrag / propSlider / propDragInt / propDrag3 pass ImGuiSliderFlags_ClampOnInput (PROP_CLAMP), because Ctrl+click turns a drag into an unbounded text field. Not AlwaysClamp: that also clamps a lo == hi == 0 range, which is how a row spells "unbounded".
pickAsset offers a (none) row, because an empty slot round-trips through the scene file.
Translate, rotate and scale handles, axis-constrained; Select mode draws none so a click always selects. transform_gizmo.cpp holds the whole gizmo. A drag pushes one step when it ends: editStep<Transform>, or one CompositeCommand when the selection has several roots. Picking and drags cast viewportRay from the near plane, so orthographic views pick too.
Snapping (the strip's toggle, or Ctrl held) moves in whole steps from where the drag began, along the handle held (overlays/gizmo_snap.h); an off-step value keeps its offset.
Keys, while the cursor is not captured: Q Select, W Move, E Rotate, R Scale, X Local / World - rebindable in Preferences > Keybinds.
While the Terrain window is open with a tool picked, a left drag over the terrain it edits brushes (TerrainToolOverlay) and no gizmo is drawn; a click that misses it picks as ever, and Esc puts the tool down before it deselects.
Everything with no mesh draws an authoring marker (gizmo_overlay_draw.cpp): lights, cameras, probes, planar reflectors and irradiance volumes, decals, particle emitters, audio sources and listeners. View > Show toggles each kind (GizmoVisibility, per project in editor_settings.json); a hidden kind cannot be picked.
The editor looks through a viewpoint of its own (EditorViewpoint: position, yaw, pitch, projection), not an entity: flying marks nothing unsaved, a scene needs no camera to be edited, and nothing of the editor's writes the game's camera. The view bar's camera box picks what the frame renders through:
| Mode | The frame renders through | Flies |
|---|---|---|
| Edit, Editor (the default) | the editor's viewpoint | yes |
| Edit, a scene camera from the box | that camera, active or not: a read-only preview, (main) on the one the game starts on | no |
| Play | the game's camera; the box reads Game | no |
| Play, ejected (F8) | the editor's viewpoint, or a previewed camera | unless a camera is previewed |
A previewed or game camera draws no frustum or marker and takes no gizmo (Visibility::cameraEntity names it), since dragging the view you look through would move it. Set as Main Camera in the inspector picks the game's eye, which is a separate thing.
The viewpoint is kept per scene in editor_settings.json under sceneViews (EditorState::sceneViews), by path relative to the project. A scene with no entry is framed from its active camera, or from (0, 2, 6) facing the origin.
Fly controls:
| Input | Action |
|---|---|
| Right mouse button (hold) | Look mode (cursor hidden) |
| Mouse movement (in look mode) | Yaw / pitch |
| W / A / S / D | Forward / left / back / right |
| Q / E | Up / down |
| Shift (hold) | Speed boost |
| Scroll wheel (in look mode) | Dolly; orthographic, zoom |
| Numpad 5 | Perspective / orthographic |
Speeds and sensitivities (CameraControllerSystem::Settings) are the Preferences Camera tab (Preferences::camera).
Orthographic (view-bar button, View > Orthographic, Numpad 5) keeps the focus - what Frame Selected, Frame All or a navigation axis last aimed at - the same size (EditorViewpoint::orthoHeight). A navigation axis snaps to an orthographic view down that axis (viewAlongAxis); turning the view returns to perspective unless the projection was switched by hand.
It opens, renders and edits like any other; a play session has nothing to render from, and ViewportOverlay::drawNoCameraNotice says so. Entity > Create > Camera makes the new camera active only when the scene has no active one, so a new camera never takes the game's view.
Decided once a frame, before the ImGui frame opens, from the hovers the last frame drew (InputOwnership, input/input_ownership.h, as EditorContext::input); the shortcuts, gizmo, picker, navigation axes and the capture declared on HostChrome all take that one answer. The first row that holds wins:
| When | Owner | What answers a press |
|---|---|---|
| The cursor is hidden and grabbed, by the fly camera or a running game | Captured | Nothing of the editor's: ImGui is told it has no mouse |
| A gizmo drag is held | GizmoHandle | The drag, wherever it has gone |
| The pointer is off the viewport | Panel | A panel, a popup, a floating window |
| Over the tool strip, the view bar, the playbar or the navigation axes | Overlay | The overlay |
| Over a gizmo handle | GizmoHandle | The handle |
| Over a blocking element of the game's UI | GameUI | Selected, unless the game has the viewport - then the game's |
| Anywhere else on the viewport | Scene | The picker - or, over the terrain with a Terrain tool up, the brush first |
While a field is typed into, a menu, popup or dialog is open, or Preferences waits for a key to rebind, no keybind answers and the fly camera hears nothing (InputOwnership::keysHeldByUI). While an edit is held under the button - a gizmo drag or a terrain stroke, its undo step not yet pushed - no keybind answers either, Play and undo included (InputOwnership::held).
A play session's viewport is the game's. With the pointer on the viewport, or the cursor grabbed by the game, keys and mouse buttons go to the game: no editor shortcut acts, so Ctrl+1 picks a weapon rather than hiding the Hierarchy. Still live: the Toggle Editor key (F5), Play / Stop (Ctrl+P), Pause / Resume (Ctrl+Shift+P), Eject / Return (F8; PlaybackBar::processKeys) and the playbar. The editor's view stands down (CameraControllerSystem::setActive), and framing, the navigation axes, the gizmo and click-picking with it (InputOwnership::clickPicks).
Eject / Return (F8, or the playbar's camera button) hands the viewport back: the running game renders through the editor's viewpoint, which flies, picks and edits as in Edit mode, while the game hears nothing (InputOwnership::hostHoldsPointer). A cursor the game grabbed is freed while ejected and restored on return. Stop ends an ejection with the session.
Operations act on the tile under the pointer, not a selection: F2 renames it; its context menu assigns it to the selected entity through an EditScope<T> (an undo step, and an override on an instance). Rename suffixes a taken name (ResourceManager::rename). Delete asks first instead of offering undo: a re-added asset takes a new slot, so every handle to the old one stays dead.
Import. The toolbar's first control is the kind's primary verb - New for materials and terrains, Import... for the rest. Meshes, skeletons and clips raise EditorState::requestModelImport, since all three come out of one model. A texture imports as colour (TextureUsage::Color); data and normal maps come with their model or through the Material Editor slot, which knows the usage. A file the project already holds is refused, because ResourceManager::add under a taken name replaces that asset in place.
"In use" - the strip on every tile, and Delete's guard - is AssetSerializer::collectAssetRefs (io/asset/asset_serializer.h), the walk a scene save builds its assets block from, so an asset a save would name is in use. Five kinds also count references that walk does not see:
| Kind | Also referenced by |
|---|---|
| Materials | every terrain's layers and plants |
| Meshes | every terrain's plants |
| Textures | every TextureHandle slot on every MaterialAsset, drawn or not (VKM_MATERIAL_MAPS) |
| Skeletons | a skinned mesh's MeshAsset::skeleton and AnimationClipAsset::skeleton, resolved from their name strings |
| Clips | every Animator's fadeFrom - session state, but a fading clip is still sampled |
A clip tile marked no rig names a skeleton that does not resolve, so it animates nothing.
Previews. Materials and meshes render through EditorRenderHooks::renderPreview, cached per asset and version, a few baked per frame (MaterialPreviewSession). A texture tile draws the renderer's own GPU copy, uploaded through EditorRenderHooks::ensureTexture. Known: an sRGB texture's thumbnail draws darker than the file - ImGui writes the linear sample to a framebuffer that is not sRGB-encoded.
Inside, the browser is a KINDS[] table of AssetKind descriptors, one per AssetType, each a set of function pointers; the only place a C++ asset type appears is KindOps<Asset>. rename is null for skeletons, whose name meshes and clips carry as a string, and for terrains, whose name is their file's path. FontAsset is not a kind: the library does not hold it.
A generated mesh has a deterministic name - mesh:generator:cube, mesh:generator:sphere:16 - and addGeneratedMesh and generateDefaultMaterial reuse what the graph holds under it, so three cubes share one mesh and one material:default. A material of its own comes from Duplicate or New, which copy the default rather than rename it - renaming would pull material:default from under everything that names it.
The engine ships effects - an explosion, a campfire, a torch, a plume of smoke - as a pack under ProjectPaths::engineContent(), content/effects/, laid out as a project is: textures and sounds in assets/effects/, prefabs in prefabs/effects/, their recipes in library/. The menu lists the pack's prefabs; choosing one copies each file of the pack the project lacks to the same path in the project, then places the prefab as Prefab does (EditorActions::placeEffect).
A scene stores a prefab instance as a reference, a pose and its overrides, not the subtree - so anything done inside an instance that is not an override is not saved. The editor makes each gesture mean what it looks like, or refuses it:
EditorActions::saveAsPrefab writes the selected subtree to the project's prefabs/ and turns it into an instance of the file.
Every mutation goes through a Command holding the before and after state. The caller has already applied the change, so pushing records it; undo and redo replay one side. The stack holds 200 steps (CommandStack::HISTORY_LIMIT) and is cleared on scene load, since entity IDs do not survive the swap. The commands are documented in command/editor_commands.h; which one an edit takes:
CommandStack::push tries Command::tryMerge against the top step while the gesture is open - that is drag coalescing. EditorSystem calls CommandStack::endGesture at the end of every frame with no mouse button held and no ImGui item active, sealing the top; without it, a second drag of the same field would merge into the first.
The editor edits a project. If ProjectController::open fails at EditorSystem::init, the editor draws the start screen and no workspace, since every workspace path would resolve against the engine's own directory. With no argument, a vkm_editor shipped beside a project opens it. A path naming a file opens its project (findProjectRoot walks up). See io.md.
ProjectController::open (session/project_controller.h) roots the editor in a project, or re-roots it in place with no restart. Its steps are in order because each composes paths or runs code the one before put in place: the outgoing project's settings are saved while its root is current, the scene is torn down (SceneIOController::beginSceneReplace) while the old gameplay module still holds the behaviors' code, and only then is the module swapped. It builds the wire schema from the module's vkmSetupNetwork so the editor can show what goes on the wire (the editor never hosts or joins), and boots the world through bootProjectWorld, as every host but vkm_cook does. An entry scene that will not load leaves the default scene and an error toast - the editor is where you fix it (io.md).
Choosing a project - OpenProjectDialog (chrome/open_project_dialog.h), Open Recent, the start screen - goes through EditorState::requestSceneAction, because opening one throws the scene away.
New Project, File > Build Scripts and File > Package Game run vkm new, vkm build and vkm package through the launcher beside the engine (BuildController::launcher); the editor never builds itself. Output fills the Build window, which can stop the run and its compilers (ChildProcess). Outside a play session the editor's watch on the module reloads a new build however it was made; during one, a toast points at File > Reload Scripts. A project that opens with no module is built once.
Quit (File > Exit, the titlebar close), New Scene, Open Scene and Open Project all go through one entry point, which neither checks dirtiness nor acts - so a new destructive action cannot forget to ask:
EditorSystem::resolveSceneAction answers it once per frame, before the ImGui frame opens, because rebuilding the scene must not happen with a window on the ImGui stack. Stages: Ask (clean goes straight to Run; dirty raises Unsaved Changes), Saving (ends any play session, since a save inside one is refused; backing out of the Save-As withdraws the request), Run (performSceneAction).
SceneIOController owns New / Open / Save / Save-As: the file-picker modals, then SceneSerializer::save / load (io.md). A load restores the editor's viewpoint for that scene and ends any play session (endPlaySession).
During a session the ECS holds the simulation's copy, and every panel stays live:
What Play captures - the scene document, the asset list, where each prefab instance's entities stood, the dirty flag - is PlaySnapshot (session/play_snapshot.h), which needs nothing of the editor, so vkm_engine_tests play covers the round trip. SceneIOController::isPlaying() is the state; ask it, not the clock, which is paused in Edit mode too. SceneIOController::stopPlaySession is all of Stop.
An open is a clean break - undo stack, selection, previews and a fresh ResourceManager - ending in afterSceneReplace, after which an open reselects the active entity by name. New Scene and Open Project reach it through beginSceneReplace, which empties the scene first. An import the outgoing scene never named - a sound not yet assigned - has nothing to be recreated from and is dropped; the count goes in a toast, the names in the log.
Stop is the opposite: it puts the session back exactly as Play found it, history included.
Steps that destroy by slot check it still holds their entity (EntitySnapshot::describes), and a step reclaiming a slot checks it is free; a mismatch skips the step with an error toast.
Every directory under src/editor/ is one responsibility:
| Directory | Holds |
|---|---|
| (root) | EditorSystem, EditorState, EditorContext, EditorSettings, and editor_actions - the scene mutations panels invoke |
| command/ | Undo: Command, CommandStack, the commands, EditScope/editStep/pushEdit, CommandHost::pushStep, prefab-override bookkeeping. Reaches the editor through CommandHost, so it tests without a window |
| session/ | What outlives a frame, and the project's files: SceneIOController, ProjectController, PlaySnapshot, BuildController, the material preview cache, ContentPack (the engine's packs brought into a project), the terrains' files (terrain_files.h) |
| panels/ | One file per panel, owning only its own widget state |
| overlays/ | Drawn over the viewport: gizmo, tool strip and view bar, playbar, navigation axes |
| chrome/ | Drawn around the panels: menu bar, status bar, default layout, and the menus' dialogs, drawn at the menu bar's scope so a closing menu does not take them |
| input/ | Keybinds and shortcut dispatch, InputOwnership, CameraControllerSystem and ViewFraming |
| ui/ | The widget vocabulary: prop* rows, dialog scaffold, style, icons, asset picker, audition transport |
The scene renders into the window's backbuffer inside the viewport's rect; the Viewport window has no background. Once a frame the editor states that rect, and whether its panels hold the pointer and keyboard, on HostChrome (ctx.chrome). RenderSystem, VisibilitySystem and UISystem read the rect; InputMap::update reads the capture (input.md). A runtime writes neither, and the defaults are what a shipped game wants.
The world is open to edits (HostChrome::setAuthoring) in Edit mode, paused, ejected, or with the panels shown. Fixed meshes (Mesh::movable off, the Mesh card's Movable) keep nothing then (visibility.md), so the work they save shows only in a running session with the editor hidden (Toggle Editor, F5) or in vkm_runtime.
CameraControllerSystem holds the EditorViewpoint and publishes it as ctx.hostView at the Input stage, before every reader of a view (visibility.md); VisibilitySystem renders through it instead of the scene's camera. The picker, gizmo, wire overlays and navigation axes project through ctx.visibility's matrices, so they follow whatever the frame rendered through.
Only the editor registers it - vkm_editor's main() adds it after setupEngineApp - so a shipped game cannot reach it. Its fly bindings (CameraActions) live in an InputMap it owns, sampled against what the panels hold (setCapture), never in the game's: an ejected session can fly while the game hears nothing, and a game's map spends no command slots on Camera/ actions.