moving platform work

This commit is contained in:
David Markowitz 2023-08-02 00:02:02 -07:00
parent 4336cb7f50
commit c293b7a9d7
10 changed files with 93 additions and 51 deletions

View File

@ -1,24 +0,0 @@
#ifndef __EMOVEMENTPLATFORMSTATE__H__
#define __EMOVEMENTPLATFORMSTATE__H__
#include <cstdint>
/**
* 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<eMovementPlatformState>(
static_cast<std::underlying_type<eMovementPlatformState>::type>(a) |
static_cast<std::underlying_type<eMovementPlatformState>::type>(b));
};
#endif //!__EMOVEMENTPLATFORMSTATE__H__

View File

@ -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<PlatformSubComponent>& platform) {
platform->StartPathing();
});
// state == Travelling
// //GameMessages::SendStartPathing(m_Parent);
// m_PathingStopped = false;

View File

@ -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

View File

@ -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>(
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) {

View File

@ -5,7 +5,6 @@
#include <map>
#include <string>
#include <vector>
#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);

View File

@ -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>(eMovementPlatformState::Waiting | eMovementPlatformState::ReachedDesiredWaypoint | eMovementPlatformState::ReachedFinalWaypoint),
true, 0, 0, 0);
}
void PropertyPlatform::OnUse(Entity* self, Entity* user) {
auto* rebuildComponent = self->GetComponent<RebuildComponent>();
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<float_t>(u"startEffect", dieDelay);

View File

@ -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);
}

View File

@ -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>(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") {

View File

@ -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<std::vector<LWOOBJID>&>(self->GetVar<std::vector<LWOOBJID>>(SpawnedObjects)).push_back(enemy->GetObjectID());
GameMessages::SendPlatformResync(enemy, UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::SendPlatformResync(enemy, UNASSIGNED_SYSTEM_ADDRESS, eMovementPlatformState::Travelling);
}
}
} else if (name == EndGameBufferTimer) {

View File

@ -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;