Files
DarkflameServer/dGame/dComponents/MovingPlatformComponent.h
Aaron Kimbrell 5e40aaf420 Refactor MovingPlatformComponent to support subcomponents for movement and rotation
- Introduced PlatformSubComponent as a base class for platform movement logic.
- Added MoverSubComponent for standard path-following behavior.
- Implemented SimpleMoverSubComponent for auto-generating two-waypoint paths.
- Created RotatorSubComponent to handle angular velocity and rotation along paths.
- Updated MovingPlatformComponent to manage multiple subcomponents and their states.
- Modified serialization and update logic to accommodate new subcomponent architecture.
- Adjusted GameMessages to include additional parameters for platform state synchronization.
- Enhanced SimplePhysicsComponent to prevent double movement when on a moving platform.
- Added new CMakeLists.txt for organizing MovingPlatformComponent files.
2026-04-08 16:32:10 -05:00

85 lines
2.2 KiB
C++

/*
* Darkflame Universe
* Copyright 2019
*/
#ifndef MOVINGPLATFORMCOMPONENT_H
#define MOVINGPLATFORMCOMPONENT_H
#include "Component.h"
#include "eReplicaComponentType.h"
#include "NiPoint3.h"
#include "NiQuaternion.h"
#include <string>
#include <memory>
class Path;
class Entity;
class PlatformSubComponent;
class RotatorSubComponent;
/**
* Different types of available platform subcomponents
*/
enum class eMoverSubComponentType : uint32_t {
mover = 4,
simpleMover = 5,
rotator = 6,
};
/**
* Represents entities that may be moving platforms, indicating how they should move through the world.
* The server simulates platform movement each tick to maintain authoritative state for all players.
*
* An entity can have multiple subcomponents (mover + rotator), matching the client's architecture
* where SetupPlatform creates subcomponents based on platformIsMover/platformIsSimpleMover/platformIsRotater.
*/
class MovingPlatformComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::MOVING_PLATFORM;
MovingPlatformComponent(Entity* parent, const int32_t componentID, const std::string& pathName);
~MovingPlatformComponent() override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void Update(float deltaTime) override;
void OnQuickBuildInitilized();
void OnCompleteQuickBuild();
void GotoWaypoint(uint32_t index, bool stopAtWaypoint = true);
void StartPathing();
void StopPathing();
void SetSerialized(bool value);
bool GetNoAutoStart() const;
void SetNoAutoStart(bool value);
void WarpToWaypoint(size_t index);
size_t GetLastWaypointIndex() const;
PlatformSubComponent* GetMoverSubComponent() const;
void SetMovementState(uint32_t state);
private:
void SetupPlatformSubComponents();
const Path* m_Path = nullptr;
std::u16string m_PathName;
bool m_PathingStopped = false;
eMoverSubComponentType m_MoverSubComponentType;
std::unique_ptr<PlatformSubComponent> m_MoverSubComponent;
std::unique_ptr<RotatorSubComponent> m_RotatorSubComponent;
bool m_NoAutoStart = false;
bool m_Serialize = false;
std::string m_PlatformSoundStart;
std::string m_PlatformSoundTravel;
std::string m_PlatformSoundStop;
};
#endif // MOVINGPLATFORMCOMPONENT_H