123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include "SystemComponentFixture.h"
- #include "TestAssetCode/MotionEvent.h"
- #include <EMotionFX/Source/EventManager.h>
- #include <EMotionFX/Source/MotionEventTable.h>
- #include <EMotionFX/Source/MotionManager.h>
- #include <EMotionFX/Source/Motion.h>
- #include <EMotionFX/Source/TwoStringEventData.h>
- #include <EMotionFX/Source/MotionData/NonUniformMotionData.h>
- namespace EMotionFX
- {
- struct FindEventIndicesParams
- {
- void (*m_eventFactory)(MotionEventTrack* track);
- float m_timeValue;
- size_t m_expectedLeft;
- size_t m_expectedRight;
- };
- void PrintTo(FindEventIndicesParams const object, ::std::ostream* os)
- {
- if (object.m_eventFactory == &MakeNoEvents)
- {
- *os << "Events: 0";
- }
- else if (object.m_eventFactory == &MakeOneEvent)
- {
- *os << "Events: 1";
- }
- else if (object.m_eventFactory == &MakeTwoEvents)
- {
- *os << "Events: 2";
- }
- else if (object.m_eventFactory == &MakeThreeEvents)
- {
- *os << "Events: 3";
- }
- else
- {
- *os << "Events: Unknown";
- }
- *os << " Time value: " << object.m_timeValue
- << " Expected left: " << object.m_expectedLeft
- << " Expected right: " << object.m_expectedRight
- ;
- }
- class TestFindEventIndicesFixture : public SystemComponentFixture,
- public ::testing::WithParamInterface<FindEventIndicesParams>
- {
- void SetUp() override
- {
- SystemComponentFixture::SetUp();
- m_motion = aznew Motion("TestFindEventIndicesMotion");
- m_motion->SetMotionData(aznew NonUniformMotionData());
- m_motion->GetMotionData()->SetDuration(2.0f);
- m_motion->GetEventTable()->AutoCreateSyncTrack(m_motion);
- m_syncTrack = m_motion->GetEventTable()->GetSyncTrack();
- const FindEventIndicesParams& params = GetParam();
- params.m_eventFactory(m_syncTrack);
- }
- void TearDown() override
- {
- m_motion->Destroy();
- SystemComponentFixture::TearDown();
- }
- protected:
- Motion* m_motion = nullptr;
- AnimGraphSyncTrack* m_syncTrack = nullptr;
- };
- TEST_P(TestFindEventIndicesFixture, TestFindEventIndices)
- {
- const FindEventIndicesParams& params = GetParam();
- size_t indexLeft, indexRight;
- m_syncTrack->FindEventIndices(params.m_timeValue, &indexLeft, &indexRight);
- EXPECT_EQ(indexLeft, params.m_expectedLeft);
- EXPECT_EQ(indexRight, params.m_expectedRight);
- }
- INSTANTIATE_TEST_SUITE_P(TestFindEventIndices, TestFindEventIndicesFixture,
- ::testing::ValuesIn(std::vector<FindEventIndicesParams> {
- {
- MakeNoEvents,
- 0.5f,
- InvalidIndex,
- InvalidIndex
- },
- {
- MakeOneEvent,
- 0.0f,
- 0,
- 0
- },
- {
- MakeOneEvent,
- 0.5f,
- 0,
- 0
- },
- {
- MakeTwoEvents,
- 0.0f,
- 1,
- 0
- },
- {
- MakeTwoEvents,
- 0.5f,
- 0,
- 1
- },
- {
- MakeTwoEvents,
- 1.0f,
- 1,
- 0
- },
- {
- MakeThreeEvents,
- 0.0f,
- 2,
- 0
- },
- {
- MakeThreeEvents,
- 0.5f,
- 0,
- 1
- },
- {
- MakeThreeEvents,
- 1.0f,
- 1,
- 2
- },
- {
- MakeThreeEvents,
- 1.5f,
- 2,
- 0
- },
- {
- [](MotionEventTrack* track)
- {
- MakeTwoEvents(track);
- MakeTwoEvents(track);
- },
- 0.25,
- 1,
- 2
- },
- })
- );
- struct FindMatchingEventsParams
- {
- void (*m_eventFactory)(MotionEventTrack* track);
- size_t m_startingIndex;
- size_t m_inEventAIndex;
- size_t m_inEventBIndex;
- size_t m_expectedEventA;
- size_t m_expectedEventB;
- bool m_mirrorInput;
- bool m_mirrorOutput;
- bool m_forward;
- };
- void PrintTo(FindMatchingEventsParams const object, ::std::ostream* os)
- {
- if (object.m_eventFactory == &MakeNoEvents)
- {
- *os << "Events: 0";
- }
- else if (object.m_eventFactory == &MakeOneEvent)
- {
- *os << "Events: 1";
- }
- else if (object.m_eventFactory == &MakeTwoLeftRightEvents)
- {
- *os << "Events: LRLR";
- }
- else
- {
- *os << "Events: Unknown";
- }
- *os << " Start index: " << object.m_startingIndex
- << " In Event A: " << object.m_inEventAIndex
- << " In Event B: " << object.m_inEventBIndex
- << " Expected Event A: " << object.m_expectedEventA
- << " Expected Event B: " << object.m_expectedEventB
- << " Mirror Input: " << object.m_mirrorInput
- << " Mirror Output: " << object.m_mirrorOutput
- << " Play direction: " << (object.m_forward ? "Forward" : "Backward")
- ;
- }
- class TestFindMatchingEventsFixture : public SystemComponentFixture,
- public ::testing::WithParamInterface<FindMatchingEventsParams>
- {
- void SetUp() override
- {
- SystemComponentFixture::SetUp();
- m_motion = aznew Motion("TestFindMatchingEventsMotion");
- m_motion->SetMotionData(aznew NonUniformMotionData());
- m_motion->GetMotionData()->SetDuration(4.0f);
- m_motion->GetEventTable()->AutoCreateSyncTrack(m_motion);
- m_syncTrack = m_motion->GetEventTable()->GetSyncTrack();
- const FindMatchingEventsParams& params = GetParam();
- params.m_eventFactory(m_syncTrack);
- }
- void TearDown() override
- {
- m_motion->Destroy();
- SystemComponentFixture::TearDown();
- }
- protected:
- Motion* m_motion = nullptr;
- AnimGraphSyncTrack* m_syncTrack = nullptr;
- };
- TEST_P(TestFindMatchingEventsFixture, TestFindMatchingEvents)
- {
- const FindMatchingEventsParams& params = GetParam();
- // Make sure we have an event to get the id of
- const size_t eventCount = m_syncTrack->GetNumEvents();
- const size_t eventAID = eventCount ? m_syncTrack->GetEvent(params.m_inEventAIndex).HashForSyncing(params.m_mirrorInput) : 0;
- const size_t eventBID = eventCount ? m_syncTrack->GetEvent(params.m_inEventBIndex).HashForSyncing(params.m_mirrorInput) : 0;
- size_t outLeft, outRight;
- m_syncTrack->FindMatchingEvents(
- params.m_startingIndex,
- eventAID,
- eventBID,
- &outLeft,
- &outRight,
- params.m_forward,
- params.m_mirrorOutput
- );
- EXPECT_EQ(outLeft, params.m_expectedEventA);
- EXPECT_EQ(outRight, params.m_expectedEventB);
- }
- INSTANTIATE_TEST_SUITE_P(TestFindMatchingEvents, TestFindMatchingEventsFixture,
- ::testing::ValuesIn(std::vector<FindMatchingEventsParams> {
- // With no events, it shouldn't matter what we put in, we'll get
- // back invalid indices
- {
- MakeNoEvents,
- 0, // startingIndex
- 0, // inEventAIndex
- 1, // inEventBIndex
- InvalidIndex, // expectedEventA
- InvalidIndex, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- true // forward
- },
- // With just one event, we'll always get back indices (0,0)
- {
- MakeOneEvent,
- 0, // startingIndex
- 0, // inEventAIndex
- 0, // inEventBIndex
- 0, // expectedEventA
- 0, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- true // forward
- },
- // When forward is true
- // Look for L->R events. The L->R event pairs are (0,1) and (2,3)
- // (expectedEventA will be 0 or 2 and expectedEventB will be 1 or 3)
- {
- // Starting at event 0[L], looking for events L->R, should find events 0 and 1
- MakeTwoLeftRightEvents,
- 0, // startingIndex
- 0, // inEventAIndex
- 1, // inEventBIndex
- 0, // expectedEventA
- 1, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- true // forward
- },
- {
- // Starting at event 1[R], looking for events L->R, should find events 2 and 3
- MakeTwoLeftRightEvents,
- 1, // startingIndex
- 0, // inEventAIndex
- 1, // inEventBIndex
- 2, // expectedEventA
- 3, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- true // forward
- },
- {
- // Starting at event 2[L], looking for events L->R, should find events 2 and 3
- MakeTwoLeftRightEvents,
- 2, // startingIndex
- 0, // inEventAIndex
- 1, // inEventBIndex
- 2, // expectedEventA
- 3, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- true // forward
- },
- {
- // Starting at event 3[R], looking for events L->R, should find events 0 and 1
- MakeTwoLeftRightEvents,
- 3, // startingIndex
- 0, // inEventAIndex
- 1, // inEventBIndex
- 0, // expectedEventA
- 1, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- true // forward
- },
- // Look for R->L events. The R->R event pairs are (1,2) and (3,0)
- // (expectedEventA will be 1 or 3 and expectedEventB will be 2 or 0)
- {
- // Starting at event 0[L], looking for events R->L, should find events 1 and 2
- MakeTwoLeftRightEvents,
- 0, // startingIndex
- 1, // inEventAIndex
- 2, // inEventBIndex
- 1, // expectedEventA
- 2, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- true // forward
- },
- {
- // Starting at event 1[R], looking for events R->L, should find events 1 and 2
- MakeTwoLeftRightEvents,
- 1, // startingIndex
- 1, // inEventAIndex
- 2, // inEventBIndex
- 1, // expectedEventA
- 2, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- true // forward
- },
- {
- // Starting at event 2[L], looking for events R->L, should find events 3 and 0
- MakeTwoLeftRightEvents,
- 2, // startingIndex
- 1, // inEventAIndex
- 2, // inEventBIndex
- 3, // expectedEventA
- 0, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- true // forward
- },
- {
- // Starting at event 3[R], looking for events R->L, should find events 3 and 0
- MakeTwoLeftRightEvents,
- 3, // startingIndex
- 1, // inEventAIndex
- 2, // inEventBIndex
- 3, // expectedEventA
- 0, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- true // forward
- },
- // When forward is false
- // Look for L->R events. The L->R event pairs are (0,1) and (2,3)
- // (expectedEventA will be 0 or 2 and expectedEventB will be 1 or 3)
- {
- // Starting at event 0[L], looking for events L->R, going backward, should find events 2 and 3
- MakeTwoLeftRightEvents,
- 0, // startingIndex
- 0, // inEventAIndex
- 1, // inEventBIndex
- 2, // expectedEventA
- 3, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- false // forward
- },
- {
- // Starting at event 1[R], looking for events L->R, going backward, should find events 0 and 1
- MakeTwoLeftRightEvents,
- 1, // startingIndex
- 0, // inEventAIndex
- 1, // inEventBIndex
- 0, // expectedEventA
- 1, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- false // forward
- },
- {
- // Starting at event 2[L], looking for events L->R, going backward, should find events 0 and 1
- MakeTwoLeftRightEvents,
- 2, // startingIndex
- 0, // inEventAIndex
- 1, // inEventBIndex
- 0, // expectedEventA
- 1, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- false // forward
- },
- {
- // Starting at event 3[R], looking for events L->R, going backward, should find events 2 and 3
- MakeTwoLeftRightEvents,
- 3, // startingIndex
- 0, // inEventAIndex
- 1, // inEventBIndex
- 2, // expectedEventA
- 3, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- false // forward
- },
- // Look for R->L events. The R->R event pairs are (1,2) and (3,0)
- // (expectedEventA will be 1 or 3 and expectedEventB will be 2 or 0)
- {
- // Starting at event 0[L], looking for events R->L, going backward, should find events 3 and 0
- MakeTwoLeftRightEvents,
- 0, // startingIndex
- 1, // inEventAIndex
- 2, // inEventBIndex
- 3, // expectedEventA
- 0, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- false // forward
- },
- {
- // Starting at event 1[R], looking for events R->L, going backward, should find events 3 and 0
- MakeTwoLeftRightEvents,
- 1, // startingIndex
- 1, // inEventAIndex
- 2, // inEventBIndex
- 3, // expectedEventA
- 0, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- false // forward
- },
- {
- // Starting at event 2[L], looking for events R->L, going backward, should find events 1 and 2
- MakeTwoLeftRightEvents,
- 2, // startingIndex
- 1, // inEventAIndex
- 2, // inEventBIndex
- 1, // expectedEventA
- 2, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- false // forward
- },
- {
- // Starting at event 3[R], looking for events R->L, going backward, should find events 1 and 2
- MakeTwoLeftRightEvents,
- 3, // startingIndex
- 1, // inEventAIndex
- 2, // inEventBIndex
- 1, // expectedEventA
- 2, // expectedEventB
- false, // mirrorInput
- false, // mirrorOutput
- false // forward
- }
- })
- );
- } // end namespace EMotionFX
|