mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
Add the "memoize" attribute to the node macro (#4065)
* Add memoization attribute to node macro * Fix memoization insertion for networks without conversion nodes
This commit is contained in:
@@ -42,7 +42,7 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
|
||||
for (id, metadata) in core_types::registry::NODE_METADATA.lock().unwrap().iter() {
|
||||
let id = id.clone();
|
||||
|
||||
let NodeMetadata { fields, .. } = metadata;
|
||||
let NodeMetadata { fields, memoize, .. } = metadata;
|
||||
let Some(implementations) = node_registry.get(&id) else { continue };
|
||||
let valid_call_args: HashSet<_> = implementations.iter().map(|(_, node_io)| node_io.call_argument.clone()).collect();
|
||||
let first_node_io = implementations.first().map(|(_, node_io)| node_io).unwrap_or(const { &NodeIOTypes::empty() });
|
||||
@@ -111,7 +111,7 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
|
||||
})
|
||||
.collect();
|
||||
|
||||
if generated_nodes == 0 {
|
||||
if generated_nodes == 0 && !memoize {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -127,12 +127,27 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
|
||||
|
||||
nodes.insert(NodeId(input_count as u64), document_node);
|
||||
|
||||
// If memoize is requested, append a Memo node after the main node and redirect the export through it
|
||||
let export_node_id = if *memoize {
|
||||
let memo_node_id = NodeId(input_count as u64 + 1);
|
||||
let memo_node = DocumentNode {
|
||||
inputs: vec![NodeInput::node(NodeId(input_count as u64), 0)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode(graphene_core::memo::memo::IDENTIFIER.clone()),
|
||||
visible: true,
|
||||
..Default::default()
|
||||
};
|
||||
nodes.insert(memo_node_id, memo_node);
|
||||
memo_node_id
|
||||
} else {
|
||||
NodeId(input_count as u64)
|
||||
};
|
||||
|
||||
let node = DocumentNode {
|
||||
inputs,
|
||||
call_argument: input_type.clone(),
|
||||
implementation: DocumentNodeImplementation::Network(NodeNetwork {
|
||||
exports: vec![NodeInput::Node {
|
||||
node_id: NodeId(input_count as u64),
|
||||
node_id: export_node_id,
|
||||
output_index: 0,
|
||||
}],
|
||||
nodes,
|
||||
|
||||
Reference in New Issue
Block a user