From 283306f225eba22f7b50674259309ff877b48fba Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Tue, 18 Mar 2025 22:20:50 +0100 Subject: [PATCH] Minor cleanup and added comments. --- src/AnimGraph/AnimGraphBlendTree.h | 2 +- src/AnimGraph/AnimGraphResource.cc | 130 +++++++++++++++-------------- src/AnimGraph/AnimGraphResource.h | 4 +- 3 files changed, 71 insertions(+), 65 deletions(-) diff --git a/src/AnimGraph/AnimGraphBlendTree.h b/src/AnimGraph/AnimGraphBlendTree.h index f3d440b..c4d787e 100644 --- a/src/AnimGraph/AnimGraphBlendTree.h +++ b/src/AnimGraph/AnimGraphBlendTree.h @@ -108,7 +108,7 @@ struct AnimGraphBlendTree : public AnimNode { */ template void SetInput(const char* name, T* value_ptr) { - m_node_descriptor->SetOutput(name, value_ptr); + m_node_descriptor->SetInput(name, value_ptr); std::vector connected_node_indices; diff --git a/src/AnimGraph/AnimGraphResource.cc b/src/AnimGraph/AnimGraphResource.cc index c4b0bf3..75b8c3e 100644 --- a/src/AnimGraph/AnimGraphResource.cc +++ b/src/AnimGraph/AnimGraphResource.cc @@ -933,9 +933,9 @@ void BlendTreeResource::CreateBlendTreeRuntimeNodeInstances( embedded_blend_tree_resource->CreateBlendTreeInstance( *embedded_blend_tree); embedded_blend_tree_resource->m_virtual_socket_accessor->m_inputs = - embedded_blend_tree->m_node_descriptor->m_outputs; - embedded_blend_tree_resource->m_virtual_socket_accessor->m_outputs = embedded_blend_tree->m_node_descriptor->m_inputs; + embedded_blend_tree_resource->m_virtual_socket_accessor->m_outputs = + embedded_blend_tree->m_node_descriptor->m_outputs; } node->m_name = node_resource->m_name; @@ -955,9 +955,9 @@ void BlendTreeResource::PrepareBlendTreeIOData( AnimNodeDescriptorFactory("BlendTree", instance.m_nodes[0]); instance.m_node_descriptor->m_outputs = - GetGraphInputNode()->m_virtual_socket_accessor->m_outputs; - instance.m_node_descriptor->m_inputs = GetGraphOutputNode()->m_virtual_socket_accessor->m_inputs; + instance.m_node_descriptor->m_inputs = + GetGraphInputNode()->m_virtual_socket_accessor->m_outputs; // // graph inputs @@ -1004,7 +1004,12 @@ void BlendTreeResource::PrepareBlendTreeIOData( } // - // connecton data storage + // connection data storage: we reserve memory for the used outputs of all + // nodes: + // * If a node output does not get used: we do not reserve a memory block. + // * If a node output gets used by multiple nodes: we only reserve a single + // memory block. + // The resulting memory offsets are stored in the node_offset_map. // size_t connection_data_storage_size = 0; for (const BlendTreeConnectionResource& connection : GetConnections()) { @@ -1028,6 +1033,61 @@ void BlendTreeResource::PrepareBlendTreeIOData( } } +void BlendTreeResource::SetRuntimeNodeProperties( + AnimGraphBlendTree& result) const { + for (int i = 2; i < GetNumNodes(); i++) { + const AnimNodeResource* node_resource = GetNode(i); + + NodeDescriptorBase* node_instance_accessor = AnimNodeDescriptorFactory( + node_resource->m_node_type_name, + result.m_nodes[i]); + + std::vector& resource_properties = + node_resource->m_virtual_socket_accessor->m_properties; + for (const auto& property : resource_properties) { + const std::string& name = property.m_name; + + switch (property.m_type) { + case SocketType::SocketTypeBool: + node_instance_accessor->SetProperty( + name.c_str(), + property.m_value.flag); + break; + case SocketType::SocketTypeInt: + node_instance_accessor->SetProperty( + name.c_str(), + property.m_value.int_value); + break; + case SocketType::SocketTypeFloat: + node_instance_accessor->SetProperty( + name.c_str(), + property.m_value.float_value); + break; + case SocketType::SocketTypeVec3: + node_instance_accessor->SetProperty( + name.c_str(), + property.m_value.vec3); + break; + case SocketType::SocketTypeQuat: + node_instance_accessor->SetProperty( + name.c_str(), + property.m_value.quat); + break; + case SocketType::SocketTypeString: + node_instance_accessor->SetProperty( + name.c_str(), + property.m_value_string); + break; + default: + std::cerr << "Invalid socket type " + << static_cast(property.m_type) << std::endl; + } + } + + delete node_instance_accessor; + } +} + void BlendTreeResource::CreateBlendTreeConnectionInstances( AnimGraphBlendTree& instance, NodeSocketDataOffsetMap& node_offset_map) const { @@ -1047,9 +1107,10 @@ void BlendTreeResource::CreateBlendTreeConnectionInstances( } } - instance_node_descriptors[0]->m_inputs = instance.m_node_descriptor->m_inputs; - instance_node_descriptors[1]->m_outputs = + instance_node_descriptors[0]->m_inputs = instance.m_node_descriptor->m_outputs; + instance_node_descriptors[1]->m_outputs = + instance.m_node_descriptor->m_inputs; for (const BlendTreeConnectionResource& connection : GetConnections()) { NodeDescriptorBase* source_node_descriptor = @@ -1236,59 +1297,4 @@ void BlendTreeResource::CreateBlendTreeConnectionInstances( } } -void BlendTreeResource::SetRuntimeNodeProperties( - AnimGraphBlendTree& result) const { - for (int i = 2; i < GetNumNodes(); i++) { - const AnimNodeResource* node_resource = GetNode(i); - - NodeDescriptorBase* node_instance_accessor = AnimNodeDescriptorFactory( - node_resource->m_node_type_name, - result.m_nodes[i]); - - std::vector& resource_properties = - node_resource->m_virtual_socket_accessor->m_properties; - for (const auto& property : resource_properties) { - const std::string& name = property.m_name; - - switch (property.m_type) { - case SocketType::SocketTypeBool: - node_instance_accessor->SetProperty( - name.c_str(), - property.m_value.flag); - break; - case SocketType::SocketTypeInt: - node_instance_accessor->SetProperty( - name.c_str(), - property.m_value.int_value); - break; - case SocketType::SocketTypeFloat: - node_instance_accessor->SetProperty( - name.c_str(), - property.m_value.float_value); - break; - case SocketType::SocketTypeVec3: - node_instance_accessor->SetProperty( - name.c_str(), - property.m_value.vec3); - break; - case SocketType::SocketTypeQuat: - node_instance_accessor->SetProperty( - name.c_str(), - property.m_value.quat); - break; - case SocketType::SocketTypeString: - node_instance_accessor->SetProperty( - name.c_str(), - property.m_value_string); - break; - default: - std::cerr << "Invalid socket type " - << static_cast(property.m_type) << std::endl; - } - } - - delete node_instance_accessor; - } -} - #pragma clang diagnostic pop diff --git a/src/AnimGraph/AnimGraphResource.h b/src/AnimGraph/AnimGraphResource.h index edf9fb0..f102574 100644 --- a/src/AnimGraph/AnimGraphResource.h +++ b/src/AnimGraph/AnimGraphResource.h @@ -375,12 +375,12 @@ struct BlendTreeResource : AnimGraphResource { AnimGraphBlendTree& instance, NodeSocketDataOffsetMap& node_offset_map) const; + void SetRuntimeNodeProperties(AnimGraphBlendTree& result) const; + void CreateBlendTreeConnectionInstances( AnimGraphBlendTree& instance, NodeSocketDataOffsetMap& node_offset_map) const; - void SetRuntimeNodeProperties(AnimGraphBlendTree& result) const; - void InitGraphConnectors() { AddNode(AnimNodeResourceFactory("BlendTreeSockets")); AnimNodeResource* output_node = GetGraphOutputNode();