Skip to content

Commit 19cb1ef

Browse files
committed
Store cached transforms upon the document
1 parent bc5a7cf commit 19cb1ef

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

document-legacy/src/document_metadata.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use graph_craft::document::{NodeId, NodeNetwork};
66

77
#[derive(Debug, Clone)]
88
pub struct DocumentMetadata {
9-
transforms: HashMap<NodeId, DAffine2>,
9+
transforms: HashMap<LayerNodeIdentifier, DAffine2>,
1010
structure: HashMap<LayerNodeIdentifier, NodeRelations>,
1111
}
1212

@@ -29,13 +29,16 @@ impl DocumentMetadata {
2929
fn get_structure_mut(&mut self, node_identifier: LayerNodeIdentifier) -> &mut NodeRelations {
3030
self.structure.entry(node_identifier).or_default()
3131
}
32+
pub fn update_transforms(&mut self, new_transforms: HashMap<LayerNodeIdentifier, DAffine2>) {
33+
self.transforms = new_transforms;
34+
}
3235
}
3336

3437
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
3538
pub struct LayerNodeIdentifier(NonZeroU64);
3639
impl LayerNodeIdentifier {
3740
const ROOT: Self = LayerNodeIdentifier::new_unchecked(0);
38-
const fn new_unchecked(node_id: NodeId) -> Self {
41+
pub const fn new_unchecked(node_id: NodeId) -> Self {
3942
// Safety: will always be >=1
4043
Self(unsafe { NonZeroU64::new_unchecked(node_id + 1) })
4144
}

editor/src/messages/portfolio/portfolio_message_handler.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,12 @@ impl PortfolioMessageHandler {
667667
}
668668

669669
pub fn poll_node_graph_evaluation(&mut self, responses: &mut VecDeque<Message>) {
670-
let transform = self.active_document().map(|document| document.document_legacy.root.transform).unwrap_or(DAffine2::IDENTITY);
671-
self.executor.poll_node_graph_evaluation(transform, responses).unwrap_or_else(|e| {
670+
let Some(active_document) = self.active_document_id.and_then(|id| self.documents.get_mut(&id)) else {
671+
warn!("Polling node graph with no document");
672+
return;
673+
};
674+
675+
self.executor.poll_node_graph_evaluation(&mut active_document.document_legacy, responses).unwrap_or_else(|e| {
672676
log::error!("Error while evaluating node graph: {}", e);
673677
});
674678
}

editor/src/node_graph_executor.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use crate::messages::frontend::utility_types::FrontendImageData;
2-
use crate::messages::portfolio::document::node_graph::wrap_network_in_scope;
2+
use crate::messages::portfolio::document::node_graph::{wrap_network_in_scope, LayerIdentifier};
33
use crate::messages::portfolio::document::utility_types::misc::{LayerMetadata, LayerPanelEntry};
44
use crate::messages::portfolio::utility_types::PersistentData;
55
use crate::messages::prelude::*;
66

7+
use document_legacy::document::Document as DocumentLegacy;
8+
use document_legacy::document_metadata::LayerNodeIdentifier;
79
use document_legacy::layers::layer_info::{LayerDataType, LayerDataTypeDiscriminant};
810
use document_legacy::{LayerId, Operation};
911

@@ -19,7 +21,7 @@ use graphene_core::text::FontCache;
1921
use graphene_core::transform::Transform;
2022
use graphene_core::vector::style::ViewMode;
2123

22-
use graphene_core::{Color, SurfaceFrame, SurfaceId};
24+
use graphene_core::{Color, NodeIdentifier, SurfaceFrame, SurfaceId};
2325
use graphene_std::wasm_application_io::{WasmApplicationIo, WasmEditorApi};
2426
use interpreted_executor::dynamic_executor::DynamicExecutor;
2527

@@ -77,8 +79,8 @@ pub(crate) struct GenerationResponse {
7779
result: Result<TaggedValue, String>,
7880
updates: VecDeque<Message>,
7981
new_thumbnails: HashMap<NodeId, SvgSegmentList>,
80-
new_click_targets: HashMap<NodeId, Vec<ClickTarget>>,
81-
new_transforms: HashMap<NodeId, DAffine2>,
82+
new_click_targets: HashMap<LayerNodeIdentifier, Vec<ClickTarget>>,
83+
new_transforms: HashMap<LayerNodeIdentifier, DAffine2>,
8284
}
8385

8486
enum NodeGraphUpdate {
@@ -157,8 +159,8 @@ impl NodeRuntime {
157159
result,
158160
updates: responses,
159161
new_thumbnails: self.thumbnails.clone(),
160-
new_click_targets: self.click_targets.clone(),
161-
new_transforms: self.transforms.clone(),
162+
new_click_targets: self.click_targets.clone().into_iter().map(|(id, targets)| (LayerNodeIdentifier::new_unchecked(id), targets)).collect(),
163+
new_transforms: self.transforms.clone().into_iter().map(|(id, transform)| (LayerNodeIdentifier::new_unchecked(id), transform)).collect(),
162164
};
163165
self.sender.send_generation_response(response);
164166
}
@@ -460,7 +462,7 @@ impl NodeGraphExecutor {
460462
Ok(())
461463
}
462464

463-
pub fn poll_node_graph_evaluation(&mut self, transform: DAffine2, responses: &mut VecDeque<Message>) -> Result<(), String> {
465+
pub fn poll_node_graph_evaluation(&mut self, document: &mut DocumentLegacy, responses: &mut VecDeque<Message>) -> Result<(), String> {
464466
let results = self.receiver.try_iter().collect::<Vec<_>>();
465467
for response in results {
466468
match response {
@@ -473,10 +475,11 @@ impl NodeGraphExecutor {
473475
new_transforms,
474476
}) => {
475477
self.thumbnails = new_thumbnails;
478+
document.metadata.update_transforms(new_transforms);
476479
let node_graph_output = result.map_err(|e| format!("Node graph evaluation failed: {:?}", e))?;
477480
let execution_context = self.futures.remove(&generation_id).ok_or_else(|| "Invalid generation ID".to_string())?;
478481
responses.extend(updates);
479-
self.process_node_graph_output(node_graph_output, execution_context.layer_path.clone(), transform, responses, execution_context.document_id)?;
482+
self.process_node_graph_output(node_graph_output, execution_context.layer_path.clone(), responses, execution_context.document_id)?;
480483
responses.add(DocumentMessage::LayerChanged {
481484
affected_layer_path: execution_context.layer_path,
482485
});
@@ -495,7 +498,7 @@ impl NodeGraphExecutor {
495498
Ok(())
496499
}
497500

498-
fn process_node_graph_output(&mut self, node_graph_output: TaggedValue, layer_path: Vec<LayerId>, _transform: DAffine2, responses: &mut VecDeque<Message>, document_id: u64) -> Result<(), String> {
501+
fn process_node_graph_output(&mut self, node_graph_output: TaggedValue, layer_path: Vec<LayerId>, responses: &mut VecDeque<Message>, document_id: u64) -> Result<(), String> {
499502
self.last_output_type.insert(layer_path.clone(), Some(node_graph_output.ty()));
500503
match node_graph_output {
501504
TaggedValue::VectorData(vector_data) => {

0 commit comments

Comments
 (0)