Fix one failing test

This commit is contained in:
David Markowitz 2024-02-10 19:53:20 -08:00
parent 944d3e1bac
commit 1ae57dc6e8
4 changed files with 13 additions and 10 deletions

View File

@ -2,6 +2,7 @@
#define __DLUASSERT__H__ #define __DLUASSERT__H__
#include <assert.h> #include <assert.h>
#define _DEBUG
#ifdef _DEBUG #ifdef _DEBUG
# define DluAssert(expression) assert(expression) # define DluAssert(expression) assert(expression)

View File

@ -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! // 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 // 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. // 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) #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. // Writer class for writing data to files.

View File

@ -141,6 +141,7 @@ void PlatformSubComponent::SetupPath(const std::string& pathName, uint32_t start
m_InReverse = startsInReverse; m_InReverse = startsInReverse;
m_CurrentWaypointIndex = startingWaypointIndex; m_CurrentWaypointIndex = startingWaypointIndex;
m_TimeBasedMovement = m_Path->movingPlatform.timeBasedMovement; m_TimeBasedMovement = m_Path->movingPlatform.timeBasedMovement;
m_NextWaypointIndex = m_InReverse ? m_CurrentWaypointIndex - 1 : m_CurrentWaypointIndex + 1;
} }
const PathWaypoint& PlatformSubComponent::GetNextWaypoint() const { const PathWaypoint& PlatformSubComponent::GetNextWaypoint() const {
@ -159,6 +160,8 @@ float PlatformSubComponent::CalculateSpeed() const {
float unitizedDirection = 1.0f / (GetNextWaypoint().position - GetCurrentWaypoint().position).Length(); float unitizedDirection = 1.0f / (GetNextWaypoint().position - GetCurrentWaypoint().position).Length();
speed = unitizedDirection / GetCurrentWaypoint().movingPlatform.speed; speed = unitizedDirection / GetCurrentWaypoint().movingPlatform.speed;
} else { } else {
LOG("%i %i", m_CurrentWaypointIndex, m_NextWaypointIndex);
Game::logger->Flush();
speed = (GetNextWaypoint().movingPlatform.speed - GetCurrentWaypoint().movingPlatform.speed) * m_PercentUntilNextWaypoint + GetCurrentWaypoint().movingPlatform.speed; speed = (GetNextWaypoint().movingPlatform.speed - GetCurrentWaypoint().movingPlatform.speed) * m_PercentUntilNextWaypoint + GetCurrentWaypoint().movingPlatform.speed;
} }
return speed; return speed;

View File

@ -25,14 +25,17 @@ protected:
PathWaypoint waypointStart; PathWaypoint waypointStart;
waypointStart.position = NiPoint3(1, 2, 3); waypointStart.position = NiPoint3(1, 2, 3);
waypointStart.rotation = NiQuaternion(4, 5, 6, 7); waypointStart.rotation = NiQuaternion(4, 5, 6, 7);
waypointStart.movingPlatform.speed = 16.0f;
PathWaypoint waypointMiddle; PathWaypoint waypointMiddle;
waypointMiddle.position = NiPoint3(4, 5, 6); waypointMiddle.position = NiPoint3(4, 5, 6);
waypointMiddle.rotation = NiQuaternion(7, 8, 9, 10); waypointMiddle.rotation = NiQuaternion(7, 8, 9, 10);
waypointStart.movingPlatform.speed = 16.0f;
PathWaypoint waypointEnd; PathWaypoint waypointEnd;
waypointEnd.position = NiPoint3(4, 5, 7); waypointEnd.position = NiPoint3(4, 5, 7);
waypointEnd.rotation = NiQuaternion(7, 8, 9, 10); waypointEnd.rotation = NiQuaternion(7, 8, 9, 10);
waypointStart.movingPlatform.speed = 16.0f;
path.pathWaypoints.push_back(waypointStart); path.pathWaypoints.push_back(waypointStart);
path.pathWaypoints.push_back(waypointMiddle); path.pathWaypoints.push_back(waypointMiddle);
@ -59,7 +62,6 @@ protected:
auto* simplePhysicsComponent = baseEntity->AddComponent<SimplePhysicsComponent>(1); auto* simplePhysicsComponent = baseEntity->AddComponent<SimplePhysicsComponent>(1);
auto* movingPlatformComponent = baseEntity->AddComponent<MovingPlatformComponent>("ExamplePath"); auto* movingPlatformComponent = baseEntity->AddComponent<MovingPlatformComponent>("ExamplePath");
new MovingPlatformComponent(baseEntity.get(), path.pathName);
movingPlatformComponent->LoadConfigData(); movingPlatformComponent->LoadConfigData();
movingPlatformComponent->LoadDataFromTemplate(); movingPlatformComponent->LoadDataFromTemplate();
} }
@ -286,17 +288,14 @@ TEST_F(MovingPlatformComponentTests, MovingPlatformSubComponentPathAdvanceTest)
TEST_F(MovingPlatformComponentTests, MovingPlatformMoverSpeedCalculationTest) { TEST_F(MovingPlatformComponentTests, MovingPlatformMoverSpeedCalculationTest) {
MoverPlatformSubComponent moverPlatformSubComponent(baseEntity->GetComponent<MovingPlatformComponent>()); MoverPlatformSubComponent moverPlatformSubComponent(baseEntity->GetComponent<MovingPlatformComponent>());
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); moverPlatformSubComponent.SetupPath("ExamplePath", 0, false);
path.pathWaypoints.at(1).movingPlatform.speed = 16.0f;
path.pathBehavior = PathBehavior::Bounce;
ASSERT_EQ(moverPlatformSubComponent.CalculateSpeed(), 16.0f); ASSERT_EQ(moverPlatformSubComponent.CalculateSpeed(), 16.0f);
NiPoint3 r = moverPlatformSubComponent.CalculateLinearVelocity(); NiPoint3 r = moverPlatformSubComponent.CalculateLinearVelocity();
ASSERT_FLOAT_EQ(r.x, 15.988346099854); ASSERT_FLOAT_EQ(r.x, 9.2376051);
ASSERT_FLOAT_EQ(r.y, 0.26282161474228); ASSERT_FLOAT_EQ(r.y, 9.2376051);
ASSERT_FLOAT_EQ(r.z, 0.5511137843132); ASSERT_FLOAT_EQ(r.z, 9.2376051);
moverPlatformSubComponent.AdvanceToNextWaypoint(); moverPlatformSubComponent.AdvanceToNextWaypoint();
} }