diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cacc5e..1387d6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,17 +39,13 @@ set(ThirdPartyIncludeDeps PUBLIC $ PUBLIC $ PUBLIC $ - ) +) # Shared code by main executable and tests add_library(AnimTestbedCode OBJECT src/SyncTrack.cc src/SyncTrack.h src/ozzutils.cc - # src/AnimGraph/AnimGraphBlendTreeResource.cc - # src/AnimGraph/AnimGraphBlendTreeResource.h - src/AnimGraph/AnimGraph.cc - src/AnimGraph/AnimGraph.h src/AnimGraph/AnimGraphNodes.cc src/AnimGraph/AnimGraphNodes.h src/AnimGraph/AnimGraphData.cc @@ -112,7 +108,7 @@ target_sources(AnimTestbed PRIVATE 3rdparty/imgui-node-editor/imgui_extra_math.inl 3rdparty/imgui-node-editor/crude_json.cpp 3rdparty/imgui-node-editor/crude_json.h - ) +) target_link_libraries(AnimTestbed AnimTestbedCode glfw ozz_base ozz_geometry ozz_animation ${OPENGL_LIBRARIES}) @@ -124,7 +120,7 @@ set(ozz_offline_test_objs 3rdparty/ozz-animation/src/animation/offline/raw_skeleton.cc 3rdparty/ozz-animation/src/animation/offline/animation_builder.cc 3rdparty/ozz-animation/src/animation/offline/raw_animation.cc - ) +) target_sources(runtests PRIVATE tests/AnimGraphResourceTests.cc @@ -133,7 +129,7 @@ target_sources(runtests PRIVATE tests/SyncTrackTests.cc tests/main.cc ${ozz_offline_test_objs} - ) +) target_include_directories( runtests diff --git a/src/AnimGraph/AnimGraph.cc b/src/AnimGraph/AnimGraph.cc deleted file mode 100644 index 0a3edb8..0000000 --- a/src/AnimGraph/AnimGraph.cc +++ /dev/null @@ -1,3 +0,0 @@ -// -// Created by martin on 25.03.22. -// \ No newline at end of file diff --git a/src/AnimGraph/AnimGraph.h b/src/AnimGraph/AnimGraph.h deleted file mode 100644 index 97e8b9f..0000000 --- a/src/AnimGraph/AnimGraph.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Created by martin on 25.03.22. -// - -#ifndef ANIMTESTBED_ANIMGRAPH_H -#define ANIMTESTBED_ANIMGRAPH_H - -#include "AnimNode.h" -#include "AnimGraphData.h" - -// -// AnimGraph (Runtime) -// -struct AnimGraph { - ~AnimGraph() {} - - bool Init(AnimGraphContext& context) { - return m_root_node->Init(context); - } - void UpdateTime(float dt) { - m_time_last = m_time_now; - m_time_now = m_time_now + dt; - m_root_node->UpdateTime(m_time_last, m_time_now); - } - void Evaluate(AnimGraphContext& context) { - - } - - AnimNode* m_root_node = nullptr; - - float m_time_now = 0.f; - float m_time_last = 0.f; - - Vec3 m_root_bone_translation = {}; - Quat m_root_bone_rotation = {}; -}; - -#endif // ANIMTESTBED_ANIMGRAPH_H diff --git a/src/AnimGraph/AnimGraphBlendTree.cc b/src/AnimGraph/AnimGraphBlendTree.cc index f007bb2..dfc4395 100644 --- a/src/AnimGraph/AnimGraphBlendTree.cc +++ b/src/AnimGraph/AnimGraphBlendTree.cc @@ -1,3 +1,5 @@ +#pragma clang diagnostic push +#pragma ide diagnostic ignored "misc-no-recursion" // // Created by martin on 17.03.24. // @@ -5,7 +7,6 @@ #include "AnimGraphBlendTree.h" #include -#include bool AnimGraphBlendTree::Init(AnimGraphContext& context) { for (size_t i = 2; i < m_nodes.size(); i++) { @@ -64,9 +65,9 @@ void AnimGraphBlendTree::UpdateOrderedNodesRecursive(int node_index) { void AnimGraphBlendTree::MarkActiveInputs( const std::vector& input_connections) { - for (size_t i = 0, n = m_nodes.size(); i < n; i++) { - if (m_nodes[i]->m_tick_number != m_tick_number) { - m_nodes[i]->m_state = AnimNodeEvalState::Deactivated; + for (AnimNode* node : m_nodes) { + if (node->m_tick_number != m_tick_number) { + node->m_state = AnimNodeEvalState::Deactivated; } } @@ -104,7 +105,7 @@ void AnimGraphBlendTree::MarkActiveInputs( void AnimGraphBlendTree::CalcSyncTrack( const std::vector& input_connections) { - for (size_t i = m_eval_ordered_nodes.size() - 1; i >= 0; i--) { + for (int i = m_eval_ordered_nodes.size() - 1; i >= 0; i--) { AnimNode* node = m_eval_ordered_nodes[i]; if (node->m_state == AnimNodeEvalState::Deactivated) { continue; @@ -119,8 +120,8 @@ void AnimGraphBlendTree::UpdateTime(float time_last, float time_now) { const std::vector& graph_output_inputs = m_node_input_connections[0]; - for (size_t i = 0, n = graph_output_inputs.size(); i < n; i++) { - AnimNode* node = graph_output_inputs[i].m_source_node; + for (const AnimGraphConnection& graph_output_input : graph_output_inputs) { + AnimNode* node = graph_output_input.m_source_node; if (node != nullptr && node->m_state != AnimNodeEvalState::TimeUpdated) { node->UpdateTime(time_last, time_now); } @@ -158,15 +159,18 @@ void AnimGraphBlendTree::PropagateTimeToNodeInputs(const AnimNode* node) { const std::vector& node_input_connections = m_node_input_connections[node_index]; - for (size_t i = 0, n = node_input_connections.size(); i < n; i++) { - AnimNode* input_node = node_input_connections[i].m_source_node; + for (const AnimGraphConnection& node_input_connection : + node_input_connections) { + AnimNode* input_node = node_input_connection.m_source_node; // Only propagate time updates via animation sockets. if (input_node != nullptr - && node_input_connections[i].m_socket.m_type + && node_input_connection.m_socket.m_type == SocketType::SocketTypeAnimation && input_node->m_state == AnimNodeEvalState::Activated) { input_node->UpdateTime(node_time_last, node_time_now); } } } + +#pragma clang diagnostic pop \ No newline at end of file diff --git a/src/AnimGraph/AnimGraphBlendTree.h b/src/AnimGraph/AnimGraphBlendTree.h index 492f156..b32fef7 100644 --- a/src/AnimGraph/AnimGraphBlendTree.h +++ b/src/AnimGraph/AnimGraphBlendTree.h @@ -189,8 +189,8 @@ struct AnimGraphBlendTree : public AnimNode { return nullptr; } - size_t GetAnimNodeIndex(const AnimNode* node) const { - for (size_t i = 0; i < m_nodes.size(); i++) { + int GetAnimNodeIndex(const AnimNode* node) const { + for (int i = 0; i < m_nodes.size(); i++) { if (m_nodes[i] == node) { return i; } diff --git a/src/AnimGraph/AnimGraphEditor.h b/src/AnimGraph/AnimGraphEditor.h index 5b09030..08686b1 100644 --- a/src/AnimGraph/AnimGraphEditor.h +++ b/src/AnimGraph/AnimGraphEditor.h @@ -5,8 +5,6 @@ #ifndef ANIMTESTBED_ANIMGRAPHEDITOR_H #define ANIMTESTBED_ANIMGRAPHEDITOR_H -#include "AnimGraph.h" - namespace ax::NodeEditor { struct EditorContext; } // namespace ax::NodeEditor diff --git a/src/AnimGraph/AnimGraphResource.cc b/src/AnimGraph/AnimGraphResource.cc index c55ec47..faddaae 100644 --- a/src/AnimGraph/AnimGraphResource.cc +++ b/src/AnimGraph/AnimGraphResource.cc @@ -1,3 +1,5 @@ +#pragma clang diagnostic push +#pragma ide diagnostic ignored "misc-no-recursion" // // Created by martin on 17.03.24. // @@ -664,7 +666,6 @@ void AnimGraphResource::CreateBlendTreeConnectionInstances( embedded_graph_activation_connection.m_target_socket_name = target_socket->m_name; - // TODO: what to set the pointer to?!? embedded_graph_activation_connection.m_socket = *target_socket; instance.m_node_input_connections[connection.target_node_index].push_back( @@ -866,4 +867,5 @@ bool AnimGraphResource::LoadStateMachineResourceFromJson( assert(false && "Not yet implemented"); return false; -} \ No newline at end of file +} +#pragma clang diagnostic pop \ No newline at end of file diff --git a/src/AnimGraph/AnimGraphResource.h b/src/AnimGraph/AnimGraphResource.h index 09eb6ff..5558443 100644 --- a/src/AnimGraph/AnimGraphResource.h +++ b/src/AnimGraph/AnimGraphResource.h @@ -5,10 +5,8 @@ #ifndef ANIMTESTBED_ANIMGRAPHRESOURCE_H #define ANIMTESTBED_ANIMGRAPHRESOURCE_H -#include "AnimGraph.h" -#include "AnimGraphNodes.h" - #include "3rdparty/json/json.hpp" +#include "AnimGraphNodes.h" struct AnimGraphBlendTree; struct AnimGraphStateMachine; @@ -23,7 +21,8 @@ struct AnimNodeResource { float m_position[2] = {0.f, 0.f}; }; -static inline AnimNodeResource* AnimNodeResourceFactory(const std::string& node_type_name); +static inline AnimNodeResource* AnimNodeResourceFactory( + const std::string& node_type_name); struct BlendTreeConnectionResource { size_t source_node_index = -1; @@ -36,8 +35,7 @@ struct BlendTreeResource { std::vector m_nodes; std::vector m_connections; - ~BlendTreeResource() { CleanupNodes(); - } + ~BlendTreeResource() { CleanupNodes(); } void Reset() { CleanupNodes(); @@ -62,8 +60,12 @@ struct BlendTreeResource { m_nodes[1]->m_name = "Inputs"; } - [[nodiscard]] AnimNodeResource* GetGraphOutputNode() const { return m_nodes[0]; } - [[nodiscard]] AnimNodeResource* GetGraphInputNode() const { return m_nodes[1]; } + [[nodiscard]] AnimNodeResource* GetGraphOutputNode() const { + return m_nodes[0]; + } + [[nodiscard]] AnimNodeResource* GetGraphInputNode() const { + return m_nodes[1]; + } size_t GetNodeIndex(const AnimNodeResource* node_resource) const { for (size_t i = 0, n = m_nodes.size(); i < n; i++) { @@ -75,7 +77,7 @@ struct BlendTreeResource { return -1; } - bool ConnectSockets ( + bool ConnectSockets( const AnimNodeResource* source_node, const std::string& source_socket_name, const AnimNodeResource* target_node, @@ -86,13 +88,17 @@ struct BlendTreeResource { std::vector result; for (size_t i = 0; i < m_nodes.size(); i++) { - for (size_t j = 0, num_inputs = instance_node_descriptors[i]->m_inputs.size(); + for (size_t j = 0, + num_inputs = instance_node_descriptors[i]->m_inputs.size(); j < num_inputs; j++) { Socket& input = instance_node_descriptors[i]->m_inputs[j]; if (*input.m_reference.ptr_ptr == nullptr) { - memcpy(&input.m_value, &m_nodes[i]->m_socket_accessor->m_inputs[j].m_value, sizeof(Socket::SocketValue)); + memcpy( + &input.m_value, + &m_nodes[i]->m_socket_accessor->m_inputs[j].m_value, + sizeof(Socket::SocketValue)); result.push_back(&input); } } @@ -104,12 +110,14 @@ struct BlendTreeResource { size_t GetNodeIndexForOutputSocket(const std::string& socket_name) const { for (size_t i = 0; i < m_connections.size(); i++) { const BlendTreeConnectionResource& connection = m_connections[i]; - if (connection.target_node_index == 0 && connection.target_socket_name == socket_name) { + if (connection.target_node_index == 0 + && connection.target_socket_name == socket_name) { return connection.source_node_index; } } - std::cerr << "Error: could not find a node connected to output '" << socket_name << "'." << std::endl; + std::cerr << "Error: could not find a node connected to output '" + << socket_name << "'." << std::endl; return -1; } @@ -117,12 +125,14 @@ struct BlendTreeResource { size_t GetNodeIndexForInputSocket(const std::string& socket_name) const { for (size_t i = 0; i < m_connections.size(); i++) { const BlendTreeConnectionResource& connection = m_connections[i]; - if (connection.source_node_index == 1 && connection.source_socket_name == socket_name) { + if (connection.source_node_index == 1 + && connection.source_socket_name == socket_name) { return connection.target_node_index; } } - std::cerr << "Error: could not find a node connected to input '" << socket_name << "'." << std::endl; + std::cerr << "Error: could not find a node connected to input '" + << socket_name << "'." << std::endl; return -1; } @@ -140,7 +150,7 @@ struct StateMachineResource { std::vector m_transitions; }; -struct AnimGraphResource: AnimNodeResource { +struct AnimGraphResource : AnimNodeResource { std::string m_graph_type_name; BlendTreeResource m_blend_tree_resource; diff --git a/tests/AnimGraphResourceTests.cc b/tests/AnimGraphResourceTests.cc index 6447560..3e585cb 100644 --- a/tests/AnimGraphResourceTests.cc +++ b/tests/AnimGraphResourceTests.cc @@ -2,7 +2,6 @@ // Created by martin on 04.02.22. // -#include "AnimGraph/AnimGraph.h" #include "AnimGraph/AnimGraphBlendTree.h" #include "AnimGraph/AnimGraphEditor.h" #include "AnimGraph/AnimGraphNodes.h"