Ported the local prediction player controller component
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Include/MultiplayerTypes.h>
|
||||
#include <AzNetworking/DataStructures/FixedSizeBitset.h>
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
#include <AzCore/std/smart_ptr/unique_ptr.h>
|
||||
|
||||
namespace AzNetworking
|
||||
{
|
||||
class ISerializer;
|
||||
}
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
class IMultiplayerComponentInput
|
||||
{
|
||||
public:
|
||||
virtual ~IMultiplayerComponentInput() = default;
|
||||
virtual NetComponentId GetComponentId() const = 0;
|
||||
virtual bool Serialize(AzNetworking::ISerializer& serializer) = 0;
|
||||
};
|
||||
|
||||
using MultiplayerComponentInputVector = AZStd::vector<AZStd::unique_ptr<IMultiplayerComponentInput>>;
|
||||
}
|
||||
@@ -48,19 +48,34 @@ namespace Multiplayer
|
||||
return m_inputId;
|
||||
}
|
||||
|
||||
void NetworkInput::SetServerTimeMs(AZ::TimeMs serverTimeMs)
|
||||
void NetworkInput::SetHostFrameId(HostFrameId hostFrameId)
|
||||
{
|
||||
m_serverTimeMs = serverTimeMs;
|
||||
m_hostFrameId = hostFrameId;
|
||||
}
|
||||
|
||||
AZ::TimeMs NetworkInput::GetServerTimeMs() const
|
||||
HostFrameId NetworkInput::GetHostFrameId() const
|
||||
{
|
||||
return m_serverTimeMs;
|
||||
return m_hostFrameId;
|
||||
}
|
||||
|
||||
AZ::TimeMs& NetworkInput::ModifyServerTimeMs()
|
||||
HostFrameId& NetworkInput::ModifyHostFrameId()
|
||||
{
|
||||
return m_serverTimeMs;
|
||||
return m_hostFrameId;
|
||||
}
|
||||
|
||||
void NetworkInput::SetHostTimeMs(AZ::TimeMs hostTimeMs)
|
||||
{
|
||||
m_hostTimeMs = hostTimeMs;
|
||||
}
|
||||
|
||||
AZ::TimeMs NetworkInput::GetHostTimeMs() const
|
||||
{
|
||||
return m_hostTimeMs;
|
||||
}
|
||||
|
||||
AZ::TimeMs& NetworkInput::ModifyHostTimeMs()
|
||||
{
|
||||
return m_hostTimeMs;
|
||||
}
|
||||
|
||||
void NetworkInput::AttachNetBindComponent(NetBindComponent* netBindComponent)
|
||||
@@ -76,17 +91,19 @@ namespace Multiplayer
|
||||
|
||||
bool NetworkInput::Serialize(AzNetworking::ISerializer& serializer)
|
||||
{
|
||||
if (!serializer.Serialize(m_inputId, "InputId"))
|
||||
if (!serializer.Serialize(m_inputId, "InputId")
|
||||
|| !serializer.Serialize(m_hostTimeMs, "HostTimeMs")
|
||||
|| !serializer.Serialize(m_hostFrameId, "HostFrameId"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t componentInputCount = static_cast<uint8_t>(m_componentInputs.size());
|
||||
uint16_t componentInputCount = static_cast<uint16_t>(m_componentInputs.size());
|
||||
serializer.Serialize(componentInputCount, "ComponentInputCount");
|
||||
m_componentInputs.resize(componentInputCount);
|
||||
if (serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject)
|
||||
{
|
||||
for (uint8_t i = 0; i < componentInputCount; ++i)
|
||||
for (uint16_t i = 0; i < componentInputCount; ++i)
|
||||
{
|
||||
// We need to do a little extra work here, the delta serializer won't actually write out values if they were the same as the parent.
|
||||
// We need to make sure we don't lose state that is intrinsic to the underlying type
|
||||
@@ -148,7 +165,7 @@ namespace Multiplayer
|
||||
void NetworkInput::CopyInternal(const NetworkInput& rhs)
|
||||
{
|
||||
m_inputId = rhs.m_inputId;
|
||||
m_serverTimeMs = rhs.m_serverTimeMs;
|
||||
m_hostTimeMs = rhs.m_hostTimeMs;
|
||||
m_componentInputs.resize(rhs.m_componentInputs.size());
|
||||
for (int32_t i = 0; i < rhs.m_componentInputs.size(); ++i)
|
||||
{
|
||||
|
||||
@@ -12,8 +12,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Source/NetworkInput/IMultiplayerComponentInput.h>
|
||||
#include <Source/NetworkEntity/NetworkEntityHandle.h>
|
||||
#include <Include/IMultiplayerComponentInput.h>
|
||||
#include <Include/INetworkTime.h>
|
||||
#include <Include/NetworkEntityHandle.h>
|
||||
#include <AzCore/RTTI/TypeSafeIntegral.h>
|
||||
|
||||
namespace Multiplayer
|
||||
@@ -21,8 +22,6 @@ namespace Multiplayer
|
||||
// Forwards
|
||||
class NetBindComponent;
|
||||
|
||||
AZ_TYPE_SAFE_INTEGRAL(ClientInputId, uint16_t);
|
||||
|
||||
//! @class NetworkInput
|
||||
//! @brief A single networked client input command.
|
||||
class NetworkInput final
|
||||
@@ -42,9 +41,13 @@ namespace Multiplayer
|
||||
ClientInputId GetClientInputId() const;
|
||||
ClientInputId& ModifyClientInputId();
|
||||
|
||||
void SetServerTimeMs(AZ::TimeMs serverTimeMs);
|
||||
AZ::TimeMs GetServerTimeMs() const;
|
||||
AZ::TimeMs& ModifyServerTimeMs();
|
||||
void SetHostFrameId(HostFrameId hostFrameId);
|
||||
HostFrameId GetHostFrameId() const;
|
||||
HostFrameId& ModifyHostFrameId();
|
||||
|
||||
void SetHostTimeMs(AZ::TimeMs hostTimeMs);
|
||||
AZ::TimeMs GetHostTimeMs() const;
|
||||
AZ::TimeMs& ModifyHostTimeMs();
|
||||
|
||||
void AttachNetBindComponent(NetBindComponent* netBindComponent);
|
||||
|
||||
@@ -72,10 +75,9 @@ namespace Multiplayer
|
||||
|
||||
MultiplayerComponentInputVector m_componentInputs;
|
||||
ClientInputId m_inputId = ClientInputId{ 0 };
|
||||
AZ::TimeMs m_serverTimeMs = AZ::TimeMs{ 0 };
|
||||
HostFrameId m_hostFrameId = InvalidHostFrameId;
|
||||
AZ::TimeMs m_hostTimeMs = AZ::TimeMs{ 0 };
|
||||
ConstNetworkEntityHandle m_owner;
|
||||
bool m_wasAttached = false;
|
||||
};
|
||||
}
|
||||
|
||||
AZ_TYPE_SAFE_INTEGRAL_SERIALIZEBINDING(Multiplayer::ClientInputId);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
#include <Source/NetworkInput/NetworkInputChild.h>
|
||||
#include <Source/NetworkEntity/INetworkEntityManager.h>
|
||||
#include <Include/INetworkEntityManager.h>
|
||||
#include <AzNetworking/Serialization/ISerializer.h>
|
||||
|
||||
namespace Multiplayer
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
#include <Source/NetworkInput/NetworkInputVector.h>
|
||||
#include <Source/NetworkEntity/INetworkEntityManager.h>
|
||||
#include <Include/INetworkEntityManager.h>
|
||||
#include <AzNetworking/Serialization/ISerializer.h>
|
||||
#include <AzNetworking/Serialization/DeltaSerializer.h>
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Source/NetworkInput/NetworkInput.h>
|
||||
#include <Source/NetworkEntity/NetworkEntityHandle.h>
|
||||
#include <Include/NetworkEntityHandle.h>
|
||||
#include <AzCore/std/containers/fixed_vector.h>
|
||||
|
||||
namespace Multiplayer
|
||||
|
||||
Reference in New Issue
Block a user