Minor cleanup.

This commit is contained in:
Martin Felis
2022-02-24 23:47:31 +01:00
parent 976875c218
commit 73e7a60875
4 changed files with 111 additions and 92 deletions
+36 -36
View File
@@ -5,7 +5,7 @@
#include "AnimGraphResource.h"
#include "catch.hpp"
using namespace AnimGraphCode;
using namespace AniGraph;
TEST_CASE("BasicGraph", "[AnimGraphResource]") {
AnimGraphResource graph_resource;
@@ -87,7 +87,7 @@ TEST_CASE("BasicGraph", "[AnimGraphResource]") {
CHECK(graph.m_socket_accessor->FindInputSocket("GraphOutput"));
CHECK(
reinterpret_cast<char*>(blend2_instance->m_output)
== graph.GetOutput("GraphOutput"));
== graph.getOutput("GraphOutput"));
// check node input dependencies
size_t anim_sampler_index0 = anim_sampler_instance0->m_index;
@@ -194,14 +194,14 @@ TEST_CASE("ResourceSaveLoadGraphInputs", "[AnimGraphResource]") {
AnimGraph anim_graph =
AnimGraph::createFromResource(graph_resource_loaded);
REQUIRE(
anim_graph.GetOutput("GraphOutput") == anim_graph.m_output_buffer);
anim_graph.getOutput("GraphOutput") == anim_graph.m_output_buffer);
REQUIRE(
anim_graph.GetOutput("SomeFloatOutput")
anim_graph.getOutput("SomeFloatOutput")
== anim_graph.m_output_buffer + sizeof(AnimData));
REQUIRE(anim_graph.GetInput("GraphAnimInput") == nullptr);
REQUIRE(anim_graph.GetInput("GraphFloatInput") == nullptr);
REQUIRE(anim_graph.GetInput("GraphBoolInput") == nullptr);
REQUIRE(anim_graph.getInput("GraphAnimInput") == nullptr);
REQUIRE(anim_graph.getInput("GraphFloatInput") == nullptr);
REQUIRE(anim_graph.getInput("GraphBoolInput") == nullptr);
}
}
@@ -217,15 +217,15 @@ TEST_CASE("ResourceSaveLoadGraphInputs", "[AnimGraphResource]") {
AnimGraph anim_graph = AnimGraph::createFromResource(graph_resource_origin);
void* graph_anim_input_ptr = anim_graph.GetInput("GraphAnimInput");
void* graph_output_ptr = anim_graph.GetOutput("GraphOutput");
void* graph_anim_input_ptr = anim_graph.getInput("GraphAnimInput");
void* graph_output_ptr = anim_graph.getOutput("GraphOutput");
REQUIRE(graph_anim_input_ptr == graph_output_ptr);
REQUIRE(graph_output_ptr == anim_graph.m_output_buffer);
REQUIRE(
anim_graph.GetInput("GraphAnimInput")
== anim_graph.GetOutput("GraphOutput"));
anim_graph.getInput("GraphAnimInput")
== anim_graph.getOutput("GraphOutput"));
}
}
@@ -267,12 +267,12 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
AnimGraph anim_graph = AnimGraph::createFromResource(graph_resource);
THEN("Writing to the input pointer changes the value of the output.") {
float* float_input_ptr = (float*)anim_graph.GetInput("GraphFloatInput");
float* float_input_ptr = (float*)anim_graph.getInput("GraphFloatInput");
REQUIRE(float_input_ptr != nullptr);
*float_input_ptr = 23.123f;
float* float_output_ptr =
(float*)anim_graph.GetOutput("GraphFloatOutput");
(float*)anim_graph.getOutput("GraphFloatOutput");
REQUIRE(float_output_ptr != nullptr);
CHECK(*float_output_ptr == Approx(23.123f));
}
@@ -298,7 +298,7 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
REQUIRE(
*anim_graph.m_socket_accessor->m_outputs[0].m_value.ptr_ptr
== &blend2_node->m_blend_weight);
float* float_input_ptr = (float*)anim_graph.GetInput("GraphFloatInput");
float* float_input_ptr = (float*)anim_graph.getInput("GraphFloatInput");
REQUIRE(float_input_ptr == &blend2_node->m_blend_weight);
}
@@ -331,21 +331,21 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
dynamic_cast<Blend2Node*>(anim_graph.m_nodes[blend2_node_index]);
AnimData* graph_input0 =
(AnimData*)anim_graph.GetInput("GraphAnimInput0");
(AnimData*)anim_graph.getInput("GraphAnimInput0");
REQUIRE(graph_input0 == &blend2_node->m_input0);
REQUIRE(
anim_graph.m_nodes[1]
== anim_graph.getAnimNodeForInput(blend2_node_index, "Input0"));
AnimData* graph_input1 =
(AnimData*)anim_graph.GetInput("GraphAnimInput1");
(AnimData*)anim_graph.getInput("GraphAnimInput1");
REQUIRE(graph_input1 == &blend2_node->m_input1);
REQUIRE(
anim_graph.m_nodes[1]
== anim_graph.getAnimNodeForInput(blend2_node_index, "Input1"));
AnimData* graph_output =
(AnimData*)anim_graph.GetOutput("GraphAnimOutput");
(AnimData*)anim_graph.getOutput("GraphAnimOutput");
REQUIRE(graph_output == blend2_node->m_output);
REQUIRE(
anim_graph.m_nodes[blend2_node_index]
@@ -418,14 +418,14 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
// check connectivity
//
AnimData* graph_input0 =
(AnimData*)anim_graph.GetInput("GraphAnimInput0");
(AnimData*)anim_graph.getInput("GraphAnimInput0");
REQUIRE(graph_input0 == &blend2_node->m_input0);
REQUIRE(
anim_graph.m_nodes[1]
== anim_graph.getAnimNodeForInput(blend2_node_index, "Input0"));
AnimData* graph_input1 =
(AnimData*)anim_graph.GetInput("GraphAnimInput1");
(AnimData*)anim_graph.getInput("GraphAnimInput1");
REQUIRE(graph_input1 == nullptr);
REQUIRE(sampler_node->m_output == &speed_scale_node->m_input);
@@ -439,7 +439,7 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
== anim_graph.getAnimNodeForInput(blend2_node_index, "Input1"));
AnimData* graph_output =
(AnimData*)anim_graph.GetOutput("GraphAnimOutput");
(AnimData*)anim_graph.getOutput("GraphAnimOutput");
REQUIRE(graph_output == blend2_node->m_output);
REQUIRE(
anim_graph.m_nodes[blend2_node_index]
@@ -462,7 +462,7 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
WHEN("Instantiating graph") {
AnimGraph anim_graph = AnimGraph::createFromResource(graph_resource);
float* blend_weight_input =
reinterpret_cast<float*>(anim_graph.GetInput("GraphFloatInput"));
reinterpret_cast<float*>(anim_graph.getInput("GraphFloatInput"));
Blend2Node* blend2_node =
dynamic_cast<Blend2Node*>(anim_graph.m_nodes[blend2_node_index]);
@@ -473,43 +473,43 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
WHEN("Setting weight to 0. and marking nodes active.") {
*blend_weight_input = 0.;
anim_graph.MarkActiveNodes();
anim_graph.markActiveNodes();
THEN("Speed scale and sampler node are inactive") {
REQUIRE(anim_graph.CheckIsNodeActive(speed_scale_node) == false);
REQUIRE(anim_graph.CheckIsNodeActive(sampler_node) == false);
REQUIRE(anim_graph.checkIsNodeActive(speed_scale_node) == false);
REQUIRE(anim_graph.checkIsNodeActive(sampler_node) == false);
}
}
WHEN("Setting weight to 0. and marking nodes active") {
*blend_weight_input = 0.1;
anim_graph.MarkActiveNodes();
anim_graph.markActiveNodes();
THEN("Speed scale and sampler nodes are active") {
REQUIRE(anim_graph.CheckIsNodeActive(speed_scale_node) == true);
REQUIRE(anim_graph.CheckIsNodeActive(sampler_node) == true);
REQUIRE(anim_graph.checkIsNodeActive(speed_scale_node) == true);
REQUIRE(anim_graph.checkIsNodeActive(sampler_node) == true);
}
}
WHEN("Setting weight to 1. and marking nodes active") {
*blend_weight_input = 1.0;
anim_graph.MarkActiveNodes();
anim_graph.markActiveNodes();
THEN("Speed scale and sampler nodes are active") {
REQUIRE(anim_graph.CheckIsNodeActive(speed_scale_node) == true);
REQUIRE(anim_graph.CheckIsNodeActive(sampler_node) == true);
REQUIRE(anim_graph.checkIsNodeActive(speed_scale_node) == true);
REQUIRE(anim_graph.checkIsNodeActive(sampler_node) == true);
}
}
WHEN("Updating time with dt = 0.3f and speed scale = 1.0f") {
float* speed_scale_input =
reinterpret_cast<float*>(anim_graph.GetInput("SpeedScaleInput"));
reinterpret_cast<float*>(anim_graph.getInput("SpeedScaleInput"));
*blend_weight_input = 0.1;
*speed_scale_input = 1.0f;
anim_graph.MarkActiveNodes();
anim_graph.UpdateTime(0.3f);
anim_graph.markActiveNodes();
anim_graph.updateTime(0.3f);
THEN ("Anim sampler node time now must be 0.3f") {
REQUIRE(sampler_node->m_time_now == Approx(0.3f));
@@ -518,13 +518,13 @@ TEST_CASE("GraphInputOutputConnectivity", "[AnimGraphResource]") {
WHEN("Updating time with dt = 0.3f and speed scale = 1.3f") {
float* speed_scale_input =
reinterpret_cast<float*>(anim_graph.GetInput("SpeedScaleInput"));
reinterpret_cast<float*>(anim_graph.getInput("SpeedScaleInput"));
*blend_weight_input = 0.1;
*speed_scale_input = 1.3f;
anim_graph.MarkActiveNodes();
anim_graph.UpdateTime(0.3f);
anim_graph.markActiveNodes();
anim_graph.updateTime(0.3f);
THEN ("Anim sampler node time now must be 0.39f") {
REQUIRE(sampler_node->m_time_now == Approx(0.39f));