Skip to content

Editor

Applications

Editor startup and the process object, the per-user settings, project state and trust, play mode with play-mode persist and the play edit log, and headless execution.

Headers

File Description Provides
editor_application.h The editor process object: owns the engine::application, the editor_context and the protocol_server, drives the frame integration headless (through a core layer) or with the UI layer the executable injects, restarts the engine when project.open names another project and runs --export / --exec / the interactive loop. The command file of --exec is read and parsed before the engine starts, so a missing or malformed file fails at once. A windowed editor whose --project cannot be opened starts without a project, on the start screen, instead of failing (falls_back_to_start_screen). It also resolves the per-user configuration folder, loads the user settings into the context and keeps the recent-projects list. editor_application
startup_plan
startup_project
editor_context.h The editor's service table: owns the command registry, dispatcher, undo stack, selection, play controller, events, camera, console and screenshot service, and holds non-owning references into the running engine::application (taken from engine_context, rebound when the editor opens another project). Handlers reach everything through it. Main thread only. editor_context
editor_context::debug_draw_flags
editor_host
frame_task
editor_error.h The editor error category. The protocol's stable error strings and the editor's own core::error codes are one enumeration: a handler returns core::make_error(code, message) and the dispatcher writes to_string(code) into the response. Errors of other modules (ecs, scene, assets, core) that reach a response are mapped through classify_error().
editor_module_consumer.h The editor's module consumer: turns editor.command records into command_descriptors owned by the module, and keeps the module's editor UI records for the UI (panels, kit icons and kit drawers); detach removes them all. Each UI record is copied at attach, its texts into strings of its own, so nothing reads the module's text after its entry returned; the callbacks and their user data stay the module's, valid until it detaches, and the UI calls them only while it draws that module's panel or row. A module whose panels use the legacy editor.panel record (the raw ImGui context) is told once at each attach, in an INFO, that they draw in COMPAT and the record is deprecated. It vetoes an unload with UNLOAD_BLOCKED while the editor plays, because scripts and systems of the module may be live. editor_module_consumer
module_drawer_entry
module_icon_entry
module_panel_entry
editor_options.h The conjure_editor command line: the editor's own flags are parsed here, everything else (--rhi, --log-level, --frames, ...) is passed on to the engine's parser through engineArguments. A bad editor flag is INVALID_ARGS; an option the engine does not know either, or a bad engine flag value, is refused by editor_application::make_engine_desc with BAD_ARGUMENTS. main() exits with 3 for both. editor_options
headless_runner.h conjure_editor --headless --exec commands.json: a JSON array of requests or NDJSON, one request per line; a missing id becomes the zero-based index. The file is read and parsed before the engine starts (editor_application::initialise calls load_command_file), so a missing or malformed file costs no engine boot. Every request is dispatched, frames are pumped until an asynchronous response exists, responses and events are written as NDJSON to the output; the run stops at the first failure unless --keep-going. When the engine could not load the project's startup scene, the output opens with warning {code: "STARTUP_SCENE_FAILED", message} and the run carries on over the empty world: the exit code does not change, so a command file that repairs the scene still runs. editor.quit ends the run after its reply, and its non-zero exitCode becomes the run's exit code. Exit codes: 0 all ok, 1 a command failed, 2 startup or project failure (also a project.open in the file whose restart failed for both projects) or responses that could not be written, 3 bad arguments (a missing or unparseable file). exec_summary
headless_runner
log_category.h The editor's log category: every message of conjure_editor_core, conjure_editor_ui and the conjure_editor executable goes through LOG_EDITOR ("editor"), so the console panel and the protocol's log event can filter it like any other engine category.
persist_list.h Play-mode persist. While playing or paused a user or a protocol client pins a field, a whole component or a whole entity; play.stop reads the pinned values before the snapshot restore and applies them after it as one undo entry, "Persist from play (N)". Pins are UI state like the selection: not undoable, cleared at play.start and after play.stop, never saved. The play_controller owns the list (main thread only) and announces every change with the persist.changed event. persist_capture
persist_captured_entry
persist_entry
persist_list
persist_member
persist_pin_result
persist_reference
persist_report
persist_request
persist_skip
persist_unpin_request
persist_value
play_controller.h Play mode in the editing world. EDITING keeps the engine PAUSED and the script runtime in EDIT mode; play.start captures a scene snapshot, freezes the undo stack and runs the engine; play.stop ends a script's anti-aliasing override, restores the snapshot (guids preserved), remaps the selection and thaws the undo stack. A scene edit made while playing is not recorded and goes with the restore; a file edit (an ON_DISK command) stays on disk, so the controller keeps its inverse and play.stop pushes all of them as one undo entry. play.step runs exactly n fixed steps through application::step_fixed and answers once they ran. The clocks play.* report belong to the play session: play.start records the engine's fixedTime and fixedStepIndex, the session's time and fixed steps count from there (they stop while paused), and the ended session's values stay until the next play.start. edit_origin_scope
play_controller
play_controller::pending_step
play_edit_log.h Who changed what during play (the Persist table's "Changed by" column). While the scene plays or is paused, the dispatcher hands the play controller every scene edit a command makes, with the command's origin: the Inspector, a gizmo drag in the Scene view, the editor's other UI, or a protocol client. The log keeps, for each place an edit reached (a value inside a component, a whole component, or the entity as a whole), the latest edit's origin and what that edit left: the component, every component of an entity a command changed as a whole, or that it removed the entity. A value changed without a command was changed by the running game (its scripts and systems): it no longer holds what the last edit left, or, with no edit, what the snapshot of play.start held; an entity gone without a command removing it last was destroyed by the game. The log names only what it can tell from those, never a guess. Main thread only; the play controller clears it at play.start and play.stop. play_edit
play_edit_log
project_trust.h Project trust. Opening a project runs code from its folder with the rights of the user who runs the editor: the engine loads its native modules and its game assembly while it starts, and script.compile, module.build and play.start run more of it afterwards. The editor therefore opens a project only once somebody answered for it, and project_trust is where the answers are kept: project_trust
trusted_project
user_settings.h Per-user editor preferences: the active theme, the recent projects, the UI scale and the code ligatures switch, kept in <user config>/editor_settings.json, never in a project. The file is UTF-8 JSON: editor_user_settings
recent_project
user_settings_load

Breakdown

The process and its context

The entry point in editor/src/main.cpp constructs editor_application (conjure/editor/editor_application.h) over engine::application. editor_options selects the application mode and command-line options, and everything it does not know is passed on to the engine's parser. headless_runner executes requests without the workspace UI, while using the same editor services and command model.

editor_context holds the services commands operate on. project_trust controls which projects may be opened; play_controller owns the transitions between editing and play mode, the play session's pins and its edit log. editor_module_consumer connects extension records to the editor. The executable and these services are parts of the editor application. Editor Architecture covers how a command runs, frame integration, headless mode and the exit codes.

Startup order

editor_application::initialise(options, uiFactory) checks everything that can be wrong without an engine before it starts one, in this order:

  1. The arguments, the project and the configuration. make_startup_desc(options) runs make_engine_desc over --project: an option neither the editor nor the engine knows is BAD_ARGUMENTS, before the project is loaded, and then project.json and the merged configuration are read and validated. When that fails because of the project alone (its project.json is missing or invalid, or its settings do not validate even without an engine flag) and falls_back_to_start_screen(options) holds, the description is made without a project instead: startup_problem() keeps the sentence, options().projectPath is cleared, and the workspace opens on the start screen. A fault of a flag still fails the start.
  2. The log file. The run's log file is held from here on, so every later refusal is recorded in it; the fall-back's one ERROR is logged now, and --log-file therefore says why a windowed run has no project.
  3. The command file. With --exec (and no --export), headless_runner::load_command_file reads and parses the file; a missing or malformed file is BAD_ARGUMENTS and no engine starts.
  4. The trust check. plan_startup(options, trust) runs resolve_startup_project, which opens a project somebody answered for, leaves one nobody answered for out as unanswered where can_ask_about_trust(options) holds (a window, and neither --exec nor --export), and fails with PROJECT_NOT_TRUSTED everywhere else. It then makes the engine description over the project it let through and no other. A project that fell back in step 1 is not asked about.
  5. The engine. boot_engine starts the engine with the editor's core layer. The first time, it creates the editor_context and loads the user configuration (below); a later restart rebinds the context instead. Then it pushes the UI layer from the factory, unless the session is headless.
  6. The question and the server. A project left out in step 4 raises the context's trust prompt, with one WARN, and the protocol server starts. A headless session fails when the server cannot start; a windowed one logs the error and runs without it.
  7. The recent projects. remember_open_project() records the open project when records_recent_projects says so.

A windowed session can therefore start without its --project for two different reasons, and the window shows each one differently:

The project editor_host::startup_problem() editor_context::trust_prompt() The window shows
cannot be opened (no or invalid project.json, invalid settings) the reason empty the start screen, with the reason as its Open problem
opens, but nobody answered for it empty the project's folder the trust question, over the start screen

conjure_editor's main exits with 3 for BAD_ARGUMENTS or an INVALID_CONFIG that a flag caused, and with 2 for any other failure of initialise().

User settings

conjure/editor/user_settings.h holds the per-user editor preferences, kept in <user config>/editor_settings.json and never in a project:

Member Default Rule
activeTheme Midnight (DEFAULT_THEME_NAME) a non-empty string
recentProjects empty most recent first, at most MAX_RECENT_PROJECTS (10), each {root, name} with an absolute, lexically normal root stored with forward slashes
uiScale 100 (DEFAULT_UI_SCALE) an integer percentage from MIN_UI_SCALE (50) to MAX_UI_SCALE (300)
codeLigatures true a boolean

The file also holds schema_version, which must be USER_SETTINGS_SCHEMA_VERSION (1).

  • Loading never fails. load_user_settings(folder) returns the settings with a user_settings_state: MISSING (no folder or no file: the defaults), LOADED, INVALID (not JSON, or a member of the wrong type or value: the defaults and one WARN), or UNREADABLE (the file exists but cannot be read: the defaults and one WARN). parse_user_settings ignores members it does not know and puts the recent list in canonical form without touching the disk.
  • Every change is a read-modify-write. Several editors may run at once and share the file, so update_user_settings(folder, change) reads the file as it is now, applies the change and writes it atomically. It keeps the members this version does not know. A file that was INVALID is first copied, byte for byte, to editor_settings.json.bak; a file that cannot be read is not written over, and the save fails. Two editors writing in the same instant can still lose one change, but neither can tear the file.
  • Recent projects. add_recent_project puts a project at the front and drops an entry naming the same project. same_recent_root compares canonical spellings, and asks the disk (std::filesystem::equivalent) only for two roots that differ in ASCII letter case alone, so an offline drive costs nothing. record_recent_project is update_user_settings with add_recent_project.

The folder. editor_application::user_config_directory_for(options) selects it: --user-config made absolute against the working folder and lexically normal when given, otherwise platform::user_config_directory() (conjure/platform/user_directories.h: %APPDATA%/Conjure on Windows, $XDG_CONFIG_HOME/conjure or ~/.config/conjure on Linux, ~/Library/Application Support/Conjure on macOS). When neither can be resolved it is empty after one WARN, and the settings and the recent projects are kept in memory only. The same folder holds the user's themes (<user config>/themes) and fonts (<user config>/fonts).

The per-user state folder is a different one: user_state_directory() in the private core/user_paths.h, with user_paths_windows.cpp (the known folder LocalAppData with Conjure appended) and user_paths_posix.cpp (posix_user_state_directory: $XDG_STATE_HOME/conjure or ~/.local/state/conjure on Linux, and ~/Library/Application Support/Conjure on macOS) selected by CMake. It holds the project trust store, described in Project trust. Only editor/src/main.cpp asks for it, through default_trust_store_file(), so an editor_application given no store never touches it.

When it is read and written. boot_engine calls load_user_configuration() once per initialise, when it creates the context and never on a restart: after the context exists, so the load's warnings reach the console buffer, and before the UI factory runs, so the UI layer finds the settings. The context keeps the folder and the settings across rebind. remember_open_project() runs at the end of initialise and after every successful project.open restart, when records_recent_projects(options) holds (options.recordRecentProjects when set, otherwise a windowed editor that is not --headless, --exec or --export). It records project()->root_directory(), not the argument the project was opened with, and adopts the file's recent list while keeping the context's own theme. Without a folder, or when the file cannot be written (one WARN), only the context's list gets the project. The theme and preference commands (editor.theme.set, editor.preferences.set) save through the same read-modify-write.

Play-mode persist and the play edit log

While playing or paused, a user or a protocol client pins a field, a whole component or a whole entity, and play.stop keeps the pinned values. conjure/editor/persist_list.h holds the pins; play_controller owns the list and announces every change with the persist.changed event. Pins are UI state like the selection: not undoable, cleared at play.start and after play.stop, never saved. play.persist, play.unpersist and play.persisted are REQUIRES_SCENE | PLAYING_ONLY and do not carry MUTATES.

  • Coverage. An ENTITY pin covers the COMPONENT and FIELD pins of its entity (with children, every pin of its subtree), a COMPONENT pin the FIELD pins inside it, and a FIELD pin the FIELD pins below its path. A pin a wider one covers changes nothing, and a wider pin replaces the narrower ones. A pin on an entity created during play is promoted to ENTITY, and a FIELD pin inside a component added during play to COMPONENT, because the value would otherwise have nowhere to land after the restore.
  • Stopping. play_controller::stop(play_stop_mode) applies the pins with APPLY_PINS (play.stop, editor.quit {saveChanges}, a module detach) and discards them with DISCARD_PINS (the shutdown and the project.open restart, which throw the scene away). With APPLY_PINS, persist_list::capture reads the pinned values before the script runtime leaves play mode, because OnDestroy may change the scene; then the snapshot is restored, the selection remapped, undo thawed and the file edits pushed, and persist_list::apply writes the values as one undo entry, "Persist from play (N)", pushed past any open transaction.
  • Apply. apply runs only existing commands (component.set, add and remove, entity.restore, set_parent, set_enabled and destroy), so redo replays it like any other entry; the script component's entity references travel with their guids (entityRefs) and land on the entities a redo restores. Each pin is all or nothing. A pin that fails is rolled back and reported with the command's error code; when it restored entities created during play, every step is taken back and the apply starts over without it, so no applied pin references an entity that is gone (REFERENCE_NOT_PERSISTED). A failed restore drops the captured values with RESTORE_FAILED. The outcome is last_persist_report().

conjure/editor/play_edit_log.h records who changed what during play, for the Persist table's "Changed by" column. While the scene plays or is paused, the dispatcher hands the play controller every scene edit a command makes, with the command's origin: INSPECTOR and GIZMO while an edit_origin_scope the UI opens around that drawing lives, EDITOR for the editor's other UI, and CLIENT for a protocol client. For each place an edit reached (a value inside a component, a whole component, or the entity as a whole) the log keeps the latest edit's origin and what that edit left, up to play_edit_log::MAX_PLACES (4096) places. changed_by(entry) answers that origin while the place still holds what the edit left, GAME when it holds something else or when no command changed it and it differs from the snapshot of play.start, and NONE when nothing changed it. The controller clears the log at play.start and play.stop.

Runtime state. A running script's started flag (OnStart was attempted) and created flag (OnCreate returned this session) are the state of the script runtime, not values play changed, and a play snapshot never carries them. support::is_script_runtime_state names both, and support::strip_script_runtime_state removes them from a script component's JSON: in the values play.persisted reports, in the values persist_list::capture reads, in what the play edit log records, and in the Persist panel's summaries; same_as_edited and changed_from_edited skip them. Written back while editing, they would make the next play session skip a script's OnStart and run OnReload in place of OnCreate.

How the panels show pins is described in Play-mode persist in the UI.

Threading Model

The application, the context, the play controller with its pins and edit log, and the user settings are main-thread only. The user settings file is read once per initialise and written at the moment of a change, on the main thread; other editor processes share the file, which is why every write re-reads it. The exceptions to the main thread (the stdio reader and the screenshot encode job) are described in Editor Architecture.

Extension Points

  • A user setting. Add the member to editor_user_settings with its default and limits, read and check it in parse_user_settings (a wrong value makes the file INVALID), write it in serialise_user_settings, and save every change through update_user_settings, never a write-back of what was loaded. Preferences a client may read or set go through editor.preferences.get and set in core/commands/commands_theme.cpp.
  • A way to open a project. It must go through editor_application::require_trusted; see Project trust.
  • A command-line option. Parse it in parse_editor_options (conjure/editor/editor_options.h); a test that starts an editor passes options from scratch_editor_options, so it never touches the user's real settings.

Testing

tests/editor/test_editor_application.cpp covers the startup order: the start-screen fall-back (editor_options::fallBackToStartScreen), a fall-back that still fails for the fault of a flag or refuses a project nobody answered for where nobody can be asked, the trust decision, and the recent projects after project.open. test_user_settings.cpp covers parsing, the read-modify-write, the backup and the recent list; test_persist_list.cpp and test_play_edit_log.cpp cover pins, capture and apply, and the edit log's origins.

No test reads or writes the user's real settings: editor_test::headless_editor passes a scratch --user-config folder of its own (optionally seeded with headless_editor_options::userSettingsJson, and recording opened projects with recordRecentProjects), a case that starts an editor_application itself takes editor_test::scratch_editor_options(folder), and the process tests' run_editor appends a scratch --user-config.