WIP: graph evaluations. Fixed various memory issues, better tests.
This commit is contained in:
@@ -146,10 +146,12 @@ AnimNodeResource sAnimGraphNodeFromJson(const json& json_node) {
|
||||
size_t string_length = value_str.size();
|
||||
constexpr size_t string_max_length = sizeof(property.m_value.str) - 1;
|
||||
if (string_length > string_max_length) {
|
||||
std::cerr << "Warning: string '" << value_str << "' too long, truncating to " << string_max_length << " bytes." << std::endl;
|
||||
std::cerr << "Warning: string '" << value_str
|
||||
<< "' too long, truncating to " << string_max_length
|
||||
<< " bytes." << std::endl;
|
||||
string_length = string_max_length;
|
||||
}
|
||||
memcpy (property.m_value.str, value_str.data(), string_length);
|
||||
memcpy(property.m_value.str, value_str.data(), string_length);
|
||||
property.m_value.str[string_length] = 0;
|
||||
} else {
|
||||
std::cerr << "Invalid type for property '" << property.m_name
|
||||
@@ -404,7 +406,7 @@ void AnimGraphResource::prepareGraphIOData(AnimGraph& instance) const {
|
||||
int output_block_offset = 0;
|
||||
for (int i = 0; i < graph_outputs.size(); i++) {
|
||||
graph_outputs[i].m_reference.ptr =
|
||||
(void*)&instance.m_output_buffer[output_block_offset];
|
||||
&instance.m_output_buffer[output_block_offset];
|
||||
output_block_offset += graph_outputs[i].m_type_size;
|
||||
}
|
||||
}
|
||||
@@ -524,29 +526,41 @@ void AnimGraphResource::setRuntimeNodeProperties(AnimGraph& instance) const {
|
||||
NodeSocketAccessorBase* node_instance_accessor =
|
||||
AnimNodeAccessorFactory(node_resource.m_type_name, instance.m_nodes[i]);
|
||||
|
||||
std::vector<Socket>& resource_properties = node_resource.m_socket_accessor->m_properties;
|
||||
std::vector<Socket>& resource_properties =
|
||||
node_resource.m_socket_accessor->m_properties;
|
||||
for (size_t j = 0, n = resource_properties.size(); j < n; j++) {
|
||||
const Socket& property = resource_properties[j];
|
||||
const std::string& name = property.m_name;
|
||||
|
||||
switch (property.m_type) {
|
||||
case SocketType::SocketTypeBool:
|
||||
node_instance_accessor->SetPropertyReferenceValue<const bool&>(name, property.m_value.flag);
|
||||
node_instance_accessor->SetPropertyReferenceValue<const bool&>(
|
||||
name,
|
||||
property.m_value.flag);
|
||||
break;
|
||||
case SocketType::SocketTypeFloat:
|
||||
node_instance_accessor->SetPropertyReferenceValue(name, property.m_value.float_value);
|
||||
node_instance_accessor->SetPropertyReferenceValue(
|
||||
name,
|
||||
property.m_value.float_value);
|
||||
break;
|
||||
case SocketType::SocketTypeVec3:
|
||||
node_instance_accessor->SetPropertyReferenceValue(name, property.m_value.vec3);
|
||||
node_instance_accessor->SetPropertyReferenceValue(
|
||||
name,
|
||||
property.m_value.vec3);
|
||||
break;
|
||||
case SocketType::SocketTypeQuat:
|
||||
node_instance_accessor->SetPropertyReferenceValue(name, property.m_value.quat);
|
||||
node_instance_accessor->SetPropertyReferenceValue(
|
||||
name,
|
||||
property.m_value.quat);
|
||||
break;
|
||||
case SocketType::SocketTypeString:
|
||||
node_instance_accessor->SetPropertyReferenceValue(name, property.m_value.str);
|
||||
node_instance_accessor->SetPropertyReferenceValue(
|
||||
name,
|
||||
property.m_value.str);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Invalid socket type " << static_cast<int>(property.m_type) << std::endl;
|
||||
std::cerr << "Invalid socket type "
|
||||
<< static_cast<int>(property.m_type) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user