Merging latest origin/main
This commit is contained in:
@@ -37,7 +37,7 @@ namespace Multiplayer
|
||||
|
||||
void OnRotationChangedEvent(const AZ::Quaternion& rotation);
|
||||
void OnTranslationChangedEvent(const AZ::Vector3& translation);
|
||||
void OnScaleChangedEvent(const AZ::Vector3& scale);
|
||||
void OnScaleChangedEvent(float scale);
|
||||
void OnResetCountChangedEvent();
|
||||
|
||||
AZ::Transform m_previousTransform = AZ::Transform::CreateIdentity();
|
||||
@@ -45,7 +45,7 @@ namespace Multiplayer
|
||||
|
||||
AZ::Event<AZ::Quaternion>::Handler m_rotationEventHandler;
|
||||
AZ::Event<AZ::Vector3>::Handler m_translationEventHandler;
|
||||
AZ::Event<AZ::Vector3>::Handler m_scaleEventHandler;
|
||||
AZ::Event<float>::Handler m_scaleEventHandler;
|
||||
AZ::Event<uint8_t>::Handler m_resetCountEventHandler;
|
||||
|
||||
EntityPreRenderEvent::Handler m_entityPreRenderEventHandler;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 <AzCore/std/containers/array.h>
|
||||
#include <AzNetworking/DataStructures/IBitset.h>
|
||||
#include <AzNetworking/Serialization/ISerializer.h>
|
||||
|
||||
#include <Multiplayer/NetworkTime/RewindableObject.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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 <AzCore/std/containers/array.h>
|
||||
#include <AzNetworking/DataStructures/IBitset.h>
|
||||
#include <AzNetworking/Serialization/ISerializer.h>
|
||||
|
||||
#include <Multiplayer/NetworkTime/RewindableObject.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
//! @class RewindableFixedVector
|
||||
//! @brief Data structure that has a compile-time upper bound, provides vector semantics and supports network serialization
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
class RewindableFixedVector
|
||||
{
|
||||
public:
|
||||
//! Default constructor
|
||||
constexpr RewindableFixedVector() = default;
|
||||
|
||||
//! Construct and initialize buffer to the provided value
|
||||
//! @param initialValue initial value to set the internal buffer to
|
||||
//! @param count initial value to reserve in the vector
|
||||
constexpr RewindableFixedVector(const TYPE& initialValue, uint32_t count);
|
||||
|
||||
//! Destructor
|
||||
~RewindableFixedVector();
|
||||
|
||||
//! Serialization method for fixed vector 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 fixed vector 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);
|
||||
|
||||
//! Copies elements from the buffer pointed to by Buffer to this FixedSizeVector instance, vector size will be set to BufferSize
|
||||
//! @param buffer pointer to the buffer to copy
|
||||
//! @param bufferSize number of elements in the buffer to copy
|
||||
//! @return bool true on success, false if the input data was too large to fit in the vector
|
||||
constexpr bool copy_values(const TYPE* buffer, uint32_t bufferSize);
|
||||
|
||||
//! Copy buffer from the provided vector
|
||||
//! @param RHS instance to copy from
|
||||
constexpr RewindableFixedVector<TYPE, SIZE>& operator=(const RewindableFixedVector<TYPE, SIZE>& rhs);
|
||||
|
||||
//! Equality operator, returns true if the current instance is equal to RHS
|
||||
//! @param rhs the FixedSizeVector instance to test for equality against
|
||||
//! @return bool true if equal, false if not
|
||||
constexpr bool operator ==(const RewindableFixedVector<TYPE, SIZE>& rhs) const;
|
||||
|
||||
//! Inequality operator, returns true if the current instance is not equal to RHS
|
||||
//! @param rhs the FixedSizeVector instance to test for inequality against
|
||||
//! @return bool false if equal, true if not equal
|
||||
constexpr bool operator !=(const RewindableFixedVector<TYPE, SIZE>& rhs) const;
|
||||
|
||||
//! Resizes the vector to the requested number of elements, initializing new elements if necessary
|
||||
//! @param count the number of elements to size the vector to
|
||||
//! @return bool true on success
|
||||
constexpr bool resize(uint32_t count);
|
||||
|
||||
//! Resizes the vector to the requested number of elements, without initialization
|
||||
//! @param count the number of elements to size the vector to
|
||||
//! @return bool true on success
|
||||
constexpr bool resize_no_construct(uint32_t count);
|
||||
|
||||
//! Resets the vector, returning it to size 0
|
||||
constexpr void clear();
|
||||
|
||||
//! Const element access
|
||||
//! @param Index index of the element to return
|
||||
//! @return const reference to the requested element
|
||||
constexpr const TYPE& operator[](uint32_t index) const;
|
||||
|
||||
//! Non-const element access
|
||||
//! @param Index index of the element to return
|
||||
//! @return non-const reference to the requested element
|
||||
constexpr TYPE& operator[](uint32_t index);
|
||||
|
||||
//! Pushes a new element to the back of the vector
|
||||
//! @param Value value to append to the back of this vector
|
||||
//! @return boolean true on success, false if the vector was full
|
||||
constexpr bool push_back(const TYPE& value);
|
||||
|
||||
//! Pops the last element off the vector, decreasing the vector's size by one
|
||||
//! @return bool true on success, false if the vector was empty
|
||||
constexpr bool pop_back();
|
||||
|
||||
//! Returns if the vector is empty
|
||||
//! @return bool true on empty, false if the vector contains valid elements
|
||||
constexpr bool empty() const;
|
||||
|
||||
//! Gets the last element of the vector
|
||||
constexpr const TYPE& back() const;
|
||||
|
||||
//! Gets the size of the vector
|
||||
constexpr uint32_t size() const;
|
||||
|
||||
typedef const RewindableObject<TYPE, Multiplayer::RewindHistorySize>* const_iterator;
|
||||
const_iterator begin() const { return m_container.cbegin(); }
|
||||
const_iterator end() const { return m_container.cbegin() + aznumeric_cast<size_t>(size()); }
|
||||
typedef RewindableObject<TYPE, Multiplayer::RewindHistorySize>* iterator;
|
||||
constexpr iterator begin() { return m_container.begin(); }
|
||||
constexpr iterator end() { return m_container.begin() + aznumeric_cast<size_t>(size()); }
|
||||
|
||||
private:
|
||||
AZStd::array<RewindableObject<TYPE, Multiplayer::RewindHistorySize>, SIZE> m_container;
|
||||
// Synchronized value for vector size, prefer using size() locally which checks m_container.size()
|
||||
RewindableObject<uint32_t, Multiplayer::RewindHistorySize> m_rewindableSize;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Multiplayer/NetworkTime/RewindableFixedVector.inl>
|
||||
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* 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>
|
||||
constexpr RewindableFixedVector<TYPE, SIZE>::RewindableFixedVector(const TYPE& initialValue, uint32_t count)
|
||||
{
|
||||
m_container.fill(initialValue);
|
||||
m_rewindableSize = count;
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
RewindableFixedVector<TYPE, SIZE>::~RewindableFixedVector()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
bool RewindableFixedVector<TYPE, SIZE>::Serialize(AzNetworking::ISerializer& serializer)
|
||||
{
|
||||
if(!m_rewindableSize.Serialize(serializer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t idx = 0; idx < size(); ++idx)
|
||||
{
|
||||
if(!m_container[idx].Serialize(serializer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return serializer.IsValid();
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
bool RewindableFixedVector<TYPE, SIZE>::Serialize(AzNetworking::ISerializer& serializer, AzNetworking::IBitset& deltaRecord)
|
||||
{
|
||||
if (deltaRecord.GetBit(SIZE))
|
||||
{
|
||||
const uint32_t origSize = m_rewindableSize;
|
||||
if(!m_rewindableSize.Serialize(serializer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject) && origSize == m_rewindableSize)
|
||||
{
|
||||
deltaRecord.SetBit(SIZE, false);
|
||||
}
|
||||
}
|
||||
for (uint32_t idx = 0; idx < size(); ++idx)
|
||||
{
|
||||
if (deltaRecord.GetBit(idx))
|
||||
{
|
||||
serializer.ClearTrackedChangesFlag();
|
||||
if(!m_container[idx].Serialize(serializer))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject) && !serializer.GetTrackedChangesFlag())
|
||||
{
|
||||
deltaRecord.SetBit(idx, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return serializer.IsValid();
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr bool RewindableFixedVector<TYPE, SIZE>::copy_values(const TYPE* buffer, uint32_t bufferSize)
|
||||
{
|
||||
if (!resize(bufferSize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t idx = 0; idx < bufferSize; ++idx)
|
||||
{
|
||||
m_container[idx] = buffer[idx];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr RewindableFixedVector<TYPE, SIZE>& RewindableFixedVector<TYPE, SIZE>::operator=(const RewindableFixedVector<TYPE, SIZE>& rhs)
|
||||
{
|
||||
resize(rhs.size());
|
||||
for (uint32_t idx = 0; idx < size(); ++idx)
|
||||
{
|
||||
m_container[idx] = rhs.m_container[idx].Get();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr bool RewindableFixedVector<TYPE, SIZE>::operator ==(const RewindableFixedVector<TYPE, SIZE>& rhs) const
|
||||
{
|
||||
return m_container == rhs.m_container && m_rewindableSize == rhs.m_rewindableSize;
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr bool RewindableFixedVector<TYPE, SIZE>::operator !=(const RewindableFixedVector<TYPE, SIZE>& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr bool RewindableFixedVector<TYPE, SIZE>::resize(uint32_t count)
|
||||
{
|
||||
if (count > SIZE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count == size())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (count > size())
|
||||
{
|
||||
for (uint32_t idx = size(); idx < count; ++idx)
|
||||
{
|
||||
m_container[idx] = TYPE();
|
||||
}
|
||||
}
|
||||
m_rewindableSize = count;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr bool RewindableFixedVector<TYPE, SIZE>::resize_no_construct(uint32_t count)
|
||||
{
|
||||
if (count > SIZE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_rewindableSize = count;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr void RewindableFixedVector<TYPE, SIZE>::clear()
|
||||
{
|
||||
for (uint32_t idx = 0; idx < SIZE; ++idx)
|
||||
{
|
||||
m_container[idx] = TYPE();
|
||||
}
|
||||
m_rewindableSize = 0;
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr const TYPE& RewindableFixedVector<TYPE, SIZE>::operator[](uint32_t index) const
|
||||
{
|
||||
AZ_Assert(index < size(), "Out of bounds access (requested %u, reserved %u)", index, size());
|
||||
return m_container[index].Get();
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr TYPE& RewindableFixedVector<TYPE, SIZE>::operator[](uint32_t index)
|
||||
{
|
||||
AZ_Assert(index < size(), "Out of bounds access (requested %u, reserved %u)", index, size());
|
||||
return m_container[index].Modify();
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr bool RewindableFixedVector<TYPE, SIZE>::push_back(const TYPE& value)
|
||||
{
|
||||
if (size() < SIZE)
|
||||
{
|
||||
m_container[m_rewindableSize] = value;
|
||||
m_rewindableSize = m_rewindableSize + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr bool RewindableFixedVector<TYPE, SIZE>::pop_back()
|
||||
{
|
||||
if (size() > 0)
|
||||
{
|
||||
m_rewindableSize = m_rewindableSize - 1;
|
||||
m_container[m_rewindableSize] = TYPE();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr bool RewindableFixedVector<TYPE, SIZE>::empty() const
|
||||
{
|
||||
return m_rewindableSize.Get() == 0;
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr const TYPE& RewindableFixedVector<TYPE, SIZE>::back() const
|
||||
{
|
||||
AZ_Assert(size() > 0, "Attempted to get back element of an empty RewindableFixedVector");
|
||||
return m_container[m_rewindableSize - 1].Get();
|
||||
}
|
||||
|
||||
template <typename TYPE, uint32_t SIZE>
|
||||
constexpr uint32_t RewindableFixedVector<TYPE, SIZE>::size() const
|
||||
{
|
||||
return m_rewindableSize;
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace Multiplayer
|
||||
RewindableObject() = default;
|
||||
|
||||
//! Constructor.
|
||||
//! @param connectionId the connectionId of the connection that owns the object.
|
||||
//! @param value base type value to construct from
|
||||
RewindableObject(const BASE_TYPE& value);
|
||||
|
||||
//! Copy construct from underlying base type.
|
||||
|
||||
Reference in New Issue
Block a user