Skip to content

Editor

Commands and Undo

Command registration, validation, dispatch, references, and undo history.

Headers

File Description Provides
builtin_commands.h The built-in command catalogue: every command of the session, editor, history, console, project, scene, entity, component, asset, prefab, script, play, input, view, physics, selection, reflection, module and profiler groups. Implementations live in engine/src/editor/core/commands/commands_<group>.cpp, one free function per command plus its schema.
command_desc.h One command a module exports. Strings may point at module literals: the consumer copies what it keeps. command_desc
command_dispatcher.h The one execution path: the scope of the client's token, schema validation, preconditions, the handler, undo recording, revision bump, events and the audit record, for every source of commands. While playing the undo stack is frozen: a scene edit is executed and not recorded, an ON_DISK command's inverse goes to the play controller, which makes one undo entry of them at play.stop. Asynchronous handlers park their request and answer through async_reply; resolve_completed() hands the finished responses back once per frame and times the stale ones out. An asynchronous command that changes the scene (ASYNC | MUTATES) is recorded, dirties the scene, bumps the revision and emits scene.changed when it completes, not when it is dispatched; inside a batch, an undo or redo step or a rollback it must complete inside its handler (SYNC_IN_BATCH). Only a request left parked counts toward a client's cap of pending requests (BUSY beyond it): one that must complete inside its handler is never refused for it. Main thread only. command_dispatcher
command_dispatcher::batch_state
command_dispatcher::pending_request
command_registry.h The command catalogue: descriptors by name with their compiled argument schemas, the self-description editor.schema returns and the hash session.hello reports. Main thread only; module.load adds commands at runtime and module.unload removes them by owner. command_registry
command_registry::entry
editor_command.h Commands are data. Every mutation of the editor, whether it comes from a panel, a protocol client, an --exec file or the undo stack, is a command_request handed to the command_dispatcher. A mutating handler returns the inverse request that undoes it and, when the forward request is not deterministic (assigned guids), a normalised replay request for redo. async_reply
command_descriptor
command_inverse
command_invocation
command_outcome
command_request
entity_ref.h Entity addressing: a protocol argument names an entity by guid (a uuid string) or by hierarchy path ("Root/Child/Leaf"); ecs::entity ids never cross the protocol. Responses always carry guids. entity_ref
reflection_path.h Property paths: "transform.position.x", "materials[1]", "script.fields.speed". The first segment names the component type (resolved by the command through the component registry), the rest walks the component's reflection description down to one value. Values move through JSON only: the component is serialised with ecs::component_to_json, patched at the JSON pointer the path resolves to, and written back with ecs::component_from_json. field_ref
path_segment
reflection_path
schema_validator.h The hand-written JSON Schema subset: type (one name or an array of names), properties, required, additionalProperties (default false at the top level of a command's args, true below), items, enum, minimum, maximum, minItems, maxItems, oneOf (shallow), plus the documentation keywords description, title and default. Any other keyword fails compilation, so a typo in a descriptor is caught at registration rather than silently accepted. compiled_schema
undo_stack.h Undo as inverse commands. An entry holds the inverses (applied in reverse by history.undo) and the replays (applied forwards by history.redo); the dispatcher records one entry per mutating command, or appends to the client's open transaction / the running batch. Depth 1024, 256 MiB of serialised arguments (oldest evicted first), coalescing of drag-style edits, frozen during play. transaction_scope
undo_entry
undo_stack

Breakdown

Command descriptors identify operations and their requirements. command_registry owns registrations, schema_validator validates arguments, and command_dispatcher checks command requirements before invoking handlers. builtin_commands registers the operations supplied with the editor.

entity_ref and reflection_path address entities and reflected properties. Mutating commands return inverse operations that undo_stack records; transactions and coalescing combine related edits into useful undo steps. The same command model serves the graphical interface and remote or headless clients.

See Editor Architecture for dispatch, failure handling, transactions, coalescing, and play-mode undo.