Initial step for connectivity refactor.

Instead of wiring up pointers with prepareNodeEval() and finishNodeEval() use for each connection a single memory block where outputs and inputs point to.
This commit is contained in:
Martin Felis
2023-03-30 23:50:07 +02:00
parent 411aa5ef20
commit 91607baa9d
8 changed files with 249 additions and 855 deletions
+29 -59
View File
@@ -86,8 +86,8 @@ struct AnimNode {
struct BlendTreeNode : public AnimNode {};
template <>
struct NodeSocketAccessor<BlendTreeNode> : public NodeSocketAccessorBase {
NodeSocketAccessor(AnimNode* node_) {}
struct NodeDescriptor<BlendTreeNode> : public NodeDescriptorBase {
NodeDescriptor(BlendTreeNode* node_) {}
};
//
@@ -122,34 +122,6 @@ struct Blend2Node : public AnimNode {
virtual void Evaluate(AnimGraphContext& context) override;
};
template <>
struct NodeSocketAccessor<Blend2Node> : public NodeSocketAccessorBase {
NodeSocketAccessor(AnimNode* node_) {
Blend2Node* node = dynamic_cast<Blend2Node*>(node_);
RegisterInput("Input0", &node->i_input0);
RegisterInput("Input1", &node->i_input1);
RegisterInput(
"Weight",
&node->i_blend_weight,
SocketFlags::SocketFlagAffectsTime);
RegisterOutput("Output", &node->o_output);
RegisterProperty("Sync", &node->m_sync_blend);
}
virtual void UpdateFlags() override {
Socket* weight_input_socket = FindSocket(m_inputs, "Weight");
assert(weight_input_socket != nullptr);
if (GetProperty<bool>("Sync", false) == true) {
weight_input_socket->m_flags = SocketFlags::SocketFlagAffectsTime;
} else {
weight_input_socket->m_flags = SocketFlags::SocketFlagNone;
}
}
};
template <>
struct NodeDescriptor<Blend2Node> : public NodeDescriptorBase {
NodeDescriptor(Blend2Node* node) {
@@ -198,9 +170,8 @@ struct SpeedScaleNode : public AnimNode {
};
template <>
struct NodeSocketAccessor<SpeedScaleNode> : public NodeSocketAccessorBase {
NodeSocketAccessor(AnimNode* node_) {
SpeedScaleNode* node = dynamic_cast<SpeedScaleNode*>(node_);
struct NodeDescriptor<SpeedScaleNode> : public NodeDescriptorBase {
NodeDescriptor(SpeedScaleNode* node) {
RegisterInput(
"SpeedScale",
&node->i_speed_scale,
@@ -211,6 +182,7 @@ struct NodeSocketAccessor<SpeedScaleNode> : public NodeSocketAccessorBase {
}
};
//
// AnimSamplerNode
//
@@ -231,9 +203,8 @@ struct AnimSamplerNode : public AnimNode {
};
template <>
struct NodeSocketAccessor<AnimSamplerNode> : public NodeSocketAccessorBase {
NodeSocketAccessor(AnimNode* node_) {
AnimSamplerNode* node = dynamic_cast<AnimSamplerNode*>(node_);
struct NodeDescriptor<AnimSamplerNode> : public NodeDescriptorBase {
NodeDescriptor(AnimSamplerNode* node) {
RegisterOutput("Output", &node->o_output);
RegisterProperty("Filename", &node->m_filename);
@@ -253,34 +224,33 @@ struct ConstScalarNode : public AnimNode {
};
template <>
struct NodeSocketAccessor<ConstScalarNode> : public NodeSocketAccessorBase {
NodeSocketAccessor(AnimNode* node_) {
ConstScalarNode* node = dynamic_cast<ConstScalarNode*>(node_);
struct NodeDescriptor<ConstScalarNode> : public NodeDescriptorBase {
NodeDescriptor(ConstScalarNode* node) {
RegisterOutput("ScalarOutput", &node->o_value);
RegisterProperty("ScalarValue", &node->value);
}
};
//
// MathAddNode
//
struct MathAddNode : public AnimNode {
float* i_input0 = nullptr;
float* i_input1 = nullptr;
float o_output = 0.f;
float* o_output = nullptr;
void Evaluate(AnimGraphContext& context) override {
assert (i_input0 != nullptr);
assert (i_input1 != nullptr);
o_output = *i_input0 + *i_input1;
*o_output = *i_input0 + *i_input1;
}
};
template <>
struct NodeSocketAccessor<MathAddNode> : public NodeSocketAccessorBase {
NodeSocketAccessor(AnimNode* node_) {
MathAddNode* node = dynamic_cast<MathAddNode*>(node_);
struct NodeDescriptor<MathAddNode> : public NodeDescriptorBase {
NodeDescriptor(MathAddNode* node) {
RegisterInput("Input0", &node->i_input0);
RegisterInput("Input1", &node->i_input1);
RegisterOutput("Output", &node->o_output);
@@ -294,23 +264,22 @@ struct MathFloatToVec3Node : public AnimNode {
float* i_input0 = nullptr;
float* i_input1 = nullptr;
float* i_input2 = nullptr;
Vec3 o_output = {0.f, 0.f, 0.f};
Vec3* o_output = nullptr;
void Evaluate(AnimGraphContext& context) override {
assert (i_input0 != nullptr);
assert (i_input1 != nullptr);
assert (i_input2 != nullptr);
o_output[0] = *i_input0;
o_output[1] = *i_input1;
o_output[2] = *i_input2;
o_output->v[0] = *i_input0;
o_output->v[1] = *i_input1;
o_output->v[2] = *i_input2;
}
};
template <>
struct NodeSocketAccessor<MathFloatToVec3Node> : public NodeSocketAccessorBase {
NodeSocketAccessor(AnimNode* node_) {
MathFloatToVec3Node* node = dynamic_cast<MathFloatToVec3Node*>(node_);
struct NodeDescriptor<MathFloatToVec3Node> : public NodeDescriptorBase {
NodeDescriptor(MathFloatToVec3Node* node) {
RegisterInput("Input0", &node->i_input0);
RegisterInput("Input1", &node->i_input1);
RegisterInput("Input2", &node->i_input2);
@@ -318,6 +287,7 @@ struct NodeSocketAccessor<MathFloatToVec3Node> : public NodeSocketAccessorBase {
}
};
static inline AnimNode* AnimNodeFactory(const std::string& name) {
AnimNode* result;
if (name == "Blend2") {
@@ -345,23 +315,23 @@ static inline AnimNode* AnimNodeFactory(const std::string& name) {
return nullptr;
}
static inline NodeSocketAccessorBase* AnimNodeAccessorFactory(
static inline NodeDescriptorBase* AnimNodeDescriptorFactory(
const std::string& node_type_name,
AnimNode* node) {
if (node_type_name == "Blend2") {
return new NodeSocketAccessor<Blend2Node>(node);
return CreateNodeDescriptor<Blend2Node>(node);
} else if (node_type_name == "SpeedScale") {
return new NodeSocketAccessor<SpeedScaleNode>(node);
return CreateNodeDescriptor<SpeedScaleNode>(node);
} else if (node_type_name == "AnimSampler") {
return new NodeSocketAccessor<AnimSamplerNode>(node);
return CreateNodeDescriptor<AnimSamplerNode>(node);
} else if (node_type_name == "BlendTree") {
return new NodeSocketAccessor<BlendTreeNode>(node);
return CreateNodeDescriptor<BlendTreeNode>(node);
} else if (node_type_name == "MathAddNode") {
return new NodeSocketAccessor<MathAddNode>(node);
return CreateNodeDescriptor<MathAddNode>(node);
} else if (node_type_name == "MathFloatToVec3Node") {
return new NodeSocketAccessor<MathFloatToVec3Node>(node);
return CreateNodeDescriptor<MathFloatToVec3Node>(node);
} else if (node_type_name == "ConstScalarNode") {
return new NodeSocketAccessor<ConstScalarNode>(node);
return CreateNodeDescriptor<ConstScalarNode>(node);
} else {
std::cerr << "Invalid node type name " << node_type_name << "."
<< std::endl;