From 1ae57dc6e80058aee67aa7462c49c26e24e80d21 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Sat, 10 Feb 2024 19:53:20 -0800 Subject: [PATCH] Fix one failing test --- dCommon/DluAssert.h | 1 + dCommon/Logger.h | 2 +- dGame/dComponents/MovingPlatformComponent.cpp | 3 +++ .../MovingPlatformComponentTests.cpp | 17 ++++++++--------- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dCommon/DluAssert.h b/dCommon/DluAssert.h index c54dd54e..d112f011 100644 --- a/dCommon/DluAssert.h +++ b/dCommon/DluAssert.h @@ -2,6 +2,7 @@ #define __DLUASSERT__H__ #include +#define _DEBUG #ifdef _DEBUG # define DluAssert(expression) assert(expression) diff --git a/dCommon/Logger.h b/dCommon/Logger.h index 5754d9ac..fc0d118f 100644 --- a/dCommon/Logger.h +++ b/dCommon/Logger.h @@ -29,7 +29,7 @@ constexpr const char* GetFileNameFromAbsolutePath(const char* path) { // they will not be valid constexpr and will be evaluated at runtime instead of compile time! // The full string is still stored in the binary, however the offset of the filename in the absolute paths // is used in the instruction instead of the start of the absolute path. -#define LOG(message, ...) do { auto str = FILENAME_AND_LINE; Game::logger->Log(str, message, ##__VA_ARGS__); } while(0) +#define LOG(message, ...) do { auto str = FILENAME_AND_LINE; Game::logger->Log(str, message, ##__VA_ARGS__); Game::logger->Flush(); } while(0) #define LOG_DEBUG(message, ...) do { auto str = FILENAME_AND_LINE; Game::logger->LogDebug(str, message, ##__VA_ARGS__); } while(0) // Writer class for writing data to files. diff --git a/dGame/dComponents/MovingPlatformComponent.cpp b/dGame/dComponents/MovingPlatformComponent.cpp index ab865d95..ece25685 100644 --- a/dGame/dComponents/MovingPlatformComponent.cpp +++ b/dGame/dComponents/MovingPlatformComponent.cpp @@ -141,6 +141,7 @@ void PlatformSubComponent::SetupPath(const std::string& pathName, uint32_t start m_InReverse = startsInReverse; m_CurrentWaypointIndex = startingWaypointIndex; m_TimeBasedMovement = m_Path->movingPlatform.timeBasedMovement; + m_NextWaypointIndex = m_InReverse ? m_CurrentWaypointIndex - 1 : m_CurrentWaypointIndex + 1; } const PathWaypoint& PlatformSubComponent::GetNextWaypoint() const { @@ -159,6 +160,8 @@ float PlatformSubComponent::CalculateSpeed() const { float unitizedDirection = 1.0f / (GetNextWaypoint().position - GetCurrentWaypoint().position).Length(); speed = unitizedDirection / GetCurrentWaypoint().movingPlatform.speed; } else { + LOG("%i %i", m_CurrentWaypointIndex, m_NextWaypointIndex); + Game::logger->Flush(); speed = (GetNextWaypoint().movingPlatform.speed - GetCurrentWaypoint().movingPlatform.speed) * m_PercentUntilNextWaypoint + GetCurrentWaypoint().movingPlatform.speed; } return speed; diff --git a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp index e809cc84..41dc6cd8 100644 --- a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp +++ b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp @@ -25,14 +25,17 @@ protected: PathWaypoint waypointStart; waypointStart.position = NiPoint3(1, 2, 3); waypointStart.rotation = NiQuaternion(4, 5, 6, 7); + waypointStart.movingPlatform.speed = 16.0f; PathWaypoint waypointMiddle; waypointMiddle.position = NiPoint3(4, 5, 6); waypointMiddle.rotation = NiQuaternion(7, 8, 9, 10); + waypointStart.movingPlatform.speed = 16.0f; PathWaypoint waypointEnd; waypointEnd.position = NiPoint3(4, 5, 7); waypointEnd.rotation = NiQuaternion(7, 8, 9, 10); + waypointStart.movingPlatform.speed = 16.0f; path.pathWaypoints.push_back(waypointStart); path.pathWaypoints.push_back(waypointMiddle); @@ -59,7 +62,6 @@ protected: auto* simplePhysicsComponent = baseEntity->AddComponent(1); auto* movingPlatformComponent = baseEntity->AddComponent("ExamplePath"); - new MovingPlatformComponent(baseEntity.get(), path.pathName); movingPlatformComponent->LoadConfigData(); movingPlatformComponent->LoadDataFromTemplate(); } @@ -286,17 +288,14 @@ TEST_F(MovingPlatformComponentTests, MovingPlatformSubComponentPathAdvanceTest) TEST_F(MovingPlatformComponentTests, MovingPlatformMoverSpeedCalculationTest) { MoverPlatformSubComponent moverPlatformSubComponent(baseEntity->GetComponent()); - path.pathWaypoints.at(0).position = NiPoint3(99.296440, 419.293335, 207.219498); - path.pathWaypoints.at(0).movingPlatform.speed = 16.0f; - path.pathWaypoints.at(1).position = NiPoint3(141.680099, 419.990051, 208.680450); - path.pathWaypoints.at(1).movingPlatform.speed = 16.0f; - path.pathBehavior = PathBehavior::Bounce; + moverPlatformSubComponent.SetupPath("ExamplePath", 0, false); + ASSERT_EQ(moverPlatformSubComponent.CalculateSpeed(), 16.0f); NiPoint3 r = moverPlatformSubComponent.CalculateLinearVelocity(); - ASSERT_FLOAT_EQ(r.x, 15.988346099854); - ASSERT_FLOAT_EQ(r.y, 0.26282161474228); - ASSERT_FLOAT_EQ(r.z, 0.5511137843132); + ASSERT_FLOAT_EQ(r.x, 9.2376051); + ASSERT_FLOAT_EQ(r.y, 9.2376051); + ASSERT_FLOAT_EQ(r.z, 9.2376051); moverPlatformSubComponent.AdvanceToNextWaypoint(); }