From e6fe2edfaeb23b619c3c6cd06dfabf56cb457d96 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Thu, 3 Aug 2023 21:37:08 -0700 Subject: [PATCH] better tests for advancing waypoint --- dGame/dComponents/MovingPlatformComponent.cpp | 4 +- .../MovingPlatformComponentTests.cpp | 51 +++++++++++++++---- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/dGame/dComponents/MovingPlatformComponent.cpp b/dGame/dComponents/MovingPlatformComponent.cpp index 11294c2a..caac434e 100644 --- a/dGame/dComponents/MovingPlatformComponent.cpp +++ b/dGame/dComponents/MovingPlatformComponent.cpp @@ -38,7 +38,7 @@ PlatformSubComponent::PlatformSubComponent(MovingPlatformComponent* parentCompon void PlatformSubComponent::AdvanceToNextWaypoint() { uint32_t numWaypoints = m_Path->pathWaypoints.size(); m_CurrentWaypointIndex = m_NextWaypointIndex; - uint32_t nextWaypointIndex = m_CurrentWaypointIndex; + uint32_t nextWaypointIndex = m_CurrentWaypointIndex + 1; if (numWaypoints <= nextWaypointIndex) { PathBehavior behavior = m_Path->pathBehavior; if (behavior == PathBehavior::Once) { @@ -56,7 +56,7 @@ void PlatformSubComponent::AdvanceToNextWaypoint() { void PlatformSubComponent::AdvanceToNextReverseWaypoint() { uint32_t numWaypoints = m_Path->pathWaypoints.size(); m_CurrentWaypointIndex = m_NextWaypointIndex; - int32_t nextWaypointIndex = m_CurrentWaypointIndex; + int32_t nextWaypointIndex = m_CurrentWaypointIndex - 1; if (nextWaypointIndex < 0) { PathBehavior behavior = m_Path->pathBehavior; if (behavior == PathBehavior::Once) { diff --git a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp index 79f370be..8c70c0ee 100644 --- a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp +++ b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp @@ -25,11 +25,16 @@ protected: waypointStart.position = NiPoint3(1, 2, 3); waypointStart.rotation = NiQuaternion(4, 5, 6, 7); + PathWaypoint waypointMiddle; + waypointMiddle.position = NiPoint3(4, 5, 6); + waypointMiddle.rotation = NiQuaternion(7, 8, 9, 10); + PathWaypoint waypointEnd; waypointEnd.position = NiPoint3(4, 5, 6); waypointEnd.rotation = NiQuaternion(7, 8, 9, 10); path.pathWaypoints.push_back(waypointStart); + path.pathWaypoints.push_back(waypointMiddle); path.pathWaypoints.push_back(waypointEnd); baseEntity = std::make_unique(15, GameDependenciesTest::info); @@ -304,15 +309,14 @@ TEST_F(MovingPlatformComponentTests, MovingPlatformSubComponentPathAdvanceForwar moverPlatformSubComponent.m_InReverse = false; moverPlatformSubComponent.AdvanceToNextWaypoint(); ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 1); - ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 0); - ASSERT_FALSE(moverPlatformSubComponent.m_InReverse); + ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 2); moverPlatformSubComponent.AdvanceToNextWaypoint(); - ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 1); - ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 0); + ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 2); + ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 2); ASSERT_FALSE(moverPlatformSubComponent.m_InReverse); path.pathBehavior = PathBehavior::Bounce; moverPlatformSubComponent.AdvanceToNextWaypoint(); - ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 0); + ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 2); ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 1); ASSERT_TRUE(moverPlatformSubComponent.m_InReverse); } @@ -320,23 +324,50 @@ TEST_F(MovingPlatformComponentTests, MovingPlatformSubComponentPathAdvanceForwar TEST_F(MovingPlatformComponentTests, MovingPlatformSubComponentPathAdvanceReverseTest) { MoverPlatformSubComponent moverPlatformSubComponent(nullptr); moverPlatformSubComponent._SetPath(&path); - moverPlatformSubComponent.m_CurrentWaypointIndex = 1; - moverPlatformSubComponent.m_NextWaypointIndex = 0; + moverPlatformSubComponent.m_CurrentWaypointIndex = 2; + moverPlatformSubComponent.m_NextWaypointIndex = 1; moverPlatformSubComponent.m_InReverse = true; moverPlatformSubComponent.AdvanceToNextReverseWaypoint(); + ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 1); + ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 0); + ASSERT_TRUE(moverPlatformSubComponent.m_InReverse); + moverPlatformSubComponent.AdvanceToNextReverseWaypoint(); ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 0); ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 0); ASSERT_TRUE(moverPlatformSubComponent.m_InReverse); path.pathBehavior = PathBehavior::Bounce; - moverPlatformSubComponent.m_CurrentWaypointIndex = 1; - moverPlatformSubComponent.m_NextWaypointIndex = 0; - moverPlatformSubComponent.AdvanceToNextReverseWaypoint(); + moverPlatformSubComponent.AdvanceToNextWaypoint(); ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 0); ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 1); ASSERT_TRUE(moverPlatformSubComponent.m_InReverse); +} + +TEST_F(MovingPlatformComponentTests, MovingPlatformSubComponentPathAdvanceTest) { + MoverPlatformSubComponent moverPlatformSubComponent(nullptr); + moverPlatformSubComponent._SetPath(&path); + path.pathBehavior = PathBehavior::Bounce; + moverPlatformSubComponent.m_CurrentWaypointIndex = 0; + moverPlatformSubComponent.m_NextWaypointIndex = 1; + moverPlatformSubComponent.m_InReverse = false; + moverPlatformSubComponent.AdvanceToNextWaypoint(); + ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 1); + ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 2); + ASSERT_FALSE(moverPlatformSubComponent.m_InReverse); + moverPlatformSubComponent.AdvanceToNextWaypoint(); + ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 2); + ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 1); + ASSERT_TRUE(moverPlatformSubComponent.m_InReverse); moverPlatformSubComponent.AdvanceToNextReverseWaypoint(); ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 1); ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 0); + ASSERT_TRUE(moverPlatformSubComponent.m_InReverse); + moverPlatformSubComponent.AdvanceToNextReverseWaypoint(); + ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 0); + ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 1); + ASSERT_FALSE(moverPlatformSubComponent.m_InReverse); + moverPlatformSubComponent.AdvanceToNextWaypoint(); + ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 1); + ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 2); ASSERT_FALSE(moverPlatformSubComponent.m_InReverse); }