Added index member to node, preparing synctrack and node evaluation.
parent
d6453911e2
commit
976875c218
|
@ -368,7 +368,7 @@ void AnimGraph::UpdateOrderedNodes() {
|
|||
continue;
|
||||
}
|
||||
|
||||
int input_node_index = getAnimNodeIndex(input_node);
|
||||
int input_node_index = input_node->m_index;
|
||||
bool is_node_processed = false;
|
||||
for (size_t j = 0, m = m_eval_ordered_nodes.size(); j < m; j++) {
|
||||
if (m_eval_ordered_nodes[j] == input_node) {
|
||||
|
@ -404,7 +404,7 @@ void AnimGraph::MarkActiveNodes() {
|
|||
for (size_t i = 0, n = m_eval_ordered_nodes.size(); i < n; i++) {
|
||||
AnimNode* node = m_eval_ordered_nodes[i];
|
||||
if (CheckIsNodeActive(node)) {
|
||||
int node_index = getAnimNodeIndex(node);
|
||||
int node_index = node->m_index;
|
||||
node->MarkActiveInputs(m_node_inputs[node_index]);
|
||||
|
||||
// Non-animation data inputs are always active.
|
||||
|
@ -418,6 +418,18 @@ void AnimGraph::MarkActiveNodes() {
|
|||
}
|
||||
}
|
||||
|
||||
void AnimGraph::EvalSyncTracks() {
|
||||
for (size_t i = m_eval_ordered_nodes.size() - 1; i >= 0; i--) {
|
||||
AnimNode* node = m_eval_ordered_nodes[i];
|
||||
int node_index = node->m_index;
|
||||
if (node->m_state == AnimNodeEvalState::Deactivated) {
|
||||
continue;
|
||||
}
|
||||
|
||||
node->CalcSyncTrack(m_node_inputs[node_index]);
|
||||
}
|
||||
}
|
||||
|
||||
void AnimGraph::UpdateTime(float dt) {
|
||||
const std::vector<NodeInput> graph_output_inputs = m_node_inputs[0];
|
||||
for (size_t i = 0, n = graph_output_inputs.size(); i < n; i++) {
|
||||
|
@ -433,7 +445,7 @@ void AnimGraph::UpdateTime(float dt) {
|
|||
continue;
|
||||
}
|
||||
|
||||
int node_index = getAnimNodeIndex(node);
|
||||
int node_index = node->m_index;
|
||||
const std::vector<NodeInput> node_inputs =
|
||||
m_node_inputs[node_index];
|
||||
float node_time_now = node->m_time_now;
|
||||
|
@ -452,6 +464,17 @@ void AnimGraph::UpdateTime(float dt) {
|
|||
}
|
||||
}
|
||||
|
||||
void AnimGraph::Evaluate() {
|
||||
for (size_t i = m_eval_ordered_nodes.size() - 1; i >= 0; i--) {
|
||||
AnimNode* node = m_eval_ordered_nodes[i];
|
||||
if (node->m_state == AnimNodeEvalState::Deactivated) {
|
||||
continue;
|
||||
}
|
||||
|
||||
node->Evaluate();
|
||||
}
|
||||
}
|
||||
|
||||
void* AnimGraph::GetOutput(const std::string& name) const {
|
||||
Socket* socket = m_socket_accessor->FindInputSocket(name);
|
||||
if (socket == nullptr) {
|
||||
|
|
|
@ -98,6 +98,14 @@ enum class AnimNodeEvalState {
|
|||
};
|
||||
|
||||
struct AnimNode {
|
||||
std::string m_name;
|
||||
std::string m_node_type_name;
|
||||
float m_time_now = 0.f;
|
||||
float m_time_last = 0.f;
|
||||
size_t m_index = -1;
|
||||
AnimNodeEvalState m_state = AnimNodeEvalState::Undefined;
|
||||
SyncTrack m_sync_track;
|
||||
|
||||
virtual ~AnimNode(){};
|
||||
|
||||
virtual void MarkActiveInputs(const std::vector<NodeInput>& inputs) {
|
||||
|
@ -109,18 +117,25 @@ struct AnimNode {
|
|||
}
|
||||
}
|
||||
|
||||
virtual void CalcSyncTrack(const std::vector<NodeInput>& inputs) {
|
||||
for (size_t i = 0, n = inputs.size(); i < n; i++) {
|
||||
AnimNode* input_node = inputs[i].m_node;
|
||||
if (input_node != nullptr
|
||||
&& inputs[i].m_type == SocketType::SocketTypeAnimation
|
||||
&& input_node->m_state != AnimNodeEvalState::Deactivated) {
|
||||
m_sync_track = input_node->m_sync_track;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void UpdateTime(float time_last, float time_now) {
|
||||
m_time_last = time_last;
|
||||
m_time_now = time_now;
|
||||
m_state = AnimNodeEvalState::TimeUpdated;
|
||||
}
|
||||
|
||||
std::string m_name;
|
||||
std::string m_node_type_name;
|
||||
float m_time_now = 0.f;
|
||||
float m_time_last = 0.f;
|
||||
AnimNodeEvalState m_state = AnimNodeEvalState::Undefined;
|
||||
SyncTrack m_sync_track;
|
||||
virtual void Evaluate() {};
|
||||
};
|
||||
|
||||
|
||||
|
@ -598,6 +613,7 @@ struct AnimGraph {
|
|||
bool CheckIsNodeActive(AnimNode* node) {
|
||||
return node->m_state != AnimNodeEvalState::Deactivated;
|
||||
}
|
||||
void EvalSyncTracks();
|
||||
void UpdateTime(float dt);
|
||||
void Evaluate();
|
||||
void Reset() {
|
||||
|
@ -658,17 +674,6 @@ struct AnimGraph {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
size_t getAnimNodeIndex(AnimNode* node) {
|
||||
for (size_t i = 0, n = m_nodes.size(); i < n; i++) {
|
||||
if (m_nodes[i] == node) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "Could not find node " << node << "." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static AnimGraph createFromResource(const AnimGraphResource& resource) {
|
||||
AnimGraph result;
|
||||
|
||||
|
@ -678,6 +683,7 @@ struct AnimGraph {
|
|||
AnimNode* node = AnimNodeFactory(node_resource.m_type_name.c_str());
|
||||
node->m_name = node_resource.m_name;
|
||||
node->m_node_type_name = node_resource.m_type_name;
|
||||
node->m_index = i;
|
||||
result.m_nodes.push_back(node);
|
||||
|
||||
assert(node_resource.m_socket_accessor != nullptr);
|
||||
|
@ -821,7 +827,7 @@ struct AnimGraph {
|
|||
|
||||
(*source_socket->m_value.ptr_ptr) = target_socket->m_value.ptr;
|
||||
|
||||
size_t target_node_index = result.getAnimNodeIndex(target_node);
|
||||
size_t target_node_index = target_node->m_index;
|
||||
|
||||
std::vector<NodeInput>& node_inputs =
|
||||
result.m_node_inputs[target_node_index];
|
||||
|
|
|
@ -90,9 +90,9 @@ TEST_CASE("BasicGraph", "[AnimGraphResource]") {
|
|||
== graph.GetOutput("GraphOutput"));
|
||||
|
||||
// check node input dependencies
|
||||
size_t anim_sampler_index0 = graph.getAnimNodeIndex(anim_sampler_instance0);
|
||||
size_t anim_sampler_index1 = graph.getAnimNodeIndex(anim_sampler_instance1);
|
||||
size_t blend_index = graph.getAnimNodeIndex(blend2_instance);
|
||||
size_t anim_sampler_index0 = anim_sampler_instance0->m_index;
|
||||
size_t anim_sampler_index1 = anim_sampler_instance1->m_index;
|
||||
size_t blend_index = blend2_instance->m_index;
|
||||
|
||||
CHECK(graph.m_node_inputs[anim_sampler_index0].size() == 0);
|
||||
CHECK(graph.m_node_inputs[anim_sampler_index1].size() == 0);
|
||||
|
|
Loading…
Reference in New Issue