AnimGraphStateMachineTests.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Serialization/SerializeContext.h>
  9. #include <AzCore/Serialization/Utils.h>
  10. #include <EMotionFX/Source/EventHandler.h>
  11. #include <EMotionFX/Source/AnimGraphMotionNode.h>
  12. #include <EMotionFX/Source/AnimGraphStateMachine.h>
  13. #include <EMotionFX/Source/MotionSet.h>
  14. #include <Tests/AnimGraphFixture.h>
  15. namespace EMotionFX
  16. {
  17. #ifdef ENABLE_SINGLEFRAME_MULTISTATETRANSITIONING
  18. class AnimGraphStateMachine_MultiplePassesSingleFrameFixture : public AnimGraphFixture
  19. , public ::testing::WithParamInterface</*numStates*/int>
  20. {
  21. public:
  22. void ConstructGraph() override
  23. {
  24. const int numStates = GetParam();
  25. AnimGraphFixture::ConstructGraph();
  26. /*
  27. +-------+ +---+ +---+ +---+
  28. | Start |--->| A |--->| B |---> ... --->| N |
  29. +-------+ +---+ +---+ +---+
  30. BlendTime & CountDownTime = 0.0 m_lastState
  31. */
  32. AnimGraphNode* stateStart = aznew AnimGraphMotionNode();
  33. m_rootStateMachine->AddChildNode(stateStart);
  34. m_rootStateMachine->SetEntryState(stateStart);
  35. const char startChar = 'A';
  36. AnimGraphNode* prevState = stateStart;
  37. for (int i = 0; i < numStates; ++i)
  38. {
  39. AnimGraphNode* state = aznew AnimGraphMotionNode();
  40. state->SetName(AZStd::string(1, startChar + i).c_str());
  41. m_rootStateMachine->AddChildNode(state);
  42. AddTransitionWithTimeCondition(prevState, state, /*blendTime*/0.0f, /*countDownTime*/0.0f);
  43. prevState = state;
  44. }
  45. m_lastState = prevState;
  46. }
  47. AnimGraphNode* m_lastState = nullptr;
  48. };
  49. TEST_P(AnimGraphStateMachine_MultiplePassesSingleFrameFixture, TestAnimGraphStateMachine_MultiplePassesSingleFrameTest)
  50. {
  51. Simulate(/*simulationTime*/0.0f, /*expectedFps*/60.0f, /*fpsVariance*/0.0f,
  52. /*preCallback*/[this](AnimGraphInstance* animGraphInstance)
  53. {
  54. },
  55. /*postCallback*/[this](AnimGraphInstance* animGraphInstance)
  56. {
  57. // Check if we transitioned through the whole state machine and are at the last state.
  58. const AnimGraphNode* currentState = this->m_rootStateMachine->GetCurrentState(animGraphInstance);
  59. EXPECT_EQ(this->m_lastState, currentState);
  60. },
  61. /*preUpdateCallback*/[this](AnimGraphInstance*, float, float, int) {},
  62. /*postUpdateCallback*/[this](AnimGraphInstance*, float, float, int) {}
  63. );
  64. }
  65. std::vector<int> animGraphStateMachinePassesTestData
  66. {
  67. 1/*numStates*/,
  68. 2,
  69. 3,
  70. 8,
  71. static_cast<int>(AnimGraphStateMachine::GetMaxNumPasses())
  72. };
  73. INSTANTIATE_TEST_CASE_P(TestAnimGraphStateMachine_MultiplePassesSingleFrameTest,
  74. AnimGraphStateMachine_MultiplePassesSingleFrameFixture,
  75. ::testing::ValuesIn(animGraphStateMachinePassesTestData)
  76. );
  77. #endif
  78. } // EMotionFX