Add RewindableArray and cleanup a bit more of vector
parent
50b9233552
commit
d2797c0d15
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* 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/NetworkTime/INetworkTime.h>
|
||||||
|
#include <Multiplayer/NetworkTime/RewindableObject.h>
|
||||||
|
#include <AzNetworking/Serialization/ISerializer.h>
|
||||||
|
#include <AzNetworking/ConnectionLayer/IConnection.h>
|
||||||
|
#include <AzNetworking/Utilities/NetworkCommon.h>
|
||||||
|
#include <AzCore/std/containers/array.h>
|
||||||
|
#include <AzCore/std/string/string.h>
|
||||||
|
#include <AzCore/Console/ILogger.h>
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
//! @class RewindableArray
|
||||||
|
//! @brief Data structure that has a compile-time upper bound, provides array semantics and supports network serialization
|
||||||
|
template <typename TYPE, uint32_t SIZE>
|
||||||
|
class RewindableArray
|
||||||
|
: public AZStd::array<RewindableObject<TYPE, Multiplayer::RewindHistorySize>, SIZE>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Serialization method for array contained rewindable objects
|
||||||
|
//! @param serializer ISerializer instance to use for serialization
|
||||||
|
//! @return bool true for success, false for serialization failure
|
||||||
|
bool Serialize(AzNetworking::ISerializer& serializer);
|
||||||
|
|
||||||
|
//! Serialization method for array contained rewindable objects
|
||||||
|
//! @param serializer ISerializer instance to use for serialization
|
||||||
|
//! @param deltaRecord Bitset delta record used to detect state change during reconciliation
|
||||||
|
//! @return bool true for success, false for serialization failure
|
||||||
|
bool Serialize(AzNetworking::ISerializer& serializer, AzNetworking::IBitset &deltaRecord);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Multiplayer/NetworkTime/RewindableArray.inl>
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
namespace Multiplayer
|
||||||
|
{
|
||||||
|
template <typename TYPE, uint32_t SIZE>
|
||||||
|
bool RewindableArray<TYPE, SIZE>::Serialize(AzNetworking::ISerializer& serializer)
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < size(); ++i)
|
||||||
|
{
|
||||||
|
if(!this[i].Serialize(serializer))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return serializer.IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename TYPE, uint32_t SIZE>
|
||||||
|
bool RewindableArray<TYPE, SIZE>::Serialize(AzNetworking::ISerializer& serializer, AzNetworking::IBitset& deltaRecord)
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < size(); ++i)
|
||||||
|
{
|
||||||
|
if (deltaRecord.GetBit(i))
|
||||||
|
{
|
||||||
|
serializer.ClearTrackedChangesFlag();
|
||||||
|
if(!this[i].Serialize(serializer))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject) && !serializer.GetTrackedChangesFlag())
|
||||||
|
{
|
||||||
|
deltaRecord.SetBit(i, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return serializer.IsValid();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue