// // Created by martin on 25.03.22. // #ifndef ANIMTESTBED_ANIMGRAPH_H #define ANIMTESTBED_ANIMGRAPH_H #include "AnimGraphData.h" #include "AnimGraphNodes.h" // // AnimGraph (Runtime) // struct AnimGraph { AnimData m_local_transforms; std::vector m_nodes; std::vector m_eval_ordered_nodes; std::vector > m_node_inputs; NodeSocketAccessorBase* m_socket_accessor; char* m_input_buffer = nullptr; char* m_output_buffer = nullptr; std::vector& getGraphOutputs() { return m_socket_accessor->m_inputs; } std::vector& getGraphInputs() { return m_socket_accessor->m_outputs; } ~AnimGraph() { delete[] m_input_buffer; delete[] m_output_buffer; for (int i = 0; i < m_nodes.size(); i++) { delete m_nodes[i]; } delete m_socket_accessor; } void updateOrderedNodes(); void markActiveNodes(); bool checkIsNodeActive(AnimNode* node) { return node->m_state != AnimNodeEvalState::Deactivated; } void evalSyncTracks(); void updateTime(float dt); void evaluate(); void reset() { for (size_t i = 0, n = m_nodes.size(); i < n; i++) { m_nodes[i]->m_time_now = 0.f; m_nodes[i]->m_time_last = 0.f; m_nodes[i]->m_state = AnimNodeEvalState::Undefined; } } void* getOutput(const std::string& name) const; void* getInput(const std::string& name) const; int getNodeEvalOrderIndex(const AnimNode* node) { for (size_t i = 0, n = m_eval_ordered_nodes.size(); i < n; i++) { if (m_eval_ordered_nodes[i] == node) { return i; } } return -1; } AnimNode* getAnimNodeForInput( size_t node_index, const std::string& input_name) { assert(node_index < m_nodes.size()); assert(node_index < m_node_inputs.size()); std::vector& node_inputs = m_node_inputs[node_index]; for (size_t i = 0, n = node_inputs.size(); i < n; i++) { if (node_inputs[i].m_input_name == input_name) { return node_inputs[i].m_node; } } return nullptr; } AnimNode* getAnimNode(const char* name) { for (size_t i = 0; i < m_nodes.size(); i++) { if (m_nodes[i]->m_name == name) { return m_nodes[i]; } } return nullptr; } }; #endif //ANIMTESTBED_ANIMGRAPH_H