Many fixes for external gem multiplayer components and component network inputs, fixes an uninitialized variable resulting in continual desyncs, restructures our public includes to match the directory structure of source, allows autogen artefacts to be included by external gems, allowing for external multiplayer components to interact with multiplayer gem components with no extra code

This commit is contained in:
karlberg
2021-05-14 14:24:33 -07:00
parent 795aa114e6
commit 5acdc40595
73 changed files with 348 additions and 267 deletions
@@ -0,0 +1,36 @@
/*
* 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 <Multiplayer/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 GetNetComponentId() const = 0;
virtual bool Serialize(AzNetworking::ISerializer& serializer) = 0;
};
using MultiplayerComponentInputVector = AZStd::vector<AZStd::unique_ptr<IMultiplayerComponentInput>>;
}
@@ -0,0 +1,83 @@
/*
* 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 <Multiplayer/NetworkEntity/NetworkEntityHandle.h>
#include <Multiplayer/NetworkInput/IMultiplayerComponentInput.h>
#include <Multiplayer/NetworkTime/INetworkTime.h>
#include <AzCore/RTTI/TypeSafeIntegral.h>
namespace Multiplayer
{
// Forwards
class NetBindComponent;
//! @class NetworkInput
//! @brief A single networked client input command.
class NetworkInput final
{
public:
//! Intentionally restrict instancing of these objects to associated containers classes only
//! This is a mechanism used to restrict calling autonomous client predicted setter functions to the ProcessInput call chain only
friend class NetworkInputArray;
friend class NetworkInputMigrationVector;
friend class NetworkInputHistory;
friend class NetworkInputChild;
NetworkInput(const NetworkInput&);
NetworkInput& operator= (const NetworkInput&);
void SetClientInputId(ClientInputId inputId);
ClientInputId GetClientInputId() const;
ClientInputId& ModifyClientInputId();
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);
bool Serialize(AzNetworking::ISerializer& serializer);
const IMultiplayerComponentInput* FindComponentInput(NetComponentId componentId) const;
IMultiplayerComponentInput* FindComponentInput(NetComponentId componentId);
template <class InputType>
const InputType* FindComponentInput() const
{
return static_cast<const InputType*>(FindComponentInput(InputType::s_netComponentId));
}
template <typename InputType>
InputType* FindComponentInput()
{
return static_cast<InputType*>(FindComponentInput(InputType::s_netComponentId));
}
private:
//! Only associated containers can instance; see above comments.
NetworkInput() = default;
void CopyInternal(const NetworkInput& rhs);
MultiplayerComponentInputVector m_componentInputs;
ClientInputId m_inputId = ClientInputId{ 0 };
HostFrameId m_hostFrameId = InvalidHostFrameId;
AZ::TimeMs m_hostTimeMs = AZ::TimeMs{ 0 };
ConstNetworkEntityHandle m_owner;
bool m_wasAttached = false;
};
}