Started working on graph initialization in ATP Editor.
This commit is contained in:
@@ -43,7 +43,7 @@ json sSocketToJson(const Socket& socket) {
|
||||
result["value"][2] = socket.m_value.quat[2];
|
||||
result["value"][3] = socket.m_value.quat[3];
|
||||
} else if (socket.m_type == SocketType::SocketTypeString) {
|
||||
result["value"] = std::string(socket.m_value.str);
|
||||
result["value"] = *socket.m_value.string_ptr;
|
||||
} else {
|
||||
std::cerr << "Invalid socket type '" << static_cast<int>(socket.m_type)
|
||||
<< "'." << std::endl;
|
||||
@@ -142,17 +142,7 @@ AnimNodeResource sAnimGraphNodeFromJson(const json& json_node) {
|
||||
property.m_value.quat[2] = json_property["value"][2];
|
||||
property.m_value.quat[3] = json_property["value"][3];
|
||||
} else if (property.m_type == SocketType::SocketTypeString) {
|
||||
std::string value_str = json_property["value"];
|
||||
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;
|
||||
string_length = string_max_length;
|
||||
}
|
||||
memcpy(property.m_value.str, value_str.data(), string_length);
|
||||
property.m_value.str[string_length] = 0;
|
||||
*(property.m_value.string_ptr) = json_property["value"].get<std::string>();
|
||||
} else {
|
||||
std::cerr << "Invalid type for property '" << property.m_name
|
||||
<< "'. Cannot parse json to type '"
|
||||
@@ -263,7 +253,7 @@ bool AnimGraphResource::saveToFile(const char* filename) const {
|
||||
|
||||
std::ofstream output_file;
|
||||
output_file.open(filename);
|
||||
output_file << to_string(result) << std::endl;
|
||||
output_file << result.dump(4, ' ') << std::endl;
|
||||
output_file.close();
|
||||
|
||||
return true;
|
||||
@@ -340,18 +330,14 @@ bool AnimGraphResource::loadFromFile(const char* filename) {
|
||||
return true;
|
||||
}
|
||||
|
||||
AnimGraph AnimGraphResource::createInstance() const {
|
||||
AnimGraph result;
|
||||
|
||||
void AnimGraphResource::createInstance(AnimGraph& result) const {
|
||||
createRuntimeNodeInstances(result);
|
||||
prepareGraphIOData(result);
|
||||
connectRuntimeNodes(result);
|
||||
setRuntimeNodeProperties(result);
|
||||
|
||||
result.updateOrderedNodes();
|
||||
result.reset();
|
||||
|
||||
return result;
|
||||
result.resetNodeStates();
|
||||
}
|
||||
|
||||
void AnimGraphResource::createRuntimeNodeInstances(AnimGraph& instance) const {
|
||||
@@ -384,8 +370,11 @@ void AnimGraphResource::prepareGraphIOData(AnimGraph& instance) const {
|
||||
for (int i = 0; i < graph_inputs.size(); i++) {
|
||||
input_block_size += sizeof(void*);
|
||||
}
|
||||
instance.m_input_buffer = new char[input_block_size];
|
||||
memset(instance.m_input_buffer, 0, input_block_size);
|
||||
|
||||
if (input_block_size > 0) {
|
||||
instance.m_input_buffer = new char[input_block_size];
|
||||
memset(instance.m_input_buffer, 0, input_block_size);
|
||||
}
|
||||
|
||||
int input_block_offset = 0;
|
||||
for (int i = 0; i < graph_inputs.size(); i++) {
|
||||
@@ -400,8 +389,11 @@ void AnimGraphResource::prepareGraphIOData(AnimGraph& instance) const {
|
||||
for (int i = 0; i < graph_outputs.size(); i++) {
|
||||
output_block_size += graph_outputs[i].m_type_size;
|
||||
}
|
||||
instance.m_output_buffer = new char[output_block_size];
|
||||
memset(instance.m_output_buffer, 0, output_block_size);
|
||||
|
||||
if (output_block_size > 0) {
|
||||
instance.m_output_buffer = new char[output_block_size];
|
||||
memset(instance.m_output_buffer, 0, output_block_size);
|
||||
}
|
||||
|
||||
int output_block_offset = 0;
|
||||
for (int i = 0; i < graph_outputs.size(); i++) {
|
||||
@@ -557,9 +549,9 @@ void AnimGraphResource::setRuntimeNodeProperties(AnimGraph& instance) const {
|
||||
property.m_value.quat);
|
||||
break;
|
||||
case SocketType::SocketTypeString:
|
||||
node_instance_accessor->SetPropertyReferenceValue(
|
||||
node_instance_accessor->SetPropertyValue(
|
||||
name,
|
||||
property.m_value.str);
|
||||
*property.m_value.string_ptr);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Invalid socket type "
|
||||
|
||||
Reference in New Issue
Block a user