mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-12-01 15:53:26 -10:00
Stage recorded edits every frame in a session so each movement reaches peers
This commit is contained in:
1 parent
b12b692a2d
commit
75d0bee48d
3 files changed
+30
-6
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
///
|
||||
|
||||
@@ -102,10 +102,13 @@ impl MessageHandler<SyncMessage, SyncMessageContext<'_>> 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
|
||||
|
||||
Reference in new issue
Block a user