mirror of
				https://github.com/DarkflameUniverse/DarkflameServer.git
				synced 2025-10-31 04:32:06 +00:00 
			
		
		
		
	refactor to class style and not c style
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| #include "CDMovingPlatformComponentTable.h" | ||||
|  | ||||
| CDMovingPlatformComponentTable::CDMovingPlatformComponentTable() { | ||||
| 	auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MovementAIComponent"); | ||||
| 	auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MovingPlatforms"); | ||||
| 	while (!tableData.eof()) { | ||||
| 		CDMovingPlatformTableEntry entry; | ||||
| 		entry.platformIsSimpleMover = tableData.getIntField("platformIsSimpleMover", 0) == 1; | ||||
| @@ -17,7 +17,7 @@ CDMovingPlatformComponentTable::CDMovingPlatformComponentTable() { | ||||
| } | ||||
|  | ||||
| void CDMovingPlatformComponentTable::CachePlatformEntry(ComponentID id) { | ||||
| 	auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM MovementAIComponent WHERE id = ?;"); | ||||
| 	auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM MovingPlatforms WHERE id = ?;"); | ||||
| 	query.bind(1, static_cast<int32_t>(id)); | ||||
|  | ||||
| 	auto tableData = query.execQuery(); | ||||
|   | ||||
| @@ -313,7 +313,7 @@ Entity* EntityManager::GetSpawnPointEntity(const std::string& spawnName) const { | ||||
| 	// Check if the spawn point entity is valid just in case | ||||
| 	return GetEntity(spawnPoint->second); | ||||
| } | ||||
|  | ||||
| #include <thread> | ||||
| const std::unordered_map<std::string, LWOOBJID>& EntityManager::GetSpawnPointEntities() const { | ||||
| 	return m_SpawnPoints; | ||||
| } | ||||
|   | ||||
| @@ -19,24 +19,31 @@ | ||||
|  //------------- PlatformSubComponent begin -------------- | ||||
|  | ||||
| PlatformSubComponent::PlatformSubComponent(MovingPlatformComponent* parentComponent) { | ||||
| 	m_Position = NiPoint3::ZERO; | ||||
| 	DluAssert(parentComponent != nullptr); | ||||
| 	m_ParentComponent = parentComponent; | ||||
| 	m_Position = parentComponent->GetParent()->GetPosition(); | ||||
| 	m_Rotation = parentComponent->GetParent()->GetRotation(); | ||||
|  | ||||
| 	m_State = eMovementPlatformState::Stopped | eMovementPlatformState::ReachedDesiredWaypoint; | ||||
| 	m_DesiredWaypointIndex = 0; | ||||
| 	m_DesiredWaypointIndex = -1; | ||||
| 	m_PercentUntilNextWaypoint = 0.0f; | ||||
| 	m_CurrentWaypointIndex = 0; | ||||
| 	m_NextWaypointIndex = -1; | ||||
| 	m_IdleTimeElapsed = 0.0f; | ||||
| 	m_Speed = 0.0f; | ||||
| 	m_WaitTime = 0.0f; | ||||
| 	m_MoveTimeElapsed = 0.0f; | ||||
| 	m_IsDirty = false; | ||||
| 	m_InReverse = false; | ||||
| 	m_ShouldStopAtDesiredWaypoint = false; | ||||
|  | ||||
| 	m_PercentUntilNextWaypoint = 0.0f; | ||||
|  | ||||
| 	m_CurrentWaypointIndex = 0; | ||||
| 	m_NextWaypointIndex = 0; | ||||
|  | ||||
| 	m_IdleTimeElapsed = 0.0f; | ||||
| 	m_LinearVelocity = NiPoint3::ZERO; | ||||
| 	m_AngularVelocity = NiPoint3::ZERO; | ||||
| 	m_TimeBasedMovement = false; | ||||
| 	m_Path = nullptr;  | ||||
| } | ||||
|  | ||||
| void PlatformSubComponent::Update(float deltaTime) { | ||||
| 	if (m_State == 0) return; | ||||
| 	if (m_State == 0 || !m_Path) return; | ||||
| 	if (m_State & eMovementPlatformState::Travelling) { | ||||
| 		m_MoveTimeElapsed += deltaTime; | ||||
|  | ||||
| @@ -44,13 +51,34 @@ void PlatformSubComponent::Update(float deltaTime) { | ||||
| 		// Unfortunately for the poor client, they chose to, instead of change the speed once at the start of the waypoint, | ||||
| 		// the speed is changed over the course of the waypoint. This means we have to recalculate the linear velocity every frame. | ||||
| 		// yay. | ||||
| 		if (GetCurrentWaypoint().movingPlatform.speed != GetNextWaypoint().movingPlatform.speed) { | ||||
| 		if (m_Speed == 0.0f || (GetCurrentWaypoint().movingPlatform.speed != GetNextWaypoint().movingPlatform.speed)) { | ||||
| 			UpdateLinearVelocity(); | ||||
| 			m_IsDirty = true; | ||||
| 		} | ||||
| 		m_Position += m_LinearVelocity * deltaTime; | ||||
| 		if (CalculatePercentToNextWaypoint() > 0.99) { | ||||
| 			m_MoveTimeElapsed = 0; | ||||
| 			m_ParentComponent->GetParent()->SetPosition(m_Position); | ||||
| 			m_InReverse ? AdvanceToNextReverseWaypoint() : AdvanceToNextWaypoint(); | ||||
| 			m_IsDirty = true; | ||||
| 			Game::entityManager->SerializeEntity(m_ParentComponent->GetParent()); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| float PlatformSubComponent::CalculatePercentToNextWaypoint() { | ||||
| 	if (m_TimeBasedMovement) return 0; | ||||
| 	float distanceToNextWaypoint = (GetNextWaypoint().position - GetCurrentWaypoint().position).Length(); | ||||
| 	if (distanceToNextWaypoint == 0.0f) return 0; | ||||
| 	float distanceToCurrentWaypoint = (m_Position - GetCurrentWaypoint().position).Length(); | ||||
| 	return distanceToCurrentWaypoint / distanceToNextWaypoint; | ||||
| } | ||||
|  | ||||
| void PlatformSubComponent::UpdateAngularVelocity() { | ||||
| 	// Update the angular velocity | ||||
| 	// This one is sure to be fun... | ||||
| } | ||||
|  | ||||
| void PlatformSubComponent::UpdateLinearVelocity() { | ||||
| 	m_LinearVelocity = CalculateLinearVelocity(); | ||||
| } | ||||
| @@ -58,6 +86,8 @@ void PlatformSubComponent::UpdateLinearVelocity() { | ||||
| void PlatformSubComponent::AdvanceToNextWaypoint() { | ||||
| 	uint32_t numWaypoints = m_Path->pathWaypoints.size(); | ||||
| 	m_CurrentWaypointIndex = m_NextWaypointIndex; | ||||
| 	m_ParentComponent->GetParent()->SetPosition(GetCurrentWaypoint().position); | ||||
| 	m_ParentComponent->GetParent()->SetRotation(GetCurrentWaypoint().rotation); | ||||
| 	uint32_t nextWaypointIndex = m_CurrentWaypointIndex + 1; | ||||
| 	if (numWaypoints <= nextWaypointIndex) { | ||||
| 		PathBehavior behavior = m_Path->pathBehavior; | ||||
| @@ -71,11 +101,16 @@ void PlatformSubComponent::AdvanceToNextWaypoint() { | ||||
| 		} | ||||
| 	} | ||||
| 	m_NextWaypointIndex = nextWaypointIndex; | ||||
| 	m_DesiredWaypointIndex = nextWaypointIndex; | ||||
| 	UpdateLinearVelocity(); | ||||
| 	UpdateAngularVelocity(); | ||||
| 	m_IsDirty = true; | ||||
| } | ||||
|  | ||||
| void PlatformSubComponent::AdvanceToNextReverseWaypoint() { | ||||
| 	uint32_t numWaypoints = m_Path->pathWaypoints.size(); | ||||
| 	m_ParentComponent->GetParent()->SetPosition(GetCurrentWaypoint().position); | ||||
| 	m_ParentComponent->GetParent()->SetRotation(GetCurrentWaypoint().rotation); | ||||
| 	m_CurrentWaypointIndex = m_NextWaypointIndex; | ||||
| 	int32_t nextWaypointIndex = m_CurrentWaypointIndex - 1; | ||||
| 	if (nextWaypointIndex < 0) { | ||||
| @@ -90,11 +125,15 @@ void PlatformSubComponent::AdvanceToNextReverseWaypoint() { | ||||
| 		} | ||||
| 	} | ||||
| 	m_NextWaypointIndex = nextWaypointIndex; | ||||
| 	m_DesiredWaypointIndex = nextWaypointIndex; | ||||
| 	UpdateLinearVelocity(); | ||||
| 	UpdateAngularVelocity(); | ||||
| 	m_IsDirty = true; | ||||
| } | ||||
|  | ||||
| void PlatformSubComponent::SetupPath(const std::string& pathName, uint32_t startingWaypointIndex, bool startsInReverse) { | ||||
| 	m_Path = Game::zoneManager->GetZone()->GetPath(pathName); | ||||
| 	Game::logger->Log("MovingPlatformComponent", "setting up path %s", pathName.c_str()); | ||||
| 	if (!m_Path) { | ||||
| 		Game::logger->Log("MovingPlatformComponent", "Failed to find path (%s)", pathName.c_str()); | ||||
| 		return; | ||||
| @@ -104,15 +143,13 @@ void PlatformSubComponent::SetupPath(const std::string& pathName, uint32_t start | ||||
| 	m_TimeBasedMovement = m_Path->movingPlatform.timeBasedMovement; | ||||
| } | ||||
|  | ||||
| const PathWaypoint PlatformSubComponent::GetNextWaypoint() const { | ||||
| const PathWaypoint& PlatformSubComponent::GetNextWaypoint() const { | ||||
| 	DluAssert(m_Path != nullptr); | ||||
| 	if (m_NextWaypointIndex >= m_Path->pathWaypoints.size()) return PathWaypoint(); | ||||
| 	return m_Path->pathWaypoints.at(m_NextWaypointIndex); | ||||
| } | ||||
|  | ||||
| const PathWaypoint PlatformSubComponent::GetCurrentWaypoint() const { | ||||
| const PathWaypoint& PlatformSubComponent::GetCurrentWaypoint() const { | ||||
| 	DluAssert(m_Path != nullptr); | ||||
| 	if (m_CurrentWaypointIndex >= m_Path->pathWaypoints.size()) return PathWaypoint(); | ||||
| 	return m_Path->pathWaypoints.at(m_CurrentWaypointIndex); | ||||
| } | ||||
|  | ||||
| @@ -146,6 +183,7 @@ void PlatformSubComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsIn | ||||
| 	outBitStream->Write(m_NextWaypointIndex); | ||||
| 	outBitStream->Write(m_IdleTimeElapsed); | ||||
| 	outBitStream->Write(m_MoveTimeElapsed); | ||||
|  | ||||
| 	if (!bIsInitialUpdate) m_IsDirty = false; | ||||
| } | ||||
|  | ||||
| @@ -153,6 +191,11 @@ void PlatformSubComponent::StartPathing() { | ||||
| 	m_State |= eMovementPlatformState::Travelling; | ||||
| 	m_State &= ~eMovementPlatformState::Stopped; | ||||
| 	m_State &= ~eMovementPlatformState::Waiting; | ||||
| 	m_IsDirty = true; | ||||
| 	m_CurrentWaypointIndex = m_ParentComponent->GetStartingWaypointIndex(); | ||||
| 	m_InReverse = m_ParentComponent->GetStartsIsInReverse(); | ||||
| 	m_NextWaypointIndex = m_InReverse ? m_CurrentWaypointIndex - 1 : m_CurrentWaypointIndex + 1; | ||||
| 	Game::entityManager->SerializeEntity(m_ParentComponent->GetParent()); | ||||
| } | ||||
|  | ||||
| void PlatformSubComponent::ResumePathing() { | ||||
| @@ -163,11 +206,14 @@ void PlatformSubComponent::ResumePathing() { | ||||
| 		m_State |= eMovementPlatformState::Waiting; | ||||
| 		m_State &= ~eMovementPlatformState::Stopped; | ||||
| 		m_State &= ~eMovementPlatformState::Travelling; | ||||
| 		m_IsDirty = true; | ||||
| 	} else { | ||||
| 		m_State &= eMovementPlatformState::Waiting; | ||||
| 		m_State &= eMovementPlatformState::Travelling; | ||||
| 		m_State &= eMovementPlatformState::Stopped; | ||||
| 		// Set the velocities | ||||
| 		m_IsDirty = true; | ||||
| 		UpdateLinearVelocity(); | ||||
| 		UpdateAngularVelocity(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -266,7 +312,7 @@ SimpleMoverPlatformSubComponent::SimpleMoverPlatformSubComponent(MovingPlatformC | ||||
| //------------- MovingPlatformComponent begin -------------- | ||||
|  | ||||
| MovingPlatformComponent::MovingPlatformComponent(Entity* parent, const std::string& pathName) : Component(parent) { | ||||
|  | ||||
| 	m_PathName = GeneralUtils::ASCIIToUTF16(pathName); | ||||
| } | ||||
|  | ||||
| void MovingPlatformComponent::LoadDataFromTemplate() { | ||||
| @@ -274,18 +320,23 @@ void MovingPlatformComponent::LoadDataFromTemplate() { | ||||
| } | ||||
|  | ||||
| void MovingPlatformComponent::LoadConfigData() { | ||||
| 	if (m_Parent->GetVar<bool>(u"platformIsSimpleMover")) { | ||||
| 		AddMovingPlatform<SimpleMoverPlatformSubComponent>(NiPoint3::ZERO, false); | ||||
| 	} | ||||
| 	if (m_Parent->GetVar<bool>(u"platformIsMover")) { | ||||
| 		AddMovingPlatform<MoverPlatformSubComponent>(); | ||||
| 	} | ||||
| 	if (m_Parent->GetVar<bool>(u"platformIsSimpleMover")) { | ||||
| 		AddMovingPlatform<SimpleMoverPlatformSubComponent>(NiPoint3::ZERO, false); | ||||
| 	} | ||||
| 	if (m_Parent->GetVar<bool>(u"platformIsRotater")) { | ||||
| 		AddMovingPlatform<RotatorPlatformSubComponent>(); | ||||
| 	} | ||||
| 	m_StartingWaypointIndex = m_Parent->GetVar<uint32_t>(u"attached_path_start"); | ||||
| 	m_StartsIsInReverse = false; | ||||
| 	m_DirtyPathInfo = true; | ||||
| 	m_StartOnload = m_Parent->GetVar<bool>(u"startPathingOnLoad"); | ||||
| } | ||||
|  | ||||
| void MovingPlatformComponent::Update(float deltaTime) { | ||||
| 	std::for_each(m_Platforms.begin(), m_Platforms.end(), [deltaTime](const std::unique_ptr<PlatformSubComponent>& platform) { platform->Update(deltaTime); }); | ||||
| } | ||||
|  | ||||
| void MovingPlatformComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { | ||||
| @@ -326,227 +377,39 @@ void MovingPlatformComponent::OnCompleteRebuild() { | ||||
| } | ||||
|  | ||||
| void MovingPlatformComponent::SetMovementState(eMovementPlatformState value) { | ||||
| 	// auto* subComponent = static_cast<MoverSubComponent*>(m_MoverSubComponent); | ||||
|  | ||||
| 	// subComponent->mState = value; | ||||
|  | ||||
| 	// Game::entityManager->SerializeEntity(m_Parent); | ||||
| } | ||||
|  | ||||
| void MovingPlatformComponent::GotoWaypoint(uint32_t index, bool stopAtWaypoint) { | ||||
| 	// auto* subComponent = static_cast<MoverSubComponent*>(m_MoverSubComponent); | ||||
|  | ||||
| 	// subComponent->mDesiredWaypointIndex = index; | ||||
| 	// subComponent->mNextWaypointIndex = index; | ||||
| 	// subComponent->mShouldStopAtDesiredWaypoint = stopAtWaypoint; | ||||
|  | ||||
| 	// StartPathing(); | ||||
| } | ||||
|  | ||||
| void MovingPlatformComponent::StartPathing() { | ||||
| 	std::for_each(m_Platforms.begin(), m_Platforms.end(), [](const std::unique_ptr<PlatformSubComponent>& platform) { | ||||
| 		platform->StartPathing(); | ||||
| 		}); | ||||
| 	// state == Travelling | ||||
| 	// //GameMessages::SendStartPathing(m_Parent); | ||||
| 	// m_PathingStopped = false; | ||||
|  | ||||
| 	// auto* subComponent = static_cast<MoverSubComponent*>(m_MoverSubComponent); | ||||
|  | ||||
| 	// subComponent->mShouldStopAtDesiredWaypoint = true; | ||||
| 	// subComponent->mState = eMovementPlatformState::Stationary; | ||||
|  | ||||
| 	// NiPoint3 targetPosition; | ||||
|  | ||||
| 	// if (m_Path != nullptr) { | ||||
| 	// 	const auto& currentWaypoint = m_Path->pathWaypoints[subComponent->mCurrentWaypointIndex]; | ||||
| 	// 	const auto& nextWaypoint = m_Path->pathWaypoints[subComponent->mNextWaypointIndex]; | ||||
|  | ||||
| 	// 	subComponent->mPosition = currentWaypoint.position; | ||||
| 	// 	subComponent->mSpeed = currentWaypoint.movingPlatform.speed; | ||||
| 	// 	subComponent->mWaitTime = currentWaypoint.movingPlatform.wait; | ||||
|  | ||||
| 	// 	targetPosition = nextWaypoint.position; | ||||
| 	// } else { | ||||
| 	// 	subComponent->mPosition = m_Parent->GetPosition(); | ||||
| 	// 	subComponent->mSpeed = 1.0f; | ||||
| 	// 	subComponent->mWaitTime = 2.0f; | ||||
|  | ||||
| 	// 	targetPosition = m_Parent->GetPosition() + NiPoint3(0.0f, 10.0f, 0.0f); | ||||
| 	// } | ||||
|  | ||||
| 	// m_Parent->AddCallbackTimer(subComponent->mWaitTime, [this] { | ||||
| 	// 	SetMovementState(eMovementPlatformState::Moving); | ||||
| 	// 	}); | ||||
|  | ||||
| 	// const auto travelTime = Vector3::Distance(targetPosition, subComponent->mPosition) / subComponent->mSpeed + 1.5f; | ||||
|  | ||||
| 	// const auto travelNext = subComponent->mWaitTime + travelTime; | ||||
|  | ||||
| 	// m_Parent->AddCallbackTimer(travelTime, [subComponent, this] { | ||||
| 	// 	for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) { | ||||
| 	// 		script->OnWaypointReached(m_Parent, subComponent->mNextWaypointIndex); | ||||
| 	// 	} | ||||
| 	// 	}); | ||||
|  | ||||
| 	// m_Parent->AddCallbackTimer(travelNext, [this] { | ||||
| 	// 	ContinuePathing(); | ||||
| 	// 	}); | ||||
|  | ||||
| 	// //GameMessages::SendPlatformResync(m_Parent, UNASSIGNED_SYSTEM_ADDRESS); | ||||
|  | ||||
| 	// Game::entityManager->SerializeEntity(m_Parent); | ||||
| } | ||||
|  | ||||
| void MovingPlatformComponent::ContinuePathing() { | ||||
| 	// state == Travelling | ||||
| 	// auto* subComponent = static_cast<MoverSubComponent*>(m_MoverSubComponent); | ||||
|  | ||||
| 	// subComponent->mState = eMovementPlatformState::Stationary; | ||||
|  | ||||
| 	// subComponent->mCurrentWaypointIndex = subComponent->mNextWaypointIndex; | ||||
|  | ||||
| 	// NiPoint3 targetPosition; | ||||
| 	// uint32_t pathSize; | ||||
| 	// PathBehavior behavior; | ||||
|  | ||||
| 	// if (m_Path != nullptr) { | ||||
| 	// 	const auto& currentWaypoint = m_Path->pathWaypoints[subComponent->mCurrentWaypointIndex]; | ||||
| 	// 	const auto& nextWaypoint = m_Path->pathWaypoints[subComponent->mNextWaypointIndex]; | ||||
|  | ||||
| 	// 	subComponent->mPosition = currentWaypoint.position; | ||||
| 	// 	subComponent->mSpeed = currentWaypoint.movingPlatform.speed; | ||||
| 	// 	subComponent->mWaitTime = currentWaypoint.movingPlatform.wait; // + 2; | ||||
|  | ||||
| 	// 	pathSize = m_Path->pathWaypoints.size() - 1; | ||||
|  | ||||
| 	// 	behavior = static_cast<PathBehavior>(m_Path->pathBehavior); | ||||
|  | ||||
| 	// 	targetPosition = nextWaypoint.position; | ||||
| 	// } else { | ||||
| 	// 	subComponent->mPosition = m_Parent->GetPosition(); | ||||
| 	// 	subComponent->mSpeed = 1.0f; | ||||
| 	// 	subComponent->mWaitTime = 2.0f; | ||||
|  | ||||
| 	// 	targetPosition = m_Parent->GetPosition() + NiPoint3(0.0f, 10.0f, 0.0f); | ||||
|  | ||||
| 	// 	pathSize = 1; | ||||
| 	// 	behavior = PathBehavior::Loop; | ||||
| 	// } | ||||
|  | ||||
| 	// if (m_Parent->GetLOT() == 9483) { | ||||
| 	// 	behavior = PathBehavior::Bounce; | ||||
| 	// } else { | ||||
| 	// 	return; | ||||
| 	// } | ||||
|  | ||||
| 	// if (subComponent->mCurrentWaypointIndex >= pathSize) { | ||||
| 	// 	subComponent->mCurrentWaypointIndex = pathSize; | ||||
| 	// 	switch (behavior) { | ||||
| 	// 	case PathBehavior::Once: | ||||
| 	// 		Game::entityManager->SerializeEntity(m_Parent); | ||||
| 	// 		return; | ||||
|  | ||||
| 	// 	case PathBehavior::Bounce: | ||||
| 	// 		subComponent->mInReverse = true; | ||||
| 	// 		break; | ||||
|  | ||||
| 	// 	case PathBehavior::Loop: | ||||
| 	// 		subComponent->mNextWaypointIndex = 0; | ||||
| 	// 		break; | ||||
|  | ||||
| 	// 	default: | ||||
| 	// 		break; | ||||
| 	// 	} | ||||
| 	// } else if (subComponent->mCurrentWaypointIndex == 0) { | ||||
| 	// 	subComponent->mInReverse = false; | ||||
| 	// } | ||||
|  | ||||
| 	// if (subComponent->mInReverse) { | ||||
| 	// 	subComponent->mNextWaypointIndex = subComponent->mCurrentWaypointIndex - 1; | ||||
| 	// } else { | ||||
| 	// 	subComponent->mNextWaypointIndex = subComponent->mCurrentWaypointIndex + 1; | ||||
| 	// } | ||||
|  | ||||
| 	// /* | ||||
| 	// subComponent->mNextWaypointIndex = 0; | ||||
| 	// subComponent->mCurrentWaypointIndex = 1; | ||||
| 	// */ | ||||
|  | ||||
| 	// //GameMessages::SendPlatformResync(m_Parent, UNASSIGNED_SYSTEM_ADDRESS); | ||||
|  | ||||
| 	// if (subComponent->mCurrentWaypointIndex == subComponent->mDesiredWaypointIndex) { | ||||
| 	// 	// TODO: Send event? | ||||
| 	// 	StopPathing(); | ||||
|  | ||||
| 	// 	return; | ||||
| 	// } | ||||
|  | ||||
| 	// m_Parent->CancelCallbackTimers(); | ||||
|  | ||||
| 	// m_Parent->AddCallbackTimer(subComponent->mWaitTime, [this] { | ||||
| 	// 	SetMovementState(eMovementPlatformState::Moving); | ||||
| 	// 	}); | ||||
|  | ||||
| 	// auto travelTime = Vector3::Distance(targetPosition, subComponent->mPosition) / subComponent->mSpeed + 1.5; | ||||
|  | ||||
| 	// if (m_Parent->GetLOT() == 9483) { | ||||
| 	// 	travelTime += 20; | ||||
| 	// } | ||||
|  | ||||
| 	// const auto travelNext = subComponent->mWaitTime + travelTime; | ||||
|  | ||||
| 	// m_Parent->AddCallbackTimer(travelTime, [subComponent, this] { | ||||
| 	// 	for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) { | ||||
| 	// 		script->OnWaypointReached(m_Parent, subComponent->mNextWaypointIndex); | ||||
| 	// 	} | ||||
| 	// 	}); | ||||
|  | ||||
| 	// m_Parent->AddCallbackTimer(travelNext, [this] { | ||||
| 	// 	ContinuePathing(); | ||||
| 	// 	}); | ||||
|  | ||||
| 	// Game::entityManager->SerializeEntity(m_Parent); | ||||
| } | ||||
|  | ||||
| void MovingPlatformComponent::StopPathing() { | ||||
| 	// state == Stopped | ||||
| 	//m_Parent->CancelCallbackTimers(); | ||||
|  | ||||
| 	// auto* subComponent = static_cast<MoverSubComponent*>(m_MoverSubComponent); | ||||
|  | ||||
| 	// m_PathingStopped = true; | ||||
|  | ||||
| 	// subComponent->mState = eMovementPlatformState::Stopped; | ||||
| 	// subComponent->mDesiredWaypointIndex = -1; | ||||
| 	// subComponent->mShouldStopAtDesiredWaypoint = false; | ||||
|  | ||||
| 	// Game::entityManager->SerializeEntity(m_Parent); | ||||
|  | ||||
| 	//GameMessages::SendPlatformResync(m_Parent, UNASSIGNED_SYSTEM_ADDRESS); | ||||
| } | ||||
|  | ||||
| bool MovingPlatformComponent::GetNoAutoStart() const { | ||||
| 	return false; | ||||
| 	// return m_NoAutoStart; | ||||
| } | ||||
|  | ||||
| void MovingPlatformComponent::SetNoAutoStart(const bool value) { | ||||
| 	// m_NoAutoStart = value; | ||||
|  | ||||
| } | ||||
|  | ||||
| void MovingPlatformComponent::WarpToWaypoint(size_t index) { | ||||
| 	// const auto& waypoint = m_Path->pathWaypoints[index]; | ||||
|  | ||||
| 	// m_Parent->SetPosition(waypoint.position); | ||||
| 	// m_Parent->SetRotation(waypoint.rotation); | ||||
|  | ||||
| 	// Game::entityManager->SerializeEntity(m_Parent); | ||||
| } | ||||
|  | ||||
| size_t MovingPlatformComponent::GetLastWaypointIndex() const { | ||||
| 	return 0; | ||||
| 	// return m_Path->pathWaypoints.size() - 1; | ||||
| } | ||||
|  | ||||
| //------------- MovingPlatformComponent end -------------- | ||||
|   | ||||
| @@ -42,6 +42,8 @@ enum class eMoverSubComponentType : uint32_t { | ||||
|  | ||||
| class MovingPlatformComponent; | ||||
|  | ||||
| // In the context of a platform that is TimeBasedMovement,  | ||||
| // the speed member from the Path is used as the time to go between waypoints. | ||||
| class PlatformSubComponent { | ||||
| public: | ||||
| 	PlatformSubComponent(MovingPlatformComponent* parentComponent); | ||||
| @@ -56,43 +58,61 @@ public: | ||||
| 	virtual void StopPathing(); | ||||
| 	virtual void Update(float deltaTime); | ||||
| 	float CalculateSpeed() const; | ||||
| 	const PathWaypoint GetNextWaypoint() const; | ||||
| 	const PathWaypoint GetCurrentWaypoint() const; | ||||
| 	const PathWaypoint& GetNextWaypoint() const; | ||||
| 	const PathWaypoint& GetCurrentWaypoint() const; | ||||
| 	void SetupPath(const std::string& pathName, uint32_t startingWaypointIndex, bool startsInReverse); | ||||
| 	void AdvanceToNextWaypoint(); | ||||
| 	void AdvanceToNextReverseWaypoint(); | ||||
| 	NiPoint3 CalculateLinearVelocity(); | ||||
| 	void UpdateLinearVelocity(); | ||||
| protected: | ||||
| 	void UpdateAngularVelocity(); | ||||
| 	float CalculatePercentToNextWaypoint(); | ||||
|  | ||||
| #ifdef _MOVING_PLATFORM_TEST | ||||
| public: | ||||
| 	void _SetPath(const Path* path) { | ||||
| 		m_Path = path; | ||||
| 	} | ||||
| #endif | ||||
| 	MovingPlatformComponent* m_ParentComponent = nullptr; | ||||
| 	// Write all the getters for the below members | ||||
| 	bool GetTimeBasedMovement() const { return m_TimeBasedMovement; } | ||||
| 	const Path* GetPath() const { return m_Path; } | ||||
| 	float GetSpeed() const { return m_Speed; } | ||||
| 	float GetWaitTime() const { return m_WaitTime; } | ||||
| 	float GetMoveTimeElapsed() const { return m_MoveTimeElapsed; } | ||||
| 	float GetPercentUntilNextWaypoint() const { return m_PercentUntilNextWaypoint; } | ||||
| 	int32_t GetCurrentWaypointIndex() const { return m_CurrentWaypointIndex; } | ||||
| 	int32_t GetNextWaypointIndex() const { return m_NextWaypointIndex; } | ||||
| 	bool GetInReverse() const { return m_InReverse; } | ||||
| 	bool GetShouldStopAtDesiredWaypoint() const { return m_ShouldStopAtDesiredWaypoint; } | ||||
| 	int32_t GetDesiredWaypointIndex() const { return m_DesiredWaypointIndex; } | ||||
| 	uint32_t GetState() const { return m_State; } | ||||
| 	const NiPoint3& GetPosition() const { return m_Position; } | ||||
| 	const NiQuaternion& GetRotation() const { return m_Rotation; } | ||||
| 	const NiPoint3& GetLinearVelocity() const { return m_LinearVelocity; } | ||||
| 	const NiPoint3& GetAngularVelocity() const { return m_AngularVelocity; } | ||||
| 	const MovingPlatformComponent* GetParentComponent() const { return m_ParentComponent; } | ||||
| 	const float GetIdleTimeElapsed() const { return m_IdleTimeElapsed; } | ||||
|  | ||||
|  | ||||
| protected: | ||||
| 	MovingPlatformComponent* m_ParentComponent; | ||||
|  | ||||
| 	/** | ||||
| 	 * The state the platform is currently in | ||||
| 	 */ | ||||
| 	uint32_t m_State = eMovementPlatformState::Stopped | eMovementPlatformState::ReachedDesiredWaypoint; | ||||
| 	int32_t m_DesiredWaypointIndex = 0; | ||||
| 	float m_PercentUntilNextWaypoint = 0; | ||||
| 	uint32_t m_State; | ||||
| 	int32_t m_DesiredWaypointIndex; | ||||
| 	float m_PercentUntilNextWaypoint; | ||||
| 	NiPoint3 m_Position; | ||||
| 	int32_t m_CurrentWaypointIndex; | ||||
| 	int32_t m_NextWaypointIndex; | ||||
| 	float m_IdleTimeElapsed = 0; | ||||
| 	float m_Speed = 0; | ||||
| 	float m_WaitTime = 0; | ||||
| 	float m_MoveTimeElapsed = 0; | ||||
| 	bool m_IsDirty = false; | ||||
| 	bool m_InReverse = false; | ||||
| 	bool m_ShouldStopAtDesiredWaypoint = false; | ||||
| 	float m_IdleTimeElapsed; | ||||
| 	float m_Speed; | ||||
| 	float m_WaitTime; | ||||
| 	float m_MoveTimeElapsed; | ||||
| 	bool m_IsDirty; | ||||
| 	bool m_InReverse; | ||||
| 	bool m_ShouldStopAtDesiredWaypoint; | ||||
| 	NiPoint3 m_LinearVelocity; | ||||
| 	NiPoint3 m_AngularVelocity; | ||||
| 	bool m_TimeBasedMovement = false; | ||||
| 	const Path* m_Path = nullptr; | ||||
| 	bool m_TimeBasedMovement; | ||||
| 	const Path* m_Path; | ||||
| 	NiQuaternion m_Rotation; | ||||
| }; | ||||
|  | ||||
| class MoverPlatformSubComponent : public PlatformSubComponent { | ||||
| @@ -146,6 +166,7 @@ public: | ||||
|  | ||||
| 	void LoadDataFromTemplate(); | ||||
| 	void LoadConfigData(); | ||||
| 	void Update(float deltaTime) override; | ||||
|  | ||||
| 	void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); | ||||
|  | ||||
| @@ -228,23 +249,32 @@ public: | ||||
| 			} | ||||
| 	} | ||||
|  | ||||
| 	int32_t GetComponentId() const { return componentId; } | ||||
| 	bool HasPlatform() { return !m_Platforms.empty(); } | ||||
|  | ||||
| #ifdef _MOVING_PLATFORM_TEST | ||||
| 	/** | ||||
| 	 * Only used for testing. Do not call in production code. Let the constructor take care of this. | ||||
| 	 * | ||||
| 	 * @param platformSubComponent | ||||
| 	 */ | ||||
| 	void _AddPlatformSubComponent(std::unique_ptr<PlatformSubComponent> platformSubComponent) { | ||||
| 		m_Platforms.push_back(std::move(platformSubComponent)); | ||||
| 	const PlatformSubComponent& GetPlatform() const { | ||||
| 		return *m_Platforms.at(0); | ||||
| 	} | ||||
|  | ||||
| 	void _SetPath(const std::u16string& path) { | ||||
| 		m_PathName = path; | ||||
| 		m_DirtyPathInfo = true; | ||||
| } | ||||
| #endif | ||||
| 	int32_t GetComponentId() const { return componentId; } | ||||
| 	 | ||||
| 	// Make  | ||||
| 	const std::u16string& GetPathName() const { return m_PathName; } | ||||
| 	void SetPathName(const std::u16string& pathName) { m_PathName = pathName; } | ||||
|  | ||||
| 	bool GetPathingStopped() const { return m_PathingStopped; } | ||||
| 	void SetPathingStopped(bool value) { m_PathingStopped = value; } | ||||
|  | ||||
| 	uint32_t GetStartingWaypointIndex() const { return m_StartingWaypointIndex; } | ||||
| 	void SetStartingWaypointIndex(uint32_t value) { m_StartingWaypointIndex = value; } | ||||
|  | ||||
| 	bool GetStartsIsInReverse() const { return m_StartsIsInReverse; } | ||||
| 	void SetStartsIsInReverse(bool value) { m_StartsIsInReverse = value; } | ||||
|  | ||||
| 	bool GetStartOnload() const { return m_StartOnload; } | ||||
| 	void SetStartOnload(bool value) { m_StartOnload = value; } | ||||
|  | ||||
| 	bool GetDirtyPathInfo() const { return m_DirtyPathInfo; } | ||||
|  | ||||
| private: | ||||
| 	/** | ||||
| 	 * The name of the path this platform is currently on | ||||
| @@ -260,7 +290,7 @@ private: | ||||
|  | ||||
| 	bool m_StartsIsInReverse = false; | ||||
|  | ||||
| 	int32_t componentId = -1;; | ||||
| 	int32_t componentId = -1; | ||||
|  | ||||
| 	/** | ||||
| 	 * The mover sub component that belongs to this platform | ||||
| @@ -272,12 +302,8 @@ private: | ||||
| 	 */ | ||||
| 	bool m_NoAutoStart; | ||||
|  | ||||
| 	/** | ||||
| 	 * Whether to serialize the entity on the next update | ||||
| 	 */ | ||||
| 	bool m_Serialize = false; | ||||
|  | ||||
| 	bool m_DirtyPathInfo = false; | ||||
| 	bool m_StartOnload = false; | ||||
| }; | ||||
|  | ||||
| #endif // MOVINGPLATFORMCOMPONENT_H | ||||
|   | ||||
| @@ -357,48 +357,35 @@ void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAd | ||||
|  | ||||
| 	const auto lot = entity->GetLOT(); | ||||
|  | ||||
| 	if (lot == 12341 || lot == 5027 || lot == 5028 || lot == 14335 || lot == 14447 || lot == 14449) { | ||||
| 		iDesiredWaypointIndex = 0; | ||||
| 		iIndex = 0; | ||||
| 		nextIndex = 0; | ||||
| 		bStopAtDesiredWaypoint = true; | ||||
| 		movementState = static_cast<eMovementPlatformState>( | ||||
| 			eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint); | ||||
| 	} | ||||
|  | ||||
| 	bitStream.Write(entity->GetObjectID()); | ||||
| 	bitStream.Write((uint16_t)eGameMessageType::PLATFORM_RESYNC); | ||||
|  | ||||
| 	bool bReverse = false; | ||||
| 	int eCommand = 0; | ||||
| 	int eUnexpectedCommand = 0; | ||||
| 	float fIdleTimeElapsed = 0.0f; | ||||
| 	float fMoveTimeElapsed = 0.0f; | ||||
| 	float fPercentBetweenPoints = 0.0f; | ||||
| 	NiPoint3 ptUnexpectedLocation = NiPoint3::ZERO; | ||||
| 	NiQuaternion qUnexpectedRotation = NiQuaternion::IDENTITY; | ||||
| 	auto* movingPlatformComponent = entity->GetComponent<MovingPlatformComponent>(); | ||||
| 	if (!movingPlatformComponent) return; | ||||
| 	if (!movingPlatformComponent->HasPlatform()) return; | ||||
| 	auto& subComponent = movingPlatformComponent->GetPlatform(); | ||||
|  | ||||
| 	bitStream.Write(bReverse); | ||||
| 	bitStream.Write(bStopAtDesiredWaypoint); | ||||
| 	bitStream.Write(eCommand); | ||||
| 	bitStream.Write<int32_t>(static_cast<int32_t>(movementState)); | ||||
| 	bitStream.Write(eUnexpectedCommand); | ||||
| 	bitStream.Write(fIdleTimeElapsed); | ||||
| 	bitStream.Write(fMoveTimeElapsed); | ||||
| 	bitStream.Write(fPercentBetweenPoints); | ||||
| 	bitStream.Write(iDesiredWaypointIndex); | ||||
| 	bitStream.Write(iIndex); | ||||
| 	bitStream.Write(nextIndex); | ||||
| 	bitStream.Write(ptUnexpectedLocation.x); | ||||
| 	bitStream.Write(ptUnexpectedLocation.y); | ||||
| 	bitStream.Write(ptUnexpectedLocation.z); | ||||
| 	bitStream.Write(subComponent.GetInReverse()); | ||||
| 	bitStream.Write(subComponent.GetShouldStopAtDesiredWaypoint()); | ||||
| 	bitStream.Write<int32_t>(0); | ||||
| 	bitStream.Write(subComponent.GetState()); | ||||
| 	bitStream.Write<int32_t>(0); | ||||
| 	bitStream.Write(subComponent.GetIdleTimeElapsed()); | ||||
| 	bitStream.Write(subComponent.GetMoveTimeElapsed()); | ||||
| 	bitStream.Write(subComponent.GetPercentUntilNextWaypoint()); | ||||
| 	bitStream.Write(subComponent.GetDesiredWaypointIndex()); | ||||
| 	bitStream.Write(subComponent.GetCurrentWaypointIndex()); | ||||
| 	bitStream.Write(subComponent.GetNextWaypointIndex()); | ||||
| 	bitStream.Write(subComponent.GetPosition().x); | ||||
| 	bitStream.Write(subComponent.GetPosition().y); | ||||
| 	bitStream.Write(subComponent.GetPosition().z); | ||||
|  | ||||
| 	bitStream.Write(qUnexpectedRotation != NiQuaternion::IDENTITY); | ||||
| 	if (qUnexpectedRotation != NiQuaternion::IDENTITY) { | ||||
| 		bitStream.Write(qUnexpectedRotation.x); | ||||
| 		bitStream.Write(qUnexpectedRotation.y); | ||||
| 		bitStream.Write(qUnexpectedRotation.z); | ||||
| 		bitStream.Write(qUnexpectedRotation.w); | ||||
| 	bitStream.Write(subComponent.GetRotation() != NiQuaternion::IDENTITY); | ||||
| 	if (subComponent.GetRotation() != NiQuaternion::IDENTITY) { | ||||
| 		bitStream.Write(subComponent.GetRotation().x); | ||||
| 		bitStream.Write(subComponent.GetRotation().y); | ||||
| 		bitStream.Write(subComponent.GetRotation().z); | ||||
| 		bitStream.Write(subComponent.GetRotation().w); | ||||
| 	} | ||||
|  | ||||
| 	SEND_PACKET_BROADCAST; | ||||
| @@ -5006,7 +4993,6 @@ void GameMessages::HandleFireEventServerSide(RakNet::BitStream* inStream, Entity | ||||
| } | ||||
|  | ||||
| void GameMessages::HandleRequestPlatformResync(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) { | ||||
| 	if (entity->GetLOT() == 6267 || entity->GetLOT() == 16141) return; | ||||
| 	GameMessages::SendPlatformResync(entity, sysAddr, eMovementPlatformState::Travelling); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -5,6 +5,7 @@ | ||||
| #include "Character.h" | ||||
| #include "dZoneManager.h" | ||||
| #include "RenderComponent.h" | ||||
| #include "MovingPlatformComponent.h" | ||||
|  | ||||
| void CavePrisonCage::OnStartup(Entity* self) { | ||||
| 	const auto& myNum = self->GetVar<std::u16string>(u"myNumber"); | ||||
| @@ -83,8 +84,8 @@ void CavePrisonCage::SpawnCounterweight(Entity* self, Spawner* spawner) { | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			// Move the counterweight down 2 units | ||||
| 			counterweight->SetPosition(counterweight->GetPosition() + NiPoint3(0, -2, 0)); | ||||
| 			auto* mpc = counterweight->GetComponent<MovingPlatformComponent>(); | ||||
| 			if (mpc) mpc->StartPathing(); | ||||
|  | ||||
| 			// Serialize the counterweight | ||||
| 			Game::entityManager->SerializeEntity(counterweight); | ||||
|   | ||||
| @@ -203,6 +203,7 @@ public: | ||||
| 	const void PrintAllGameObjects(); | ||||
| 	LUTriggers::Trigger* GetTrigger(uint32_t sceneID, uint32_t triggerID); | ||||
| 	const Path* GetPath(std::string name) const; | ||||
| 	void AddPath(const Path& path) { m_Paths.push_back(path); }; | ||||
|  | ||||
| 	uint32_t GetWorldID() const { return m_WorldID; } | ||||
| 	[[nodiscard]] std::string GetZoneName() const { return m_ZoneName; } | ||||
|   | ||||
| @@ -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
	 David Markowitz
					David Markowitz