Adding rewindable mechanisms to support interpolation

Signed-off-by: puvvadar <puvvadar@amazon.com>
This commit is contained in:
puvvadar
2021-07-22 13:49:05 -07:00
parent 69d5f64bb7
commit b55bad496d
10 changed files with 57 additions and 19 deletions
@@ -186,18 +186,20 @@ namespace Multiplayer
class ScopedAlterTime final
{
public:
inline ScopedAlterTime(HostFrameId frameId, AZ::TimeMs timeMs, AzNetworking::ConnectionId connectionId)
inline ScopedAlterTime(HostFrameId frameId, AZ::TimeMs timeMs, float blendFactor, AzNetworking::ConnectionId connectionId)
{
INetworkTime* time = GetNetworkTime();
m_previousHostFrameId = time->GetHostFrameId();
m_previousHostTimeMs = time->GetHostTimeMs();
m_previousRewindConnectionId = time->GetRewindingConnectionId();
time->AlterTime(frameId, timeMs, connectionId);
time->AlterBlendFactor(blendFactor);
}
inline ~ScopedAlterTime()
{
INetworkTime* time = GetNetworkTime();
time->AlterTime(m_previousHostFrameId, m_previousHostTimeMs, m_previousRewindConnectionId);
time->AlterBlendFactor(DefaultBlendFactor);
}
private:
HostFrameId m_previousHostFrameId = InvalidHostFrameId;
@@ -21,6 +21,9 @@ namespace Multiplayer
//! The default number of rewindable samples for us to store.
static constexpr uint32_t RewindHistorySize = 128;
//! The default blend factor for ScopedAlterTime
static constexpr float DefaultBlendFactor = 1.f;
AZ_TYPE_SAFE_INTEGRAL(HostId, uint32_t);
static constexpr HostId InvalidHostId = static_cast<HostId>(-1);
@@ -42,6 +42,10 @@ namespace Multiplayer
//! @return the hosts current timeMs
virtual AZ::TimeMs GetHostTimeMs() const = 0;
//! Retrieves the hosts current blend factor (may be rewound on the server during backward reconciliation).
//! @return the hosts current blend factor
virtual float GetHostBlendFactor() const = 0;
//! Get the controlling connection that may be currently altering global game time.
//! Note this abstraction is required at a relatively high level to allow for 'don't rewind the shooter' semantics
//! @return the ConnectionId of the connection requesting the rewind operation
@@ -59,6 +63,10 @@ namespace Multiplayer
//! @param rewindConnectionId the rewinding ConnectionId
virtual void AlterTime(HostFrameId frameId, AZ::TimeMs timeMs, AzNetworking::ConnectionId rewindConnectionId) = 0;
//! Alters the current Host blend factor. Used to drive interpolation in rewound states.
//! @param blendFactor the blend factor to use
virtual void AlterBlendFactor(float blendFactor) = 0;
//! Syncs all entities contained within a volume to the current rewind state.
//! @param rewindVolume the volume to rewind entities within (needed for physics entities)
virtual void SyncEntitiesToRewindState(const AZ::Aabb& rewindVolume) = 0;
@@ -59,6 +59,10 @@ namespace Multiplayer
//! @return value in const base type form
const BASE_TYPE& Get() const;
//! Const base type retriever for one host frame behind Get().
//! @return value in const base type form
const BASE_TYPE& GetPrevious() const;
//! Base type retriever.
//! @return value in base type form
BASE_TYPE& Modify();
@@ -65,6 +65,12 @@ namespace Multiplayer
return GetValueForTime(GetCurrentTimeForProperty());
}
template <typename BASE_TYPE, AZStd::size_t REWIND_SIZE>
inline const BASE_TYPE& RewindableObject<BASE_TYPE, REWIND_SIZE>::GetPrevious() const
{
return GetValueForTime(GetCurrentTimeForProperty() - HostFrameId(1));
}
template <typename BASE_TYPE, AZStd::size_t REWIND_SIZE>
inline BASE_TYPE& RewindableObject<BASE_TYPE, REWIND_SIZE>::Modify()
{