Various bug fixes to get entity replication working
This commit is contained in:
@@ -24,7 +24,6 @@ namespace Multiplayer
|
||||
serializeContext->Class<LocalPredictionPlayerInputComponent, LocalPredictionPlayerInputComponentBase>()
|
||||
->Version(1);
|
||||
}
|
||||
|
||||
LocalPredictionPlayerInputComponentBase::Reflect(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,12 @@ namespace Multiplayer
|
||||
|
||||
NetEntityId MultiplayerComponent::GetNetEntityId() const
|
||||
{
|
||||
const NetBindComponent* netBindComponent = GetNetBindComponent();
|
||||
return netBindComponent ? netBindComponent->GetNetEntityId() : InvalidNetEntityId;
|
||||
return m_netBindComponent ? m_netBindComponent->GetNetEntityId() : InvalidNetEntityId;
|
||||
}
|
||||
|
||||
NetEntityRole MultiplayerComponent::GetNetEntityRole() const
|
||||
{
|
||||
return m_netBindComponent ? m_netBindComponent->GetNetEntityRole() : NetEntityRole::InvalidRole;
|
||||
}
|
||||
|
||||
ConstNetworkEntityHandle MultiplayerComponent::GetEntityHandle() const
|
||||
|
||||
@@ -62,6 +62,7 @@ namespace Multiplayer
|
||||
//! @}
|
||||
|
||||
NetEntityId GetNetEntityId() const;
|
||||
NetEntityRole GetNetEntityRole() const;
|
||||
ConstNetworkEntityHandle GetEntityHandle() const;
|
||||
NetworkEntityHandle GetEntityHandle();
|
||||
void MarkDirty();
|
||||
@@ -109,7 +110,8 @@ namespace Multiplayer
|
||||
int32_t bitIndex,
|
||||
TYPE& value,
|
||||
const char* name,
|
||||
[[maybe_unused]] NetComponentId componentId
|
||||
[[maybe_unused]] NetComponentId componentId,
|
||||
MultiplayerStats& stats
|
||||
)
|
||||
{
|
||||
if (bitset.GetBit(bitIndex))
|
||||
@@ -119,6 +121,7 @@ namespace Multiplayer
|
||||
serializer.Serialize(value, name);
|
||||
if (modifyRecord && !serializer.GetTrackedChangesFlag())
|
||||
{
|
||||
// If the serializer didn't change any values, then lower the flag so we don't unnecessarily notify
|
||||
bitset.SetBit(bitIndex, false);
|
||||
}
|
||||
const uint32_t postUpdateSize = serializer.GetSize();
|
||||
@@ -126,8 +129,7 @@ namespace Multiplayer
|
||||
const uint32_t updateSize = (postUpdateSize - prevUpdateSize);
|
||||
if (updateSize > 0)
|
||||
{
|
||||
MultiplayerStats& stats = AZ::Interface<IMultiplayer>::Get()->GetStats();
|
||||
if (serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject)
|
||||
if (modifyRecord)
|
||||
{
|
||||
stats.m_propertyUpdatesRecv++;
|
||||
stats.m_propertyUpdatesRecvBytes += updateSize;
|
||||
|
||||
@@ -27,6 +27,11 @@ namespace Multiplayer
|
||||
return m_owner.GetNetEntityId();
|
||||
}
|
||||
|
||||
NetEntityRole MultiplayerController::GetNetEntityRole() const
|
||||
{
|
||||
return GetNetBindComponent()->GetNetEntityRole();
|
||||
}
|
||||
|
||||
AZ::Entity* MultiplayerController::GetEntity() const
|
||||
{
|
||||
return m_owner.GetEntity();
|
||||
|
||||
@@ -47,6 +47,10 @@ namespace Multiplayer
|
||||
//! @return the networkId for the entity that owns this controller
|
||||
NetEntityId GetNetEntityId() const;
|
||||
|
||||
//! Returns the networkRole for the entity that owns this controller.
|
||||
//! @return the networkRole for the entity that owns this controller
|
||||
NetEntityRole GetNetEntityRole() const;
|
||||
|
||||
//! Returns the raw AZ::Entity pointer for the entity that owns this controller.
|
||||
//! @return the raw AZ::Entity pointer for the entity that owns this controller
|
||||
AZ::Entity* GetEntity() const;
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <Source/Components/NetworkTransformComponent.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/EBus/IEventScheduler.h>
|
||||
#include <AzFramework/Components/TransformComponent.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
@@ -24,7 +26,81 @@ namespace Multiplayer
|
||||
serializeContext->Class<NetworkTransformComponent, NetworkTransformComponentBase>()
|
||||
->Version(1);
|
||||
}
|
||||
|
||||
NetworkTransformComponentBase::Reflect(context);
|
||||
}
|
||||
|
||||
NetworkTransformComponent::NetworkTransformComponent()
|
||||
: m_rotationEventHandler([this](const AZ::Quaternion& rotation) { OnRotationChangedEvent(rotation); })
|
||||
, m_translationEventHandler([this](const AZ::Vector3& translation) { OnTranslationChangedEvent(translation); })
|
||||
, m_scaleEventHandler([this](const AZ::Vector3& scale) { OnScaleChangedEvent(scale); })
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void NetworkTransformComponent::OnInit()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void NetworkTransformComponent::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
RotationAddEvent(m_rotationEventHandler);
|
||||
TranslationAddEvent(m_translationEventHandler);
|
||||
ScaleAddEvent(m_scaleEventHandler);
|
||||
}
|
||||
|
||||
void NetworkTransformComponent::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void NetworkTransformComponent::OnRotationChangedEvent(const AZ::Quaternion& rotation)
|
||||
{
|
||||
AZ::Transform worldTm = GetTransformComponent()->GetWorldTM();
|
||||
worldTm.SetRotation(rotation);
|
||||
GetTransformComponent()->SetWorldTM(worldTm);
|
||||
}
|
||||
|
||||
void NetworkTransformComponent::OnTranslationChangedEvent(const AZ::Vector3& translation)
|
||||
{
|
||||
AZ::Transform worldTm = GetTransformComponent()->GetWorldTM();
|
||||
worldTm.SetTranslation(translation);
|
||||
GetTransformComponent()->SetWorldTM(worldTm);
|
||||
}
|
||||
|
||||
void NetworkTransformComponent::OnScaleChangedEvent(const AZ::Vector3& scale)
|
||||
{
|
||||
AZ::Transform worldTm = GetTransformComponent()->GetWorldTM();
|
||||
worldTm.SetScale(scale);
|
||||
GetTransformComponent()->SetWorldTM(worldTm);
|
||||
}
|
||||
|
||||
|
||||
NetworkTransformComponentController::NetworkTransformComponentController(NetworkTransformComponent& parent)
|
||||
: NetworkTransformComponentControllerBase(parent)
|
||||
, m_transformChangedHandler([this](const AZ::Transform&, const AZ::Transform& worldTm) { OnTransformChangedEvent(worldTm); })
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void NetworkTransformComponentController::OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
GetParent().GetTransformComponent()->BindTransformChangedEventHandler(m_transformChangedHandler);
|
||||
OnTransformChangedEvent(GetParent().GetTransformComponent()->GetWorldTM());
|
||||
}
|
||||
|
||||
void NetworkTransformComponentController::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void NetworkTransformComponentController::OnTransformChangedEvent(const AZ::Transform& worldTm)
|
||||
{
|
||||
if (GetNetEntityRole() == NetEntityRole::Authority)
|
||||
{
|
||||
SetRotation(worldTm.GetRotation());
|
||||
SetTranslation(worldTm.GetTranslation());
|
||||
SetScale(worldTm.GetScale());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Source/AutoGen/NetworkTransformComponent.AutoComponent.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
@@ -22,20 +23,37 @@ namespace Multiplayer
|
||||
public:
|
||||
AZ_MULTIPLAYER_COMPONENT(Multiplayer::NetworkTransformComponent, s_networkTransformComponentConcreteUuid, Multiplayer::NetworkTransformComponentBase);
|
||||
|
||||
static void Reflect([[maybe_unused]] AZ::ReflectContext* context);
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
void OnInit() override {}
|
||||
void OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
|
||||
void OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
|
||||
NetworkTransformComponent();
|
||||
|
||||
void OnInit() override;
|
||||
void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
|
||||
void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
|
||||
|
||||
private:
|
||||
void OnRotationChangedEvent(const AZ::Quaternion& rotation);
|
||||
void OnTranslationChangedEvent(const AZ::Vector3& translation);
|
||||
void OnScaleChangedEvent(const AZ::Vector3& scale);
|
||||
|
||||
AZ::Event<AZ::Quaternion>::Handler m_rotationEventHandler;
|
||||
AZ::Event<AZ::Vector3>::Handler m_translationEventHandler;
|
||||
AZ::Event<AZ::Vector3>::Handler m_scaleEventHandler;
|
||||
};
|
||||
|
||||
class NetworkTransformComponentController
|
||||
: public NetworkTransformComponentControllerBase
|
||||
{
|
||||
public:
|
||||
NetworkTransformComponentController(NetworkTransformComponent& parent) : NetworkTransformComponentControllerBase(parent) {}
|
||||
NetworkTransformComponentController(NetworkTransformComponent& parent);
|
||||
|
||||
void OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
|
||||
void OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
|
||||
void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
|
||||
void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
|
||||
|
||||
private:
|
||||
void OnTransformChangedEvent(const AZ::Transform& worldTm);
|
||||
|
||||
AZ::TransformChangedEvent::Handler m_transformChangedHandler;
|
||||
AZ::ScheduledEvent m_transformChangeEvent;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user