mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-10 01:18:07 +00:00
refactor to class style and not c style
This commit is contained in:
@@ -12,3 +12,28 @@ namespace Game {
|
||||
SystemAddress chatSysAddr;
|
||||
EntityManager* entityManager = nullptr;
|
||||
}
|
||||
|
||||
void GameDependenciesTest::SetUpDependencies() {
|
||||
info.pos = NiPoint3::ZERO;
|
||||
info.rot = NiQuaternion::IDENTITY;
|
||||
info.scale = 1.0f;
|
||||
info.spawner = nullptr;
|
||||
info.lot = 999;
|
||||
Game::logger = new dLogger("./testing.log", true, true);
|
||||
Game::server = new dServerMock();
|
||||
Game::config = new dConfig("worldconfig.ini");
|
||||
Game::entityManager = new EntityManager();
|
||||
Game::zoneManager = new dZoneManager();
|
||||
Game::zoneManager->LoadZone(LWOZONEID(0, 0, 0));
|
||||
}
|
||||
|
||||
void GameDependenciesTest::TearDownDependencies() {
|
||||
if (Game::server) delete Game::server;
|
||||
if (Game::entityManager) delete Game::entityManager;
|
||||
if (Game::config) delete Game::config;
|
||||
if (Game::zoneManager) delete Game::zoneManager;
|
||||
if (Game::logger) {
|
||||
Game::logger->Flush();
|
||||
delete Game::logger;
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "dServer.h"
|
||||
#include "EntityInfo.h"
|
||||
#include "EntityManager.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "dConfig.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -23,29 +24,11 @@ public:
|
||||
|
||||
class GameDependenciesTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUpDependencies() {
|
||||
info.pos = NiPoint3::ZERO;
|
||||
info.rot = NiQuaternion::IDENTITY;
|
||||
info.scale = 1.0f;
|
||||
info.spawner = nullptr;
|
||||
info.lot = 999;
|
||||
Game::logger = new dLogger("./testing.log", true, true);
|
||||
Game::server = new dServerMock();
|
||||
Game::config = new dConfig("worldconfig.ini");
|
||||
Game::entityManager = new EntityManager();
|
||||
}
|
||||
void SetUpDependencies();
|
||||
|
||||
void TearDownDependencies() {
|
||||
if (Game::server) delete Game::server;
|
||||
if (Game::entityManager) delete Game::entityManager;
|
||||
if (Game::logger) {
|
||||
Game::logger->Flush();
|
||||
delete Game::logger;
|
||||
}
|
||||
if (Game::config) delete Game::config;
|
||||
}
|
||||
void TearDownDependencies();
|
||||
|
||||
EntityInfo info{};
|
||||
EntityInfo info;
|
||||
};
|
||||
|
||||
#endif //!__GAMEDEPENDENCIES__H__
|
||||
|
@@ -21,6 +21,7 @@ protected:
|
||||
SetUpDependencies();
|
||||
path.movingPlatform.timeBasedMovement = false;
|
||||
path.pathBehavior = PathBehavior::Once;
|
||||
path.pathName = "ExamplePath";
|
||||
PathWaypoint waypointStart;
|
||||
waypointStart.position = NiPoint3(1, 2, 3);
|
||||
waypointStart.rotation = NiQuaternion(4, 5, 6, 7);
|
||||
@@ -37,219 +38,38 @@ protected:
|
||||
path.pathWaypoints.push_back(waypointMiddle);
|
||||
path.pathWaypoints.push_back(waypointEnd);
|
||||
|
||||
Game::zoneManager->GetZone()->AddPath(path);
|
||||
|
||||
// Set our starting position
|
||||
info.pos = NiPoint3(25, 26, 27);
|
||||
info.rot = NiQuaternion(28, 29, 30, 31);
|
||||
|
||||
// Simple mover data
|
||||
info.settings.push_back(new LDFData<float>(u"platformMoveX", 23));
|
||||
info.settings.push_back(new LDFData<float>(u"platformMoveY", 453));
|
||||
info.settings.push_back(new LDFData<float>(u"platformMoveZ", 523));
|
||||
info.settings.push_back(new LDFData<float>(u"platformMoveTime", 5724));
|
||||
info.settings.push_back(new LDFData<bool>(u"platformStartAtEnd", true));
|
||||
info.settings.push_back(new LDFData<bool>(u"dbonly", false));
|
||||
info.settings.push_back(new LDFData<bool>(u"platformIsMover", true));
|
||||
info.settings.push_back(new LDFData<bool>(u"platformIsSimpleMover", true));
|
||||
info.settings.push_back(new LDFData<bool>(u"platformIsRotater", true));
|
||||
|
||||
baseEntity = std::make_unique<Entity>(15, GameDependenciesTest::info);
|
||||
baseEntity->SetVar<bool>(u"dbonly", false);
|
||||
baseEntity->SetVar<float>(u"platformMoveX", 23);
|
||||
baseEntity->SetVar<float>(u"platformMoveY", 453);
|
||||
baseEntity->SetVar<float>(u"platformMoveZ", 523);
|
||||
baseEntity->SetVar<float>(u"platformMoveTime", 5724);
|
||||
baseEntity->SetVar<bool>(u"platformStartAtEnd", true);
|
||||
auto* movingPlatformComponent = new MovingPlatformComponent(baseEntity.get(), "");
|
||||
|
||||
auto* simplePhysicsComponent = new SimplePhysicsComponent(1, baseEntity.get());
|
||||
baseEntity->AddComponent(eReplicaComponentType::MOVING_PLATFORM, movingPlatformComponent);
|
||||
baseEntity->AddComponent(eReplicaComponentType::SIMPLE_PHYSICS, simplePhysicsComponent);
|
||||
baseEntity->SetPosition(NiPoint3(25, 26, 27));
|
||||
baseEntity->SetRotation(NiQuaternion(28, 29, 30, 31));
|
||||
auto moverPlatformSubComponent = std::make_unique<MoverPlatformSubComponent>(movingPlatformComponent);
|
||||
moverPlatformSubComponent->m_State = eMovementPlatformState::Stopped | eMovementPlatformState::ReachedDesiredWaypoint;
|
||||
moverPlatformSubComponent->m_DesiredWaypointIndex = 1;
|
||||
moverPlatformSubComponent->m_PercentUntilNextWaypoint = 2;
|
||||
moverPlatformSubComponent->m_Position = NiPoint3(3, 4, 5);
|
||||
moverPlatformSubComponent->m_CurrentWaypointIndex = 6;
|
||||
moverPlatformSubComponent->m_NextWaypointIndex = 7;
|
||||
moverPlatformSubComponent->m_IdleTimeElapsed = 8;
|
||||
moverPlatformSubComponent->m_MoveTimeElapsed = 11;
|
||||
moverPlatformSubComponent->m_IsDirty = true;
|
||||
moverPlatformSubComponent->m_InReverse = true;
|
||||
moverPlatformSubComponent->m_ShouldStopAtDesiredWaypoint = true;
|
||||
|
||||
auto rotatorPlatformSubComponent = std::make_unique<RotatorPlatformSubComponent>(movingPlatformComponent);
|
||||
rotatorPlatformSubComponent->m_State = eMovementPlatformState::Travelling;
|
||||
rotatorPlatformSubComponent->m_DesiredWaypointIndex = 12;
|
||||
rotatorPlatformSubComponent->m_PercentUntilNextWaypoint = 13;
|
||||
rotatorPlatformSubComponent->m_Position = NiPoint3(14, 15, 16);
|
||||
rotatorPlatformSubComponent->m_CurrentWaypointIndex = 17;
|
||||
rotatorPlatformSubComponent->m_NextWaypointIndex = 18;
|
||||
rotatorPlatformSubComponent->m_IdleTimeElapsed = 19;
|
||||
rotatorPlatformSubComponent->m_MoveTimeElapsed = 22;
|
||||
rotatorPlatformSubComponent->m_IsDirty = true;
|
||||
rotatorPlatformSubComponent->m_InReverse = true;
|
||||
rotatorPlatformSubComponent->m_ShouldStopAtDesiredWaypoint = true;
|
||||
|
||||
auto simpleMoverPlatformSubComponent = std::make_unique<SimpleMoverPlatformSubComponent>(movingPlatformComponent, NiPoint3(), true);
|
||||
simpleMoverPlatformSubComponent->m_State = eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint;
|
||||
simpleMoverPlatformSubComponent->m_DesiredWaypointIndex = 23;
|
||||
simpleMoverPlatformSubComponent->m_PercentUntilNextWaypoint = 24;
|
||||
simpleMoverPlatformSubComponent->m_CurrentWaypointIndex = 28;
|
||||
simpleMoverPlatformSubComponent->m_NextWaypointIndex = 29;
|
||||
simpleMoverPlatformSubComponent->m_IdleTimeElapsed = 30;
|
||||
simpleMoverPlatformSubComponent->m_MoveTimeElapsed = 33;
|
||||
simpleMoverPlatformSubComponent->m_IsDirty = true;
|
||||
simpleMoverPlatformSubComponent->m_InReverse = true;
|
||||
simpleMoverPlatformSubComponent->m_DirtyStartingPoint = true;
|
||||
simpleMoverPlatformSubComponent->m_HasStartingPoint = true;
|
||||
simpleMoverPlatformSubComponent->m_ShouldStopAtDesiredWaypoint = true;
|
||||
simpleMoverPlatformSubComponent->LoadConfigData();
|
||||
|
||||
movingPlatformComponent->_AddPlatformSubComponent(std::move(moverPlatformSubComponent));
|
||||
movingPlatformComponent->_AddPlatformSubComponent(std::move(rotatorPlatformSubComponent));
|
||||
movingPlatformComponent->_AddPlatformSubComponent(std::move(simpleMoverPlatformSubComponent));
|
||||
movingPlatformComponent->_SetPath(u"ExamplePath");
|
||||
baseEntity->AddComponent(SimplePhysicsComponent::ComponentType, simplePhysicsComponent);
|
||||
auto* movingPlatformComponent = new MovingPlatformComponent(baseEntity.get(), path.pathName);
|
||||
movingPlatformComponent->LoadConfigData();
|
||||
movingPlatformComponent->LoadDataFromTemplate();
|
||||
baseEntity->AddComponent(MovingPlatformComponent::ComponentType, movingPlatformComponent);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
TearDownDependencies();
|
||||
}
|
||||
|
||||
void TestSerialization() {
|
||||
auto* movingPlatformComponent = baseEntity->GetComponent<MovingPlatformComponent>();
|
||||
ASSERT_NE(movingPlatformComponent, nullptr);
|
||||
uint32_t flags = 0;
|
||||
movingPlatformComponent->Serialize(&bitStream, true, flags);
|
||||
// read in the full BitStream and check the values match what they were set to above
|
||||
bool hasPlatformSubComponents = false;
|
||||
bitStream.Read(hasPlatformSubComponents);
|
||||
ASSERT_TRUE(hasPlatformSubComponents);
|
||||
|
||||
bool dirtyPathInfo;
|
||||
bitStream.Read(dirtyPathInfo);
|
||||
ASSERT_TRUE(dirtyPathInfo);
|
||||
|
||||
bool hasPath;
|
||||
bitStream.Read(hasPath);
|
||||
ASSERT_TRUE(hasPath);
|
||||
|
||||
std::u16string pathName;
|
||||
uint16_t pathNameLength;
|
||||
bitStream.Read(pathNameLength);
|
||||
pathName.resize(pathNameLength);
|
||||
bitStream.ReadBits(reinterpret_cast<unsigned char*>(pathName.data()), BYTES_TO_BITS(pathNameLength) * 2);
|
||||
ASSERT_EQ(pathName, u"ExamplePath");
|
||||
|
||||
uint32_t pathStartIndex;
|
||||
bitStream.Read(pathStartIndex);
|
||||
ASSERT_EQ(pathStartIndex, 0);
|
||||
|
||||
bool isInReverse;
|
||||
bitStream.Read(isInReverse);
|
||||
ASSERT_FALSE(isInReverse);
|
||||
|
||||
bool hasPlatformData;
|
||||
bitStream.Read(hasPlatformData);
|
||||
ASSERT_TRUE(hasPlatformData);
|
||||
|
||||
eMoverSubComponentType platformType;
|
||||
bitStream.Read(platformType);
|
||||
ASSERT_EQ(platformType, eMoverSubComponentType::Mover);
|
||||
|
||||
bool isDirty;
|
||||
bitStream.Read(isDirty);
|
||||
ASSERT_TRUE(isDirty);
|
||||
|
||||
eMovementPlatformState state;
|
||||
bitStream.Read(state);
|
||||
ASSERT_EQ(state, eMovementPlatformState::Stopped | eMovementPlatformState::ReachedDesiredWaypoint);
|
||||
|
||||
int32_t desiredWaypointIndex;
|
||||
bitStream.Read(desiredWaypointIndex);
|
||||
ASSERT_EQ(desiredWaypointIndex, 1);
|
||||
|
||||
bool shouldStopAtDesiredWaypoint;
|
||||
bitStream.Read(shouldStopAtDesiredWaypoint);
|
||||
ASSERT_TRUE(shouldStopAtDesiredWaypoint);
|
||||
|
||||
bool isInReverse2;
|
||||
bitStream.Read(isInReverse2);
|
||||
ASSERT_TRUE(isInReverse2);
|
||||
|
||||
float percentBetweenPoints;
|
||||
bitStream.Read(percentBetweenPoints);
|
||||
ASSERT_EQ(percentBetweenPoints, 2);
|
||||
|
||||
NiPoint3 position;
|
||||
bitStream.Read(position.x);
|
||||
bitStream.Read(position.y);
|
||||
bitStream.Read(position.z);
|
||||
ASSERT_EQ(position, NiPoint3(3, 4, 5));
|
||||
|
||||
uint32_t currentWaypointIndex;
|
||||
bitStream.Read(currentWaypointIndex);
|
||||
ASSERT_EQ(currentWaypointIndex, 6);
|
||||
|
||||
uint32_t nextWaypointIndex;
|
||||
bitStream.Read(nextWaypointIndex);
|
||||
ASSERT_EQ(nextWaypointIndex, 7);
|
||||
|
||||
float idleTimeElapsed;
|
||||
bitStream.Read(idleTimeElapsed);
|
||||
ASSERT_EQ(idleTimeElapsed, 8);
|
||||
|
||||
float moveTimeElapsed;
|
||||
bitStream.Read(moveTimeElapsed);
|
||||
ASSERT_EQ(moveTimeElapsed, 11);
|
||||
|
||||
bool hasPlatformData2;
|
||||
bitStream.Read(hasPlatformData2);
|
||||
ASSERT_TRUE(hasPlatformData2);
|
||||
|
||||
eMoverSubComponentType platformType2;
|
||||
bitStream.Read(platformType2);
|
||||
ASSERT_EQ(platformType2, eMoverSubComponentType::Rotator);
|
||||
|
||||
bool isDirty2;
|
||||
bitStream.Read(isDirty2);
|
||||
ASSERT_TRUE(isDirty2);
|
||||
|
||||
eMovementPlatformState state2;
|
||||
bitStream.Read(state2);
|
||||
ASSERT_EQ(state2, eMovementPlatformState::Travelling);
|
||||
|
||||
int32_t desiredWaypointIndex2;
|
||||
bitStream.Read(desiredWaypointIndex2);
|
||||
ASSERT_EQ(desiredWaypointIndex2, 12);
|
||||
|
||||
bool shouldStopAtDesiredWaypoint2;
|
||||
bitStream.Read(shouldStopAtDesiredWaypoint2);
|
||||
ASSERT_TRUE(shouldStopAtDesiredWaypoint2);
|
||||
|
||||
bool isInReverse3;
|
||||
bitStream.Read(isInReverse3);
|
||||
ASSERT_TRUE(isInReverse3);
|
||||
|
||||
float percentBetweenPoints2;
|
||||
bitStream.Read(percentBetweenPoints2);
|
||||
ASSERT_EQ(percentBetweenPoints2, 13);
|
||||
|
||||
NiPoint3 position2;
|
||||
bitStream.Read(position2.x);
|
||||
bitStream.Read(position2.y);
|
||||
bitStream.Read(position2.z);
|
||||
ASSERT_EQ(position2, NiPoint3(14, 15, 16));
|
||||
|
||||
uint32_t currentWaypointIndex2;
|
||||
bitStream.Read(currentWaypointIndex2);
|
||||
ASSERT_EQ(currentWaypointIndex2, 17);
|
||||
|
||||
uint32_t nextWaypointIndex2;
|
||||
bitStream.Read(nextWaypointIndex2);
|
||||
ASSERT_EQ(nextWaypointIndex2, 18);
|
||||
|
||||
float idleTimeElapsed2;
|
||||
bitStream.Read(idleTimeElapsed2);
|
||||
ASSERT_EQ(idleTimeElapsed2, 19);
|
||||
|
||||
float moveTimeElapsed2;
|
||||
bitStream.Read(moveTimeElapsed2);
|
||||
ASSERT_EQ(moveTimeElapsed2, 22);
|
||||
|
||||
bool hasPlatformData3;
|
||||
bitStream.Read(hasPlatformData3);
|
||||
ASSERT_TRUE(hasPlatformData3);
|
||||
|
||||
eMoverSubComponentType platformType3;
|
||||
bitStream.Read(platformType3);
|
||||
ASSERT_EQ(platformType3, eMoverSubComponentType::SimpleMover);
|
||||
|
||||
void DeserializeSimpleMoverPlatformSubComponent() {
|
||||
bool dirtyStartingPoint;
|
||||
bitStream.Read(dirtyStartingPoint);
|
||||
ASSERT_TRUE(dirtyStartingPoint);
|
||||
@@ -271,25 +91,133 @@ protected:
|
||||
bitStream.Read(startingRotation.z);
|
||||
ASSERT_EQ(startingRotation, NiQuaternion(28, 29, 30, 31));
|
||||
|
||||
bool isDirty4;
|
||||
bitStream.Read(isDirty4);
|
||||
ASSERT_TRUE(isDirty4);
|
||||
bool isDirty;
|
||||
bitStream.Read(isDirty);
|
||||
ASSERT_TRUE(isDirty);
|
||||
|
||||
eMovementPlatformState state3;
|
||||
bitStream.Read(state3);
|
||||
ASSERT_EQ(state3, eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint);
|
||||
eMovementPlatformState state;
|
||||
bitStream.Read(state);
|
||||
ASSERT_EQ(state, eMovementPlatformState::Stopped | eMovementPlatformState::ReachedDesiredWaypoint);
|
||||
|
||||
int32_t currentWaypointIndex;
|
||||
bitStream.Read(currentWaypointIndex);
|
||||
ASSERT_EQ(currentWaypointIndex, 0);
|
||||
|
||||
int32_t currentWaypointIndex3;
|
||||
bitStream.Read(currentWaypointIndex3);
|
||||
ASSERT_EQ(currentWaypointIndex3, 28);
|
||||
bool isInReverse;
|
||||
bitStream.Read(isInReverse);
|
||||
ASSERT_FALSE(isInReverse);
|
||||
}
|
||||
|
||||
bool isInReverse4;
|
||||
bitStream.Read(isInReverse4);
|
||||
ASSERT_TRUE(isInReverse4);
|
||||
void DeserializeMovingPlatformSubComponent() {
|
||||
bool isDirty;
|
||||
ASSERT_TRUE(bitStream.Read(isDirty));
|
||||
ASSERT_TRUE(isDirty);
|
||||
|
||||
bool hasPlatformSubComponents2;
|
||||
bitStream.Read(hasPlatformSubComponents2);
|
||||
ASSERT_FALSE(hasPlatformSubComponents2);
|
||||
eMovementPlatformState state;
|
||||
ASSERT_TRUE(bitStream.Read(state));
|
||||
ASSERT_EQ(state, eMovementPlatformState::Stopped | eMovementPlatformState::ReachedDesiredWaypoint);
|
||||
|
||||
int32_t desiredWaypointIndex;
|
||||
ASSERT_TRUE(bitStream.Read(desiredWaypointIndex));
|
||||
ASSERT_EQ(desiredWaypointIndex, -1);
|
||||
|
||||
bool shouldStopAtDesiredWaypoint;
|
||||
ASSERT_TRUE(bitStream.Read(shouldStopAtDesiredWaypoint));
|
||||
ASSERT_FALSE(shouldStopAtDesiredWaypoint);
|
||||
|
||||
bool isInReverse2;
|
||||
ASSERT_TRUE(bitStream.Read(isInReverse2));
|
||||
ASSERT_FALSE(isInReverse2);
|
||||
|
||||
float percentBetweenPoints;
|
||||
ASSERT_TRUE(bitStream.Read(percentBetweenPoints));
|
||||
ASSERT_EQ(percentBetweenPoints, 0);
|
||||
|
||||
NiPoint3 position;
|
||||
ASSERT_TRUE(bitStream.Read(position.x));
|
||||
ASSERT_TRUE(bitStream.Read(position.y));
|
||||
ASSERT_TRUE(bitStream.Read(position.z));
|
||||
ASSERT_EQ(position, NiPoint3(25, 26, 27));
|
||||
|
||||
uint32_t currentWaypointIndex;
|
||||
ASSERT_TRUE(bitStream.Read(currentWaypointIndex));
|
||||
ASSERT_EQ(currentWaypointIndex, 0);
|
||||
|
||||
uint32_t nextWaypointIndex;
|
||||
ASSERT_TRUE(bitStream.Read(nextWaypointIndex));
|
||||
ASSERT_EQ(nextWaypointIndex, -1);
|
||||
|
||||
float idleTimeElapsed;
|
||||
ASSERT_TRUE(bitStream.Read(idleTimeElapsed));
|
||||
ASSERT_FLOAT_EQ(idleTimeElapsed, 0.0f);
|
||||
|
||||
float moveTimeElapsed;
|
||||
ASSERT_TRUE(bitStream.Read(moveTimeElapsed));
|
||||
ASSERT_FLOAT_EQ(moveTimeElapsed, 0.0f);
|
||||
}
|
||||
|
||||
void DeserializeMovingPlatformComponent() {
|
||||
// read in the full BitStream and check the values match what they were set to above
|
||||
bool hasPlatformSubComponents = false;
|
||||
ASSERT_TRUE(bitStream.Read(hasPlatformSubComponents));
|
||||
ASSERT_TRUE(hasPlatformSubComponents);
|
||||
|
||||
bool dirtyPathInfo;
|
||||
ASSERT_TRUE(bitStream.Read(dirtyPathInfo));
|
||||
ASSERT_TRUE(dirtyPathInfo);
|
||||
|
||||
bool hasPath;
|
||||
ASSERT_TRUE(bitStream.Read(hasPath));
|
||||
ASSERT_TRUE(hasPath);
|
||||
|
||||
std::u16string pathName;
|
||||
uint16_t pathNameLength;
|
||||
ASSERT_TRUE(bitStream.Read(pathNameLength));
|
||||
pathName.resize(pathNameLength);
|
||||
ASSERT_TRUE(bitStream.ReadBits(reinterpret_cast<unsigned char*>(pathName.data()), BYTES_TO_BITS(pathNameLength) * 2));
|
||||
ASSERT_EQ(pathName, u"ExamplePath");
|
||||
|
||||
uint32_t pathStartIndex;
|
||||
ASSERT_TRUE(bitStream.Read(pathStartIndex));
|
||||
ASSERT_EQ(pathStartIndex, 0);
|
||||
|
||||
bool isInReverse;
|
||||
ASSERT_TRUE(bitStream.Read(isInReverse));
|
||||
ASSERT_FALSE(isInReverse);
|
||||
|
||||
bool hasPlatformData;
|
||||
ASSERT_TRUE(bitStream.Read(hasPlatformData));
|
||||
ASSERT_TRUE(hasPlatformData);
|
||||
|
||||
eMoverSubComponentType platformType;
|
||||
ASSERT_TRUE(bitStream.Read(platformType));
|
||||
ASSERT_EQ(platformType, eMoverSubComponentType::Mover);
|
||||
DeserializeMovingPlatformSubComponent();
|
||||
|
||||
ASSERT_TRUE(bitStream.Read(hasPlatformData));
|
||||
ASSERT_TRUE(hasPlatformData);
|
||||
|
||||
ASSERT_TRUE(bitStream.Read(platformType));
|
||||
ASSERT_EQ(platformType, eMoverSubComponentType::SimpleMover);
|
||||
DeserializeSimpleMoverPlatformSubComponent();
|
||||
|
||||
ASSERT_TRUE(bitStream.Read(hasPlatformData));
|
||||
ASSERT_TRUE(hasPlatformData);
|
||||
|
||||
ASSERT_TRUE(bitStream.Read(platformType));
|
||||
ASSERT_EQ(platformType, eMoverSubComponentType::Rotator);
|
||||
DeserializeMovingPlatformSubComponent();
|
||||
|
||||
ASSERT_TRUE(bitStream.Read(hasPlatformData));
|
||||
ASSERT_FALSE(hasPlatformData);
|
||||
}
|
||||
|
||||
void TestSerialization() {
|
||||
auto* movingPlatformComponent = baseEntity->GetComponent<MovingPlatformComponent>();
|
||||
ASSERT_NE(movingPlatformComponent, nullptr);
|
||||
uint32_t flags = 0;
|
||||
movingPlatformComponent->Serialize(&bitStream, true, flags);
|
||||
DeserializeMovingPlatformComponent();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -302,89 +230,70 @@ TEST_F(MovingPlatformComponentTests, MovingPlatformSerializationTest) {
|
||||
}
|
||||
|
||||
TEST_F(MovingPlatformComponentTests, MovingPlatformSubComponentPathAdvanceForwardTest) {
|
||||
MoverPlatformSubComponent moverPlatformSubComponent(nullptr);
|
||||
moverPlatformSubComponent._SetPath(&path);
|
||||
moverPlatformSubComponent.m_CurrentWaypointIndex = 0;
|
||||
moverPlatformSubComponent.m_NextWaypointIndex = 1;
|
||||
moverPlatformSubComponent.m_InReverse = false;
|
||||
MoverPlatformSubComponent moverPlatformSubComponent(baseEntity->GetComponent<MovingPlatformComponent>());
|
||||
moverPlatformSubComponent.AdvanceToNextWaypoint();
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 1);
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 2);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypointIndex(), 1);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypointIndex(), 2);
|
||||
moverPlatformSubComponent.AdvanceToNextWaypoint();
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 2);
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 2);
|
||||
ASSERT_FALSE(moverPlatformSubComponent.m_InReverse);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypointIndex(), 2);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypointIndex(), 2);
|
||||
ASSERT_FALSE(moverPlatformSubComponent.GetInReverse());
|
||||
path.pathBehavior = PathBehavior::Bounce;
|
||||
moverPlatformSubComponent.AdvanceToNextWaypoint();
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 2);
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 1);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.m_InReverse);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypointIndex(), 2);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypointIndex(), 1);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.GetInReverse());
|
||||
}
|
||||
|
||||
TEST_F(MovingPlatformComponentTests, MovingPlatformSubComponentPathAdvanceReverseTest) {
|
||||
MoverPlatformSubComponent moverPlatformSubComponent(nullptr);
|
||||
moverPlatformSubComponent._SetPath(&path);
|
||||
moverPlatformSubComponent.m_CurrentWaypointIndex = 2;
|
||||
moverPlatformSubComponent.m_NextWaypointIndex = 1;
|
||||
moverPlatformSubComponent.m_InReverse = true;
|
||||
MoverPlatformSubComponent moverPlatformSubComponent(baseEntity->GetComponent<MovingPlatformComponent>());
|
||||
moverPlatformSubComponent.AdvanceToNextReverseWaypoint();
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 1);
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 0);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.m_InReverse);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypointIndex(), 1);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypointIndex(), 0);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.GetInReverse());
|
||||
moverPlatformSubComponent.AdvanceToNextReverseWaypoint();
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 0);
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 0);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.m_InReverse);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypointIndex(), 0);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypointIndex(), 0);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.GetInReverse());
|
||||
path.pathBehavior = PathBehavior::Bounce;
|
||||
moverPlatformSubComponent.AdvanceToNextWaypoint();
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 0);
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 1);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.m_InReverse);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypointIndex(), 0);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypointIndex(), 1);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.GetInReverse());
|
||||
}
|
||||
|
||||
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 moverPlatformSubComponent(baseEntity->GetComponent<MovingPlatformComponent>());
|
||||
moverPlatformSubComponent.AdvanceToNextWaypoint();
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 1);
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 2);
|
||||
ASSERT_FALSE(moverPlatformSubComponent.m_InReverse);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypointIndex(), 1);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypointIndex(), 2);
|
||||
ASSERT_FALSE(moverPlatformSubComponent.GetInReverse());
|
||||
moverPlatformSubComponent.AdvanceToNextWaypoint();
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 2);
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 1);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.m_InReverse);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypointIndex(), 2);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypointIndex(), 1);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.GetInReverse());
|
||||
moverPlatformSubComponent.AdvanceToNextReverseWaypoint();
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 1);
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 0);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.m_InReverse);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypointIndex(), 1);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypointIndex(), 0);
|
||||
ASSERT_TRUE(moverPlatformSubComponent.GetInReverse());
|
||||
moverPlatformSubComponent.AdvanceToNextReverseWaypoint();
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 0);
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 1);
|
||||
ASSERT_FALSE(moverPlatformSubComponent.m_InReverse);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypointIndex(), 0);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypointIndex(), 1);
|
||||
ASSERT_FALSE(moverPlatformSubComponent.GetInReverse());
|
||||
moverPlatformSubComponent.AdvanceToNextWaypoint();
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_CurrentWaypointIndex, 1);
|
||||
ASSERT_EQ(moverPlatformSubComponent.m_NextWaypointIndex, 2);
|
||||
ASSERT_FALSE(moverPlatformSubComponent.m_InReverse);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypointIndex(), 1);
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypointIndex(), 2);
|
||||
ASSERT_FALSE(moverPlatformSubComponent.GetInReverse());
|
||||
}
|
||||
|
||||
TEST_F(MovingPlatformComponentTests, MovingPlatformMoverSpeedCalculationTest) {
|
||||
MoverPlatformSubComponent moverPlatformSubComponent(nullptr);
|
||||
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);
|
||||
path.pathWaypoints.at(1).movingPlatform.speed = 16.0f;
|
||||
path.pathBehavior = PathBehavior::Bounce;
|
||||
moverPlatformSubComponent._SetPath(&path);
|
||||
moverPlatformSubComponent.m_Speed = 16.0f;
|
||||
moverPlatformSubComponent.m_TimeBasedMovement = false;
|
||||
moverPlatformSubComponent.m_InReverse = false;
|
||||
moverPlatformSubComponent.m_CurrentWaypointIndex = 0;
|
||||
moverPlatformSubComponent.m_NextWaypointIndex = 1;
|
||||
ASSERT_EQ(moverPlatformSubComponent.CalculateSpeed(), 16.0f);
|
||||
NiPoint3 r = moverPlatformSubComponent.CalculateLinearVelocity();
|
||||
ASSERT_FLOAT_EQ(r.x, 15.988346099854);
|
||||
@@ -394,10 +303,7 @@ TEST_F(MovingPlatformComponentTests, MovingPlatformMoverSpeedCalculationTest) {
|
||||
}
|
||||
|
||||
TEST_F(MovingPlatformComponentTests, MovingPlatformNextAndCurrentWaypointAccess) {
|
||||
MoverPlatformSubComponent moverPlatformSubComponent(nullptr);
|
||||
moverPlatformSubComponent._SetPath(&path);
|
||||
moverPlatformSubComponent.m_CurrentWaypointIndex = 0;
|
||||
moverPlatformSubComponent.m_NextWaypointIndex = 1;
|
||||
MoverPlatformSubComponent moverPlatformSubComponent(baseEntity->GetComponent<MovingPlatformComponent>());
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetCurrentWaypoint().position, NiPoint3(1, 2, 3));
|
||||
ASSERT_EQ(moverPlatformSubComponent.GetNextWaypoint().position, NiPoint3(4, 5, 6));
|
||||
moverPlatformSubComponent.AdvanceToNextWaypoint();
|
||||
@@ -406,23 +312,32 @@ TEST_F(MovingPlatformComponentTests, MovingPlatformNextAndCurrentWaypointAccess)
|
||||
}
|
||||
|
||||
TEST_F(MovingPlatformComponentTests, MovingPlatformRunTest) {
|
||||
MoverPlatformSubComponent moverPlatformSubComponent(nullptr);
|
||||
moverPlatformSubComponent._SetPath(&path);
|
||||
MoverPlatformSubComponent moverPlatformSubComponent(baseEntity->GetComponent<MovingPlatformComponent>());
|
||||
path.pathWaypoints.at(0).position = NiPoint3(99.296440f, 419.293335f, 207.219498f);
|
||||
path.pathWaypoints.at(0).movingPlatform.speed = 16.0f;
|
||||
|
||||
path.pathWaypoints.at(1).position = NiPoint3(141.680099f, 419.990051f, 208.680450f);
|
||||
path.pathWaypoints.at(1).movingPlatform.speed = 16.0f;
|
||||
moverPlatformSubComponent.m_State = 0;
|
||||
moverPlatformSubComponent.m_TimeBasedMovement = false;
|
||||
moverPlatformSubComponent.m_State = eMovementPlatformState::Travelling;
|
||||
moverPlatformSubComponent.m_CurrentWaypointIndex = 0;
|
||||
moverPlatformSubComponent.m_NextWaypointIndex = 1;
|
||||
moverPlatformSubComponent.m_Speed = 16.0f;
|
||||
moverPlatformSubComponent.m_Position = path.pathWaypoints.at(0).position;
|
||||
|
||||
moverPlatformSubComponent.UpdateLinearVelocity();
|
||||
moverPlatformSubComponent.Update(2.65f);
|
||||
|
||||
// just check that its close enough
|
||||
EXPECT_LT(141.680099f - moverPlatformSubComponent.m_Position.x, 0.1f);
|
||||
EXPECT_LT(419.990051f - moverPlatformSubComponent.m_Position.y, 0.1f);
|
||||
EXPECT_LT(208.680450f - moverPlatformSubComponent.m_Position.z, 0.1f);
|
||||
EXPECT_LT(141.680099f - moverPlatformSubComponent.GetPosition().x, 0.1f);
|
||||
EXPECT_LT(419.990051f - moverPlatformSubComponent.GetPosition().y, 0.1f);
|
||||
EXPECT_LT(208.680450f - moverPlatformSubComponent.GetPosition().z, 0.1f);
|
||||
}
|
||||
|
||||
TEST_F(MovingPlatformComponentTests, MovingPlatformPercentBetweenPointsTest) {
|
||||
MoverPlatformSubComponent moverPlatformSubComponent(baseEntity->GetComponent<MovingPlatformComponent>());
|
||||
path.pathWaypoints.at(0).position = NiPoint3(0, 0, 1);
|
||||
path.pathWaypoints.at(1).position = NiPoint3(0, 0, 3);
|
||||
// moverPlatformSubComponent.m_Position = NiPoint3(0, 0, 1);
|
||||
ASSERT_FLOAT_EQ(moverPlatformSubComponent.CalculatePercentToNextWaypoint(), 0.0f);
|
||||
// moverPlatformSubComponent.m_Position = NiPoint3(0, 0, 2);
|
||||
ASSERT_FLOAT_EQ(moverPlatformSubComponent.CalculatePercentToNextWaypoint(), 0.5f);
|
||||
// moverPlatformSubComponent.m_Position = NiPoint3(0, 0, 3);
|
||||
ASSERT_FLOAT_EQ(moverPlatformSubComponent.CalculatePercentToNextWaypoint(), 1.0f);
|
||||
// moverPlatformSubComponent.m_TimeBasedMovement = true;
|
||||
ASSERT_FLOAT_EQ(moverPlatformSubComponent.CalculatePercentToNextWaypoint(), 0.0f);
|
||||
}
|
||||
|
Reference in New Issue
Block a user