Editor → Commands and Undo → command_dispatcher.h
command_dispatcher
| Type | Class |
| Namespace | conjure::editor |
| Include File Path | engine/include/conjure/editor/command_dispatcher.h |
| Source File Path | engine/src/editor/core/command_dispatcher.cpp |
| API ↗ | Headless mode and the command model, The editor |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | command_dispatcher(
editor_context &context,
command_registry ®istry,
undo_stack &undo); |
Important
Copy constructor and assignment has been deleted.
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~command_dispatcher(); |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| public | DEFAULT_ | static constexpr f64 | 120.0 | |
| public | DEFAULT_ | static constexpr u32 | 8 | |
| private | m | f64 | DEFAULT_ | |
| private | mBatch | batch_state * | nullptr | |
| private | mClock | const core::clock * | nullptr | |
| private | mCompleted | std:: | {} | |
| private | mContext | editor_context * | nullptr | |
| private | m | u64 | 0 | |
| private | m | u32 | DEFAULT_ | |
| private | mNextTicket | u64 | 1 | |
| private | m | core:: | {} | |
| private | mPending | std:: | {} | |
| private | mRegistry | command_registry * | nullptr | |
| private | m | u32 | 0 | |
| private | m | u32 | 0 | |
| private | m | std:: | std::nullopt | |
| private | mUndo | undo_stack * | nullptr |
Functions
Public
async_timeout_seconds
async_timeout_seconds[[nodiscard]] f64 async_timeout_seconds() const noexcept;cancel_all
cancel_allvoid cancel_all(
protocol_error_code code,
std::string_view message);Completes every pending request with the given error (CANCELLED when the engine restarts or shuts down); the responses are delivered by the next resolve_completed().
cancel_client
cancel_clientvoid cancel_client(
u32 clientId);Drops the pending requests of a disconnected client (CANCELLED, logged) and commits its open transaction.
complete
completevoid complete(
u64 ticket,
protocol_response response);Completes a parked request (called by async_reply). A failure of client 0 (the UI, which does not wait for its answers) is logged as a WARN naming the command.
complete_mutation
complete_mutationvoid complete_mutation(
u64 ticket,
command_outcome outcome);Completes the parked request of an ASYNC | MUTATES command with its outcome (called by async_reply::succeed_mutation): records it the way a synchronous mutation is recorded at dispatch, with the request's args, client and coalesce key (the undo stack, the client's transaction, the running batch, or the play controller while frozen), marks the scene dirty unless NO_UNDO and, outside an undo or redo step, bumps the revision, sets result.revision and emits scene.changed. A completion inside the handler (a batch child, a replay) is recorded under the state it runs in. Asserted: the ticket is pending and its command is MUTATES.
dispatch
dispatch[[nodiscard]] std::optional<protocol_response> dispatch(
const protocol_request &request);Validates and executes one request. Returns the response, or nullopt when the command is asynchronous and will answer through resolve_completed() later. A known command the client's token does not open (required_access(flags) above what protocol_server::access_of_client reports) answers UNAUTHORISED with details {required, granted} before its arguments are validated; the client stays connected. Every request of a transport client, refused ones and unknown commands included, is handed to protocol_server::record_command once it was dispatched; so is every child of an editor.batch.
dispatch_inverses
dispatch_inverses[[nodiscard]] core::result<void> dispatch_inverses(
std::span<const command_inverse> inverses,
u32 clientId);Dispatches recorded inverses or replays with undo recording suppressed (history.undo/redo). The commands neither bump the revision nor emit scene.changed: the history command does both once per step.
dispatch_replays
dispatch_replays[[nodiscard]] core::result<void> dispatch_replays(
std::span<const command_request> replays,
u32 clientId);exceeds_pending_limit
exceeds_pending_limit[[nodiscard]] bool exceeds_pending_limit(
u32 clientId) const noexcept;True when the client has more parked requests than max_pending_per_client(). Inside an ASYNC handler the request being dispatched is parked already and counts.
execute
execute[[nodiscard]] core::result<core::json::document> execute(
const command_request &request);UI convenience: dispatches from client 0 and returns the result object or the error (the error's code is the protocol code). An asynchronous command answers through on_local_response; when such a reply of client 0 fails, complete() also logs a WARN "ui: <command> failed: <message>".
in_batch
in_batch[[nodiscard]] bool in_batch() const noexcept;True while a batch runs (nested batches are refused).
is_pending
is_pending[[nodiscard]] bool is_pending(
u64 ticket) const noexcept;True while the ticket is parked and not completed.
max_pending_per_client
max_pending_per_client[[nodiscard]] u32 max_pending_per_client() const noexcept;on_local_response
on_local_response[[nodiscard]] core::event<const protocol_response &> &on_local_response() noexcept;Responses of asynchronous commands issued by client 0 (the UI).
pending_count
pending_count[[nodiscard]] usize pending_count() const noexcept;replaying
replaying[[nodiscard]] bool replaying() const noexcept;True while history.undo / redo or a batch rollback dispatch recorded inverses and replays. Handlers use it to accept values a client may not send but an earlier state legitimately held (a legacy entity name restored by undo).
requires_synchronous_completion
requires_synchronous_completion[[nodiscard]] bool requires_synchronous_completion() const noexcept;True while a request dispatched now must answer before its handler returns: inside a batch (its children are recorded into one entry and rolled back together), an undo or redo step and a batch rollback (replaying()). A SYNC_IN_BATCH handler checks it and completes its reply synchronously; an ASYNC handler that does not is answered with INTERNAL and its reply is dropped.
resolve_completed
resolve_completedvoid resolve_completed(
std::vector<protocol_response> &outResponses);Moves the responses of completed and timed-out asynchronous requests into outResponses.
rollback_steps
rollback_stepsvoid rollback_steps(
undo_entry &entry,
usize first);Takes back the steps of entry from index first on, newest first: their inverses run without being recorded (a failure is logged), and the pairs leave the entry. The rollback of a run_step() sequence.
run_batch
run_batch[[nodiscard]] core::result<std::vector<protocol_response>> run_batch(
const core::json::value &commands,
std::string_view label,
bool atomic,
u32 clientId,
core::json::document &outDetails);Runs the children of editor.batch (docs 3.4): one undo entry, atomic rollback through the recorded inverses on a failure. Returns the children's responses; the error of the failing child with details.failedIndex when atomic.
run_step
run_step[[nodiscard]] core::result<core::json::document> run_step(
const command_request &request,
undo_entry &entry);Runs one request as a step of an undo entry the caller assembles (play-mode persist at play.stop): it runs like an editor.batch child (validation, preconditions, revision and scene.changed), and its undo pair is appended to entry instead of reaching the undo stack or a transaction. Returns the result, or the request's error with nothing appended. INVALID_ARGS inside a running batch and for a command that may not run inside one (NOT_IN_BATCH, ASYNC).
set_async_timeout_seconds
set_async_timeout_secondsvoid set_async_timeout_seconds(
f64 seconds) noexcept;set_clock
set_clockvoid set_clock(
const core::clock *clock) noexcept;The clock deadlines are measured with (the engine's clock by default).
set_max_pending_per_client
set_max_pending_per_clientvoid set_max_pending_per_client(
u32 count) noexcept;The most requests one client may leave parked. An ASYNC request beyond it answers BUSY, except one that must complete inside its handler (requires_synchronous_completion()), which cannot stay parked and is never refused. A SYNC_IN_BATCH request may also finish inside its handler elsewhere (a prefab that is already loaded), so it is counted only when its handler leaves it parked: the dispatcher answers BUSY then and drops its reply, and the handler checks exceeds_pending_limit() before it starts waiting, so it can refuse with nothing changed.
Private
access_of_client
access_of_client[[nodiscard]] access_level access_of_client(
u32 clientId) const noexcept;audit
auditvoid audit(
const protocol_request &request,
const std::optional<protocol_response> &response,
bool batchChild) const;check_preconditions
check_preconditions[[nodiscard]] std::optional<protocol_error_code> check_preconditions(
const command_descriptor &descriptor,
core::json::document &details) const;conclude_mutation
conclude_mutation[[nodiscard]] protocol_response conclude_mutation(
command_flags flags,
const protocol_request &request,
command_outcome &outcome);dispatch_internal
dispatch_internal[[nodiscard]] std::optional<protocol_response> dispatch_internal(
const protocol_request &request);keep_play_edits
keep_play_editsvoid keep_play_edits(
batch_state &batch);note_touched
note_touchedvoid note_touched(
const command_outcome &outcome,
std::vector<core::uuid> &outTouched) const;now_seconds
now_seconds[[nodiscard]] f64 now_seconds() const noexcept;record_outcome
record_outcomevoid record_outcome(
command_flags flags,
const protocol_request &request,
command_outcome &outcome);