From 752df128e308a3889e1c25d2534070cb35c1ea5d Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sun, 13 Aug 2023 12:25:42 +0200 Subject: [PATCH] Don't include the document node path in the stable node id by default (#1388) * Don't include the document node path in the stable node id by default Make the inclusion of the document path for the stable node id optional and only enable it for the MonitorNode for now * Fix tests --- .../document_node_types.rs | 2 ++ node-graph/gcore/src/types.rs | 2 ++ node-graph/graph-craft/src/document.rs | 6 +++++ node-graph/graph-craft/src/imaginate_input.rs | 1 + node-graph/graph-craft/src/proto.rs | 26 +++++++++++++------ 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs index 3810d201..b822afd1 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler/document_node_types.rs @@ -207,6 +207,7 @@ fn static_nodes() -> Vec { DocumentNode { inputs: vec![NodeInput::node(0, 0)], implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode<_>"), + skip_deduplication: true, ..Default::default() }, ), @@ -1986,6 +1987,7 @@ pub static IMAGINATE_NODE: Lazy = Lazy::new(|| DocumentNodeTyp name: "Frame Monitor".into(), inputs: vec![NodeInput::Network(concrete!(ImageFrame))], implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode<_>"), + skip_deduplication: true, ..Default::default() }, ), diff --git a/node-graph/gcore/src/types.rs b/node-graph/gcore/src/types.rs index cff34f7b..2bcbc852 100644 --- a/node-graph/gcore/src/types.rs +++ b/node-graph/gcore/src/types.rs @@ -77,7 +77,9 @@ pub struct TypeDescriptor { #[specta(skip)] pub id: Option, pub name: Cow<'static, str>, + #[serde(default)] pub size: usize, + #[serde(default)] pub align: usize, } diff --git a/node-graph/graph-craft/src/document.rs b/node-graph/graph-craft/src/document.rs index bcece0f3..adffdb00 100644 --- a/node-graph/graph-craft/src/document.rs +++ b/node-graph/graph-craft/src/document.rs @@ -40,6 +40,8 @@ pub struct DocumentNode { pub inputs: Vec, pub implementation: DocumentNodeImplementation, pub metadata: DocumentNodeMetadata, + #[serde(default)] + pub skip_deduplication: bool, pub path: Option>, } @@ -97,6 +99,7 @@ impl DocumentNode { input, construction_args: args, document_node_path: self.path.unwrap_or(Vec::new()), + skip_deduplication: self.skip_deduplication, } } else { unreachable!("tried to resolve not flattened node on resolved node {:?}", self); @@ -1063,6 +1066,7 @@ mod test { input: ProtoNodeInput::Network(concrete!(u32)), construction_args: ConstructionArgs::Nodes(vec![(0, false)]), document_node_path: vec![], + skip_deduplication: false, }; assert_eq!(proto_node, reference); } @@ -1080,6 +1084,7 @@ mod test { input: ProtoNodeInput::Network(concrete!(u32)), construction_args: ConstructionArgs::Nodes(vec![(14, false)]), document_node_path: vec![1, 0], + skip_deduplication: false, }, ), ( @@ -1089,6 +1094,7 @@ mod test { input: ProtoNodeInput::Node(10, false), construction_args: ConstructionArgs::Nodes(vec![]), document_node_path: vec![1, 1], + skip_deduplication: false, }, ), (14, ProtoNode::value(ConstructionArgs::Value(TaggedValue::U32(2)), vec![1, 4])), diff --git a/node-graph/graph-craft/src/imaginate_input.rs b/node-graph/graph-craft/src/imaginate_input.rs index bd73e04a..dffe4235 100644 --- a/node-graph/graph-craft/src/imaginate_input.rs +++ b/node-graph/graph-craft/src/imaginate_input.rs @@ -36,6 +36,7 @@ pub trait ImaginateTerminationHandle: Debug + Send + Sync + 'static { #[derive(Default, Debug, specta::Type)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] struct InternalImaginateControl { + #[serde(skip)] status: Mutex, trigger_regenerate: AtomicBool, #[serde(skip)] diff --git a/node-graph/graph-craft/src/proto.rs b/node-graph/graph-craft/src/proto.rs index 8e7ed598..66951823 100644 --- a/node-graph/graph-craft/src/proto.rs +++ b/node-graph/graph-craft/src/proto.rs @@ -190,12 +190,13 @@ impl ConstructionArgs { } #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Debug, PartialEq, Clone, Hash, Eq)] +#[derive(Debug, Clone, PartialEq, Hash, Eq)] pub struct ProtoNode { pub construction_args: ConstructionArgs, pub input: ProtoNodeInput, pub identifier: NodeIdentifier, pub document_node_path: Vec, + pub skip_deduplication: bool, } /// A ProtoNodeInput represents the input of a node in a ProtoNetwork. @@ -231,7 +232,9 @@ impl ProtoNode { self.identifier.name.hash(&mut hasher); self.construction_args.hash(&mut hasher); - self.document_node_path.hash(&mut hasher); + if self.skip_deduplication { + self.document_node_path.hash(&mut hasher); + } std::mem::discriminant(&self.input).hash(&mut hasher); match self.input { ProtoNodeInput::None => (), @@ -252,6 +255,7 @@ impl ProtoNode { construction_args: value, input: ProtoNodeInput::None, document_node_path: path, + skip_deduplication: false, } } @@ -359,6 +363,7 @@ impl ProtoNetwork { construction_args: ConstructionArgs::Nodes(vec![(input_node_id, false), (node_id, true)]), input, document_node_path: path, + skip_deduplication: false, }, )); @@ -735,12 +740,12 @@ mod test { assert_eq!( ids, vec![ - 16203111412429166836, - 8181436982058796771, - 10130798762907147404, - 1082623390433068677, - 4567264975997576294, - 8215587082195034469 + 2785293541695324513, + 12994980551665119079, + 17926586814106640907, + 2523412932923113119, + 12965978620570332342, + 16191561097939296982 ] ); } @@ -757,6 +762,7 @@ mod test { input: ProtoNodeInput::Node(11, false), construction_args: ConstructionArgs::Nodes(vec![]), document_node_path: vec![], + skip_deduplication: false, }, ), ( @@ -766,6 +772,7 @@ mod test { input: ProtoNodeInput::Node(11, false), construction_args: ConstructionArgs::Nodes(vec![]), document_node_path: vec![], + skip_deduplication: false, }, ), ( @@ -775,6 +782,7 @@ mod test { input: ProtoNodeInput::Network(concrete!(u32)), construction_args: ConstructionArgs::Nodes(vec![(14, false)]), document_node_path: vec![], + skip_deduplication: false, }, ), ( @@ -784,6 +792,7 @@ mod test { input: ProtoNodeInput::Node(10, false), construction_args: ConstructionArgs::Nodes(vec![]), document_node_path: vec![], + skip_deduplication: false, }, ), ( @@ -793,6 +802,7 @@ mod test { input: ProtoNodeInput::None, construction_args: ConstructionArgs::Value(value::TaggedValue::U32(2)), document_node_path: vec![], + skip_deduplication: false, }, ), ]