New evaluation scheme.
- Animation Data are always referenced via a pointer in nodes. - Animation Data storage pointers are injected from graph when node is evaluated. - Node value outputs always stored in node. - Node value inputs always referenced via pointer. References are created when instantiating the graph.
This commit is contained in:
+56
-10
@@ -8,6 +8,34 @@
|
||||
#include "AnimGraphData.h"
|
||||
#include "AnimGraphNodes.h"
|
||||
|
||||
struct AnimDataWorkBuffer {
|
||||
std::vector<AnimData> m_eval_anim_data;
|
||||
std::vector<AnimData*> m_available_data;
|
||||
|
||||
AnimDataWorkBuffer(size_t stack_size) {
|
||||
m_eval_anim_data.resize(stack_size);
|
||||
m_available_data.resize(stack_size);
|
||||
|
||||
for (size_t i = 0; i < stack_size; i++) {
|
||||
m_available_data[i] = &m_eval_anim_data[i];
|
||||
}
|
||||
}
|
||||
|
||||
void push(AnimData* anim_data) {
|
||||
assert (m_available_data.size() < m_eval_anim_data.size());
|
||||
m_available_data.push_back(anim_data);
|
||||
}
|
||||
|
||||
void pop() {
|
||||
assert (m_available_data.size() > 0);
|
||||
m_available_data.pop_back();
|
||||
}
|
||||
|
||||
AnimData* peek() {
|
||||
return m_available_data.back();
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// AnimGraph (Runtime)
|
||||
//
|
||||
@@ -16,7 +44,8 @@ struct AnimGraph {
|
||||
|
||||
std::vector<AnimNode*> m_nodes;
|
||||
std::vector<AnimNode*> m_eval_ordered_nodes;
|
||||
std::vector<std::vector<NodeInput> > m_node_inputs;
|
||||
std::vector<std::vector<AnimGraphConnection> > m_node_input_connections;
|
||||
std::vector<std::vector<AnimGraphConnection> > m_node_output_connections;
|
||||
NodeSocketAccessorBase* m_socket_accessor;
|
||||
char* m_input_buffer = nullptr;
|
||||
char* m_output_buffer = nullptr;
|
||||
@@ -24,6 +53,8 @@ struct AnimGraph {
|
||||
std::vector<Socket>& getGraphOutputs() { return m_socket_accessor->m_inputs; }
|
||||
std::vector<Socket>& getGraphInputs() { return m_socket_accessor->m_outputs; }
|
||||
|
||||
AnimDataWorkBuffer m_anim_data_work_buffer = AnimDataWorkBuffer(5);
|
||||
|
||||
~AnimGraph() {
|
||||
delete[] m_input_buffer;
|
||||
delete[] m_output_buffer;
|
||||
@@ -36,10 +67,16 @@ struct AnimGraph {
|
||||
}
|
||||
|
||||
void updateOrderedNodes();
|
||||
void updateOrderedNodesRecursive(int node_index);
|
||||
void markActiveNodes();
|
||||
bool checkIsNodeActive(AnimNode* node) {
|
||||
return node->m_state != AnimNodeEvalState::Deactivated;
|
||||
}
|
||||
|
||||
|
||||
void prepareNodeEval(size_t node_index);
|
||||
void finishNodeEval(size_t node_index);
|
||||
|
||||
void evalSyncTracks();
|
||||
void updateTime(float dt);
|
||||
void evaluate();
|
||||
@@ -51,8 +88,8 @@ struct AnimGraph {
|
||||
}
|
||||
}
|
||||
|
||||
void* getOutput(const std::string& name) const;
|
||||
void* getInput(const std::string& name) const;
|
||||
Socket* getInputSocket(const std::string& name);
|
||||
Socket* getOutputSocket(const std::string& name);
|
||||
|
||||
int getNodeEvalOrderIndex(const AnimNode* node) {
|
||||
for (size_t i = 0, n = m_eval_ordered_nodes.size(); i < n; i++) {
|
||||
@@ -63,16 +100,15 @@ struct AnimGraph {
|
||||
|
||||
return -1;
|
||||
}
|
||||
AnimNode* getAnimNodeForInput(
|
||||
const AnimNode* getAnimNodeForInput (
|
||||
size_t node_index,
|
||||
const std::string& input_name) {
|
||||
const std::string& input_name) const {
|
||||
assert(node_index < m_nodes.size());
|
||||
assert(node_index < m_node_inputs.size());
|
||||
|
||||
std::vector<NodeInput>& 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;
|
||||
const std::vector<AnimGraphConnection>& input_connection = m_node_input_connections[node_index];
|
||||
for (size_t i = 0, n = input_connection.size(); i < n; i++) {
|
||||
if (input_connection[i].m_target_socket.m_name == input_name) {
|
||||
return input_connection[i].m_source_node;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +124,16 @@ struct AnimGraph {
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t getAnimNodeIndex (AnimNode* node) {
|
||||
for (size_t i = 0; i < m_nodes.size(); i++) {
|
||||
if (m_nodes[i] == node) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //ANIMTESTBED_ANIMGRAPH_H
|
||||
|
||||
Reference in New Issue
Block a user