mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-16 12:28:08 +00:00
refactor to class style and not c style
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user