diff --git a/dCommon/dEnums/eMovementPlatformState.h b/dCommon/dEnums/eMovementPlatformState.h deleted file mode 100644 index f4e83938..00000000 --- a/dCommon/dEnums/eMovementPlatformState.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __EMOVEMENTPLATFORMSTATE__H__ -#define __EMOVEMENTPLATFORMSTATE__H__ - -#include - -/** - * The different types of platform movement state - */ -enum class eMovementPlatformState : uint32_t -{ - Waiting = 1 << 0U, - Travelling = 1 << 1U, - Stopped = 1 << 2U, - ReachedDesiredWaypoint = 1 << 3U, - ReachedFinalWaypoint = 1 << 4U, -}; - -inline constexpr eMovementPlatformState operator|(eMovementPlatformState a, eMovementPlatformState b) { - return static_cast( - static_cast::type>(a) | - static_cast::type>(b)); -}; - -#endif //!__EMOVEMENTPLATFORMSTATE__H__ diff --git a/dGame/dComponents/MovingPlatformComponent.cpp b/dGame/dComponents/MovingPlatformComponent.cpp index c33c073c..5c06d355 100644 --- a/dGame/dComponents/MovingPlatformComponent.cpp +++ b/dGame/dComponents/MovingPlatformComponent.cpp @@ -53,6 +53,44 @@ void PlatformSubComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsIn if (!bIsInitialUpdate) m_IsDirty = false; } +void PlatformSubComponent::StartPathing() { + m_State |= eMovementPlatformState::Travelling; + m_State &= ~eMovementPlatformState::Stopped; + m_State &= ~eMovementPlatformState::Waiting; +} + +void PlatformSubComponent::ResumePathing() { + if (m_State & eMovementPlatformState::Stopped && (m_State & eMovementPlatformState::ReachedDesiredWaypoint) == 0) { + StartPathing(); + } + if (m_State & eMovementPlatformState::Travelling == 0) { + m_State |= eMovementPlatformState::Waiting; + m_State &= ~eMovementPlatformState::Stopped; + m_State &= ~eMovementPlatformState::Travelling; + } else { + m_State &= eMovementPlatformState::Waiting; + m_State &= eMovementPlatformState::Travelling; + m_State &= eMovementPlatformState::Stopped; + // Set the velocities + } +} + +void PlatformSubComponent::StopPathing() { + m_State |= eMovementPlatformState::Stopped; + m_State &= ~eMovementPlatformState::Travelling; + m_State &= ~eMovementPlatformState::Waiting; + m_LinearVelocity = NiPoint3::ZERO; + m_AngularVelocity = NiPoint3::ZERO; +} + +void PlatformSubComponent::Update(float deltaTime) { + if (m_TimeBasedMovement && m_State & eMovementPlatformState::Travelling) { + m_MoveTimeElapsed += deltaTime; + } + if (m_State == 0) return; + +} + //------------- PlatformSubComponent end -------------- //------------- MoverPlatformSubComponent begin -------------- @@ -218,6 +256,9 @@ void MovingPlatformComponent::GotoWaypoint(uint32_t index, bool stopAtWaypoint) } void MovingPlatformComponent::StartPathing() { + std::for_each(m_Platforms.begin(), m_Platforms.end(), [](const std::unique_ptr& platform) { + platform->StartPathing(); + }); // state == Travelling // //GameMessages::SendStartPathing(m_Parent); // m_PathingStopped = false; diff --git a/dGame/dComponents/MovingPlatformComponent.h b/dGame/dComponents/MovingPlatformComponent.h index 94514e51..05f98d4f 100644 --- a/dGame/dComponents/MovingPlatformComponent.h +++ b/dGame/dComponents/MovingPlatformComponent.h @@ -13,11 +13,22 @@ #include "dCommonVars.h" #include "Component.h" -#include "eMovementPlatformState.h" #include "eReplicaComponentType.h" class Path; +/** + * The different types of platform movement state + */ +enum eMovementPlatformState : uint32_t +{ + Waiting = 1 << 0U, + Travelling = 1 << 1U, + Stopped = 1 << 2U, + ReachedDesiredWaypoint = 1 << 3U, + ReachedFinalWaypoint = 1 << 4U, +}; + /** * Different types of available platforms */ @@ -39,16 +50,21 @@ public: bool GetIsDirty() const { return m_IsDirty; } virtual void LoadDataFromTemplate() {}; virtual void LoadConfigData() {}; + virtual void StartPathing(); + virtual void ResumePathing(); + virtual void StopPathing(); + virtual void Update(float deltaTime); protected: #ifdef _MOVING_PLATFORM_TEST public: #endif MovingPlatformComponent* m_ParentComponent = nullptr; + /** * The state the platform is currently in */ - eMovementPlatformState m_State = eMovementPlatformState::Stopped | eMovementPlatformState::ReachedDesiredWaypoint; + uint32_t m_State = eMovementPlatformState::Stopped | eMovementPlatformState::ReachedDesiredWaypoint; int32_t m_DesiredWaypointIndex = 0; float m_PercentBetweenPoints = 0; NiPoint3 m_Position; @@ -61,6 +77,9 @@ public: bool m_IsDirty = false; bool m_InReverse = false; bool m_ShouldStopAtDesiredWaypoint = false; + NiPoint3 m_LinearVelocity; + NiPoint3 m_AngularVelocity; + bool m_TimeBasedMovement = false; }; class MoverPlatformSubComponent : public PlatformSubComponent { @@ -159,7 +178,7 @@ public: * Determines if the entity should be serialized on the next update * @param value whether to serialize the entity or not */ - void SetSerialized(bool value); + void SetSerialized(bool value) {}; /** * Returns if this platform will start automatically after spawn diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index ef9bea48..caa096e5 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -26,7 +26,6 @@ #include "ChatPackets.h" #include "RocketLaunchLupComponent.h" #include "eUnequippableActiveType.h" -#include "eMovementPlatformState.h" #include "LeaderboardManager.h" #include "Amf3.h" #include "Loot.h" @@ -349,9 +348,9 @@ void GameMessages::SendStartPathing(Entity* entity) { SEND_PACKET_BROADCAST; } -void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAddr, bool bStopAtDesiredWaypoint, - int iIndex, int iDesiredWaypointIndex, int nextIndex, - eMovementPlatformState movementState) { +void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAddr, + eMovementPlatformState movementState, bool bStopAtDesiredWaypoint, + int iIndex, int iDesiredWaypointIndex, int nextIndex) { CBITSTREAM; CMSGHEADER; @@ -362,7 +361,8 @@ void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAd iIndex = 0; nextIndex = 0; bStopAtDesiredWaypoint = true; - movementState = eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint; + movementState = static_cast( + eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint); } bitStream.Write(entity->GetObjectID()); @@ -5005,7 +5005,7 @@ 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); + GameMessages::SendPlatformResync(entity, sysAddr, eMovementPlatformState::Travelling); } void GameMessages::HandleRebuildCancel(RakNet::BitStream* inStream, Entity* entity) { diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 695d8209..8a0deb67 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -5,7 +5,6 @@ #include #include #include -#include "eMovementPlatformState.h" #include "NiPoint3.h" #include "eEndBehavior.h" #include "eCyclingMode.h" @@ -21,6 +20,7 @@ class Leaderboard; class PropertySelectQueryProperty; class TradeItem; +enum eMovementPlatformState : uint32_t; enum class eAnimationFlags : uint32_t; enum class eUnequippableActiveType; @@ -69,9 +69,9 @@ namespace GameMessages { void SendPlayNDAudioEmitter(Entity* entity, const SystemAddress& sysAddr, std::string audioGUID); void SendStartPathing(Entity* entity); - void SendPlatformResync(Entity* entity, const SystemAddress& sysAddr, bool bStopAtDesiredWaypoint = false, - int iIndex = 0, int iDesiredWaypointIndex = 1, int nextIndex = 1, - eMovementPlatformState movementState = eMovementPlatformState::Travelling); + void SendPlatformResync(Entity* entity, const SystemAddress& sysAddr, + eMovementPlatformState movementState, bool bStopAtDesiredWaypoint = false, + int iIndex = 0, int iDesiredWaypointIndex = 1, int nextIndex = 1); void SendRestoreToPostLoadStats(Entity* entity, const SystemAddress& sysAddr); void SendServerDoneLoadingAllObjects(Entity* entity, const SystemAddress& sysAddr); diff --git a/dScripts/02_server/Map/General/PropertyPlatform.cpp b/dScripts/02_server/Map/General/PropertyPlatform.cpp index b831bf48..2e6f68ed 100644 --- a/dScripts/02_server/Map/General/PropertyPlatform.cpp +++ b/dScripts/02_server/Map/General/PropertyPlatform.cpp @@ -4,15 +4,16 @@ #include "MovingPlatformComponent.h" void PropertyPlatform::OnRebuildComplete(Entity* self, Entity* target) { - GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, true, 0, - 0, 0, eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint); + GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS + , static_cast(eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint), + true, 0, 0, 0); } void PropertyPlatform::OnUse(Entity* self, Entity* user) { auto* rebuildComponent = self->GetComponent(); if (rebuildComponent != nullptr && rebuildComponent->GetState() == eRebuildState::COMPLETED) { - GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, true, 0, - 1, 1, eMovementPlatformState::Travelling); + GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, eMovementPlatformState::Travelling, true, 0, + 1, 1); self->AddCallbackTimer(movementDelay + effectDelay, [self, this]() { self->SetNetworkVar(u"startEffect", dieDelay); diff --git a/dScripts/ai/AG/AgBusDoor.cpp b/dScripts/ai/AG/AgBusDoor.cpp index fd6c272e..880d73c4 100644 --- a/dScripts/ai/AG/AgBusDoor.cpp +++ b/dScripts/ai/AG/AgBusDoor.cpp @@ -2,6 +2,7 @@ #include "Entity.h" #include "GameMessages.h" #include "ProximityMonitorComponent.h" +#include "MovingPlatformComponent.h" void AgBusDoor::OnStartup(Entity* self) { m_Counter = 0; @@ -48,9 +49,9 @@ void AgBusDoor::OnProximityUpdate(Entity* self, Entity* entering, std::string na void AgBusDoor::MoveDoor(Entity* self, bool bOpen) { if (bOpen) { - GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, true, 1, 0); + GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, eMovementPlatformState::Travelling, true, 1, 0); } else { - GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, true, 0, 1); + GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, eMovementPlatformState::Travelling, true, 0, 1); self->AddTimer("dustTimer", 2.0f); } diff --git a/dScripts/ai/AG/AgQbElevator.cpp b/dScripts/ai/AG/AgQbElevator.cpp index b39d3198..4f4d94f4 100644 --- a/dScripts/ai/AG/AgQbElevator.cpp +++ b/dScripts/ai/AG/AgQbElevator.cpp @@ -1,6 +1,7 @@ #include "AgQbElevator.h" #include "EntityManager.h" #include "GameMessages.h" +#include "MovingPlatformComponent.h" void AgQbElevator::OnStartup(Entity* self) { @@ -14,8 +15,9 @@ void AgQbElevator::OnRebuildComplete(Entity* self, Entity* target) { float delayTime = killTime - endTime; if (delayTime < 1) delayTime = 1; - GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, true, 0, - 0, 0, eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint); + GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, + static_cast(eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint) + , true, 0, 0, 0); //add a timer that will kill the QB if no players get on in the killTime self->AddTimer("startKillTimer", killTime); @@ -32,8 +34,8 @@ void AgQbElevator::OnProximityUpdate(Entity* self, Entity* entering, std::string self->SetBoolean(u"qbPlayerRdy", true); self->CancelTimer("StartElevator"); - GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, true, 0, - 1, 1, eMovementPlatformState::Travelling); + GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, eMovementPlatformState::Travelling, true, 0, + 1, 1); } else if (!self->GetBoolean(u"StartTimer")) { self->SetBoolean(u"StartTimer", true); self->AddTimer("StartElevator", startTime); @@ -44,8 +46,8 @@ void AgQbElevator::OnProximityUpdate(Entity* self, Entity* entering, std::string void AgQbElevator::OnTimerDone(Entity* self, std::string timerName) { if (timerName == "StartElevator") { - GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, true, 0, - 1, 1, eMovementPlatformState::Travelling); + GameMessages::SendPlatformResync(self, UNASSIGNED_SYSTEM_ADDRESS, eMovementPlatformState::Travelling, true, 0, + 1, 1); } else if (timerName == "startKillTimer") { killTimerStartup(self); } else if (timerName == "KillTimer") { diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 4aa8d0c9..21de5a6e 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -17,6 +17,7 @@ #include "eReplicaComponentType.h" #include "RenderComponent.h" #include "eGameActivity.h" +#include "MovingPlatformComponent.h" void SGCannon::OnStartup(Entity* self) { Game::logger->Log("SGCannon", "OnStartup"); @@ -314,7 +315,7 @@ void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) { // Save the enemy and tell it to start pathing if (enemy != nullptr) { const_cast&>(self->GetVar>(SpawnedObjects)).push_back(enemy->GetObjectID()); - GameMessages::SendPlatformResync(enemy, UNASSIGNED_SYSTEM_ADDRESS); + GameMessages::SendPlatformResync(enemy, UNASSIGNED_SYSTEM_ADDRESS, eMovementPlatformState::Travelling); } } } else if (name == EndGameBufferTimer) { diff --git a/dZoneManager/Zone.cpp b/dZoneManager/Zone.cpp index 6b153706..e2cdbf90 100644 --- a/dZoneManager/Zone.cpp +++ b/dZoneManager/Zone.cpp @@ -381,7 +381,7 @@ void Zone::LoadPath(std::istream& file) { BinaryIO::BinaryRead(file, character); path.pathName.push_back(character); } - + Game::logger->Log("Zone", "pathname: %s", path.pathName.c_str()); BinaryIO::BinaryRead(file, path.pathType); BinaryIO::BinaryRead(file, path.flags); BinaryIO::BinaryRead(file, path.pathBehavior); @@ -479,6 +479,7 @@ void Zone::LoadPath(std::istream& file) { if (path.pathType == PathType::MovingPlatform) { BinaryIO::BinaryRead(file, waypoint.movingPlatform.lockPlayer); BinaryIO::BinaryRead(file, waypoint.movingPlatform.speed); + Game::logger->Log("Zone", "speed: %f", waypoint.movingPlatform.speed); BinaryIO::BinaryRead(file, waypoint.movingPlatform.wait); if (path.pathVersion >= 13) { uint8_t count1;