From 75d0bee48da3dbb9bee748cbad70f4126c5ee403 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Thu, 24 Sep 2026 21:17:23 +0000 Subject: [PATCH] Stage recorded edits every frame in a session so each movement reaches peers --- .../portfolio/document/document_history.rs | 19 +++++++++++++++---- .../document/document_message_handler.rs | 10 ++++++++++ .../portfolio/sync/sync_message_handler.rs | 7 +++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/editor/src/messages/portfolio/document/document_history.rs b/editor/src/messages/portfolio/document/document_history.rs index 86336f4885..9c2258e1ef 100644 --- a/editor/src/messages/portfolio/document/document_history.rs +++ b/editor/src/messages/portfolio/document/document_history.rs @@ -140,8 +140,20 @@ impl DocumentHistory { legacy_document: &str, byte_store: &dyn ResourceStorage, ) { + if !self.stage_graph(deltas, interface, registry, byte_store) { + return; + } + + self.persist_view_state(interface, view_settings, legacy_document); + } + + /// The graph half of [`stage_snapshot`](Self::stage_snapshot), without the view state. A session + /// does this every frame, so a peer sees each movement of a drag as its own hot op rather than + /// whatever the autosave timer happened to catch; retirement coarsens them later. Returns whether the + /// working copy is mounted and took the batch. + pub fn stage_graph(&mut self, deltas: &[EditorDelta], interface: &NodeNetworkInterface, registry: &ResourceRegistry, byte_store: &dyn ResourceStorage) -> bool { let needs_whole_document_stage = self.needs_whole_document_stage; - let Some(storage) = self.storage.as_mut() else { return }; + let Some(storage) = self.storage.as_mut() else { return false }; let staged = match needs_whole_document_stage { true => Self::stage_whole_document(storage, interface, registry, byte_store), @@ -159,14 +171,13 @@ impl DocumentHistory { Ok(declarations) => { self.declarations.extend(declarations); self.needs_whole_document_stage = false; + true } Err(error) => { log::error!("Storage snapshot staging failed: {error}"); - return; + false } } - - self.persist_view_state(interface, view_settings, legacy_document); } /// Converts the whole document and stages the difference from what the working copy holds. diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 02da7484cd..066b7de3e4 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -2144,6 +2144,16 @@ impl DocumentMessageHandler { } } + /// Stages what the interface recorded since the last drain, so a session sends each movement in the + /// frame it was made rather than at the next commit or autosave. Nothing else a commit does is done here. + pub(crate) fn stage_pending_edits(&mut self, byte_store: &dyn graph_craft::application_io::resource::ResourceStorage) { + let deltas = self.network_interface.take_deltas(); + if deltas.is_empty() { + return; + } + self.history.stage_graph(&deltas, &self.network_interface, &self.resources.registry, byte_store); + } + /// Brings the interface into line with what peers changed in the registry. Returns whether nothing is /// left pending: a declaration still on its way keeps the changes for a later call. /// diff --git a/editor/src/messages/portfolio/sync/sync_message_handler.rs b/editor/src/messages/portfolio/sync/sync_message_handler.rs index df4c847053..b4ed833475 100644 --- a/editor/src/messages/portfolio/sync/sync_message_handler.rs +++ b/editor/src/messages/portfolio/sync/sync_message_handler.rs @@ -102,10 +102,13 @@ impl MessageHandler> for SyncMessageHandler SyncMessage::Poll => { let resources = resource_storage.resources_mut(); for (&document_id, document) in documents.iter_mut() { - let Some(gdd) = document.storage_mut() else { continue }; - if gdd.role().is_none() { + if document.storage().is_none_or(|gdd| gdd.role().is_none()) { continue; } + // Each movement reaches peers as it happens: what the interface recorded since the last + // frame is staged, and so broadcast, ahead of this frame's poll. + document.stage_pending_edits(&resources); + let Some(gdd) = document.storage_mut() else { continue }; let events = gdd.poll_peers(); // Taken every poll rather than on an event: a refold a hello triggers can leave the