Add server side accounting for blend factor

Signed-off-by: puvvadar <puvvadar@amazon.com>
monroegm-disable-blank-issue-2
puvvadar 5 years ago
parent 7950c2b549
commit ebe326f6e9

@ -121,6 +121,8 @@ namespace Multiplayer
//! @return the current server time in milliseconds
virtual AZ::TimeMs GetCurrentHostTimeMs() const = 0;
virtual float GetCurrentBlendFactor() const = 0;
//! Returns the network time instance bound to this multiplayer instance.
//! @return pointer to the network time instance bound to this multiplayer instance
virtual INetworkTime* GetNetworkTime() = 0;

@ -44,6 +44,9 @@ namespace Multiplayer
AZ::TimeMs GetHostTimeMs() const;
AZ::TimeMs& ModifyHostTimeMs();
void SetHostBlendFactor(float hostBlendFactor);
float GetHostBlendFactor() const;
void AttachNetBindComponent(NetBindComponent* netBindComponent);
bool Serialize(AzNetworking::ISerializer& serializer);
@ -72,6 +75,7 @@ namespace Multiplayer
ClientInputId m_inputId = ClientInputId{ 0 };
HostFrameId m_hostFrameId = InvalidHostFrameId;
AZ::TimeMs m_hostTimeMs = AZ::TimeMs{ 0 };
float m_hostBlendFactor = 0.f;
ConstNetworkEntityHandle m_owner;
bool m_wasAttached = false;
};

@ -154,9 +154,12 @@ namespace Multiplayer
// Discard move input events, client may be speed hacking
if (m_clientBankedTime < sv_MaxBankTimeWindowSec)
{
// Client blends from previous frame to target so here we subtract blend factor to get to that state
const float adjustedBlendFactor = std::pow(0.2f, input.GetHostBlendFactor());
const AZ::TimeMs blendMs = AZ::TimeMs(static_cast<float>(static_cast<AZ::TimeMs>(cl_InputRateMs)) * adjustedBlendFactor);
m_clientBankedTime = AZStd::min(m_clientBankedTime + clientInputRateSec, (double)sv_MaxBankTimeWindowSec); // clamp to boundary
{
ScopedAlterTime scopedTime(input.GetHostFrameId(), input.GetHostTimeMs(), invokingConnection->GetConnectionId());
ScopedAlterTime scopedTime(input.GetHostFrameId(), input.GetHostTimeMs() - blendMs, invokingConnection->GetConnectionId());
GetNetBindComponent()->ProcessInput(input, static_cast<float>(clientInputRateSec));
}
@ -498,6 +501,7 @@ namespace Multiplayer
input.SetClientInputId(m_clientInputId);
input.SetHostFrameId(networkTime->GetHostFrameId());
input.SetHostTimeMs(multiplayer->GetCurrentHostTimeMs());
input.SetHostBlendFactor(multiplayer->GetCurrentBlendFactor());
// Allow components to form the input for this frame
GetNetBindComponent()->CreateInput(input, inputRate);

@ -802,6 +802,11 @@ namespace Multiplayer
}
}
float MultiplayerSystemComponent::GetCurrentBlendFactor() const
{
return m_renderBlendFactor;
}
INetworkTime* MultiplayerSystemComponent::GetNetworkTime()
{
return &m_networkTime;

@ -112,6 +112,7 @@ namespace Multiplayer
void Terminate(AzNetworking::DisconnectReason reason) override;
void SendReadyForEntityUpdates(bool readyForEntityUpdates) override;
AZ::TimeMs GetCurrentHostTimeMs() const override;
float GetCurrentBlendFactor() const override;
INetworkTime* GetNetworkTime() override;
INetworkEntityManager* GetNetworkEntityManager() override;
void SetFilterEntityManager(IFilterEntityManager* entityFilter) override;

@ -75,6 +75,16 @@ namespace Multiplayer
return m_hostTimeMs;
}
void NetworkInput::SetHostBlendFactor(float hostBlendFactor)
{
m_hostBlendFactor = hostBlendFactor;
}
float NetworkInput::GetHostBlendFactor() const
{
return m_hostBlendFactor;
}
void NetworkInput::AttachNetBindComponent(NetBindComponent* netBindComponent)
{
m_wasAttached = true;
@ -90,7 +100,8 @@ namespace Multiplayer
{
if (!serializer.Serialize(m_inputId, "InputId")
|| !serializer.Serialize(m_hostTimeMs, "HostTimeMs")
|| !serializer.Serialize(m_hostFrameId, "HostFrameId"))
|| !serializer.Serialize(m_hostFrameId, "HostFrameId")
|| !serializer.Serialize(m_hostBlendFactor, "HostBlendFactor"))
{
return false;
}
@ -163,6 +174,7 @@ namespace Multiplayer
m_inputId = rhs.m_inputId;
m_hostFrameId = rhs.m_hostFrameId;
m_hostTimeMs = rhs.m_hostTimeMs;
m_hostBlendFactor = rhs.m_hostBlendFactor;
m_componentInputs.resize(rhs.m_componentInputs.size());
for (int32_t i = 0; i < rhs.m_componentInputs.size(); ++i)
{

Loading…
Cancel
Save