Bug fixes, naming changes to make variables more clear, and adds a cvar to adjust client window size

This commit is contained in:
karlberg
2021-05-27 19:54:56 -07:00
parent 29163fba1a
commit 802943bbb3
12 changed files with 210 additions and 58 deletions
@@ -25,6 +25,7 @@ namespace Multiplayer
AZ_CVAR(AZ::TimeMs, cl_MaxRewindHistoryMs, AZ::TimeMs{ 2000 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Maximum number of milliseconds to keep for server correction rewind and replay");
#ifndef AZ_RELEASE_BUILD
AZ_CVAR(float, cl_DebugHackTimeMultiplier, 1.0f, nullptr, AZ::ConsoleFunctorFlags::Null, "Scalar value used to simulate clock hacking cheats for validating bank time system and anticheat");
AZ_CVAR(bool, cl_EnableDesyncDebugging, true, nullptr, AZ::ConsoleFunctorFlags::Null, "If enabled, debug logs will contain verbose information on detected state desyncs");
#endif
AZ_CVAR(bool, sv_EnableCorrections, true, nullptr, AZ::ConsoleFunctorFlags::Null, "Enables server corrections on autonomous proxy desyncs");
@@ -214,11 +215,12 @@ namespace Multiplayer
// Send correction
SendClientInputCorrection(GetLastInputId(), correction);
#ifdef _DEBUG
// In debug, show which states caused the correction
#ifndef AZ_RELEASE_BUILD
AZStd::string clientStateString;
AZStd::string serverStateString;
if (cl_EnableDesyncDebugging)
{
// In debug, show which states caused the correction
// Write in client state
AzNetworking::NetworkOutputSerializer clientStateSerializer(clientState.GetBuffer(), clientState.GetSize());
GetNetBindComponent()->SerializeEntityCorrection(clientStateSerializer);
@@ -236,11 +238,13 @@ namespace Multiplayer
GetNetBindComponent()->SerializeEntityCorrection(serverValues);
AZStd::map<AZStd::string, AZStd::pair<AZStd::string, AZStd::string>> mapComparison;
// put the server value in the first part of the pair
for (const auto& pair : serverValues.GetValueMap())
{
mapComparison[pair.first].first = pair.second;
}
// put the client value in the second part of the pair
for (const auto& pair : clientValues.GetValueMap())
{
@@ -266,12 +270,13 @@ namespace Multiplayer
}
}
}
#else
const AZStd::string clientStateString = "available in debug only";
const AZStd::string serverStateString = "available in debug only";
#endif
else
{
clientStateString = "available in debug only";
serverStateString = "available in debug only";
}
AZLOG_ERROR("** Autonomous proxy desync detected! ** clientState=[%s], serverState=[%s]", clientStateString.c_str(), serverStateString.c_str());
#endif
}
}
}
@@ -416,7 +421,7 @@ namespace Multiplayer
ClientInputId LocalPredictionPlayerInputComponentController::GetLastInputId() const
{
return m_clientInputId;
return m_lastClientInputId;
}
HostFrameId LocalPredictionPlayerInputComponentController::GetInputFrameId(const NetworkInput& input) const
@@ -520,10 +525,13 @@ namespace Multiplayer
// In debug, send the entire client output state to the server to make it easier to debug desync issues
AzNetworking::PacketEncodingBuffer processInputResult;
#ifdef _DEBUG
AzNetworking::NetworkInputSerializer processInputResultSerializer(processInputResult.GetBuffer(), processInputResult.GetCapacity());
GetNetBindComponent()->SerializeEntityCorrection(processInputResultSerializer);
processInputResult.Resize(processInputResultSerializer.GetSize());
#ifndef AZ_RELEASE_BUILD
if (cl_EnableDesyncDebugging)
{
AzNetworking::NetworkInputSerializer processInputResultSerializer(processInputResult.GetBuffer(), processInputResult.GetCapacity());
GetNetBindComponent()->SerializeEntityCorrection(processInputResultSerializer);
processInputResult.Resize(processInputResultSerializer.GetSize());
}
#endif
// Save this input and discard move history outside our client rewind window
@@ -390,6 +390,11 @@ namespace Multiplayer
m_entityServerMigrationEvent.Signal(m_netEntityHandle, hostId, connectionId);
}
void NetBindComponent::NotifyPreRender(float deltaTime, float blendFactor)
{
m_entityPreRenderEvent.Signal(deltaTime, blendFactor);
}
void NetBindComponent::AddEntityStopEventHandler(EntityStopEvent::Handler& eventHandler)
{
eventHandler.Connect(m_entityStopEvent);
@@ -420,6 +425,11 @@ namespace Multiplayer
eventHandler.Connect(m_entityServerMigrationEvent);
}
void NetBindComponent::AddEntityPreRenderEventHandler(EntityPreRenderEvent::Handler& eventHandler)
{
eventHandler.Connect(m_entityPreRenderEvent);
}
bool NetBindComponent::SerializeEntityCorrection(AzNetworking::ISerializer& serializer)
{
m_predictableRecord.ResetConsumedBits();
@@ -33,6 +33,8 @@ namespace Multiplayer
: 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); })
, m_resetCountEventHandler([this](const uint8_t&) { OnResetCountChangedEvent(); })
, m_entityPreRenderEventHandler([this](float deltaTime, float blendFactor) { OnPreRender(deltaTime, blendFactor); })
{
;
}
@@ -47,6 +49,11 @@ namespace Multiplayer
RotationAddEvent(m_rotationEventHandler);
TranslationAddEvent(m_translationEventHandler);
ScaleAddEvent(m_scaleEventHandler);
ResetCountAddEvent(m_resetCountEventHandler);
GetNetBindComponent()->AddEntityPreRenderEventHandler(m_entityPreRenderEventHandler);
// When coming into relevance, reset all blending factors so we don't interpolate to our start position
OnResetCountChangedEvent();
}
void NetworkTransformComponent::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
@@ -56,23 +63,37 @@ namespace Multiplayer
void NetworkTransformComponent::OnRotationChangedEvent(const AZ::Quaternion& rotation)
{
AZ::Transform worldTm = GetTransformComponent()->GetWorldTM();
worldTm.SetRotation(rotation);
GetTransformComponent()->SetWorldTM(worldTm);
m_previousTransform.SetRotation(m_targetTransform.GetRotation());
m_targetTransform.SetRotation(rotation);
}
void NetworkTransformComponent::OnTranslationChangedEvent(const AZ::Vector3& translation)
{
AZ::Transform worldTm = GetTransformComponent()->GetWorldTM();
worldTm.SetTranslation(translation);
GetTransformComponent()->SetWorldTM(worldTm);
m_previousTransform.SetTranslation(m_targetTransform.GetTranslation());
m_targetTransform.SetTranslation(translation);
}
void NetworkTransformComponent::OnScaleChangedEvent(const AZ::Vector3& scale)
{
AZ::Transform worldTm = GetTransformComponent()->GetWorldTM();
worldTm.SetScale(scale);
GetTransformComponent()->SetWorldTM(worldTm);
m_previousTransform.SetScale(m_targetTransform.GetScale());
m_targetTransform.SetScale(scale);
}
void NetworkTransformComponent::OnResetCountChangedEvent()
{
m_previousTransform = m_targetTransform;
}
void NetworkTransformComponent::OnPreRender([[maybe_unused]] float deltaTime, float blendFactor)
{
if (!HasController())
{
AZ::Transform blendTransform;
blendTransform.SetRotation(m_previousTransform.GetRotation().Slerp(m_targetTransform.GetRotation(), blendFactor));
blendTransform.SetTranslation(m_previousTransform.GetTranslation().Lerp(m_targetTransform.GetTranslation(), blendFactor));
blendTransform.SetScale(m_previousTransform.GetScale().Lerp(m_targetTransform.GetScale(), blendFactor));
GetTransformComponent()->SetWorldTM(blendTransform);
}
}
@@ -96,11 +117,8 @@ namespace Multiplayer
void NetworkTransformComponentController::OnTransformChangedEvent(const AZ::Transform& worldTm)
{
if (IsAuthority())
{
SetRotation(worldTm.GetRotation());
SetTranslation(worldTm.GetTranslation());
SetScale(worldTm.GetScale());
}
SetRotation(worldTm.GetRotation());
SetTranslation(worldTm.GetTranslation());
SetScale(worldTm.GetScale());
}
}