Some cleanup to better support backward reconciliation as well as dynamic player spawning on connect
This commit is contained in:
@@ -11,19 +11,12 @@
|
||||
*/
|
||||
|
||||
#include <Source/NetworkTime/NetworkTime.h>
|
||||
#include <Source/Components/NetBindComponent.h>
|
||||
#include <Include/IMultiplayer.h>
|
||||
#include <AzFramework/Visibility/IVisibilitySystem.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
NetworkTime::NetworkTime()
|
||||
{
|
||||
AZ::Interface<INetworkTime>::Register(this);
|
||||
}
|
||||
|
||||
NetworkTime::~NetworkTime()
|
||||
{
|
||||
AZ::Interface<INetworkTime>::Unregister(this);
|
||||
}
|
||||
|
||||
bool NetworkTime::IsTimeRewound() const
|
||||
{
|
||||
return m_rewindingConnectionId != AzNetworking::InvalidConnectionId;
|
||||
@@ -51,11 +44,6 @@ namespace Multiplayer
|
||||
return m_hostTimeMs;
|
||||
}
|
||||
|
||||
void NetworkTime::SyncRewindableEntityState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AzNetworking::ConnectionId NetworkTime::GetRewindingConnectionId() const
|
||||
{
|
||||
return m_rewindingConnectionId;
|
||||
@@ -72,4 +60,38 @@ namespace Multiplayer
|
||||
m_hostTimeMs = timeMs;
|
||||
m_rewindingConnectionId = rewindConnectionId;
|
||||
}
|
||||
|
||||
void NetworkTime::SyncEntitiesToRewindState(const AZ::Aabb& rewindVolume)
|
||||
{
|
||||
// TODO: extrude rewind volume for initial gather
|
||||
AZStd::vector<AzFramework::VisibilityEntry*> gatheredEntries;
|
||||
AZ::Interface<AzFramework::IVisibilitySystem>::Get()->GetDefaultVisibilityScene()->Enumerate(rewindVolume, [&gatheredEntries](const AzFramework::IVisibilityScene::NodeData& nodeData)
|
||||
{
|
||||
gatheredEntries.reserve(gatheredEntries.size() + nodeData.m_entries.size());
|
||||
for (AzFramework::VisibilityEntry* visEntry : nodeData.m_entries)
|
||||
{
|
||||
if (visEntry->m_typeFlags & AzFramework::VisibilityEntry::TypeFlags::TYPE_Entity)
|
||||
{
|
||||
// TODO: offset aabb for exact rewound position and check against the non-extruded rewind volume
|
||||
gatheredEntries.push_back(visEntry);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (AzFramework::VisibilityEntry* visEntry : gatheredEntries)
|
||||
{
|
||||
AZ::Entity* entity = static_cast<AZ::Entity*>(visEntry->m_userData);
|
||||
[[maybe_unused]] NetBindComponent* entryNetBindComponent = entity->template FindComponent<NetBindComponent>();
|
||||
if (entryNetBindComponent != nullptr)
|
||||
{
|
||||
// TODO: invoke the sync to rewind event on the netBindComponent and add the entity to the rewound entity set
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkTime::ClearRewoundEntities()
|
||||
{
|
||||
AZ_Assert(!IsTimeRewound(), "Cannot clear rewound entity state while still within scoped rewind");
|
||||
// TODO: iterate all rewound entities, signal them to sync rewind state, and clear the rewound entity set
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace Multiplayer
|
||||
: public INetworkTime
|
||||
{
|
||||
public:
|
||||
NetworkTime();
|
||||
virtual ~NetworkTime();
|
||||
NetworkTime() = default;
|
||||
virtual ~NetworkTime() = default;
|
||||
|
||||
//! INetworkTime overrides.
|
||||
//! @{
|
||||
@@ -33,10 +33,11 @@ namespace Multiplayer
|
||||
HostFrameId GetUnalteredHostFrameId() const override;
|
||||
void IncrementHostFrameId() override;
|
||||
AZ::TimeMs GetHostTimeMs() const override;
|
||||
void SyncRewindableEntityState() override;
|
||||
AzNetworking::ConnectionId GetRewindingConnectionId() const override;
|
||||
HostFrameId GetHostFrameIdForRewindingConnection(AzNetworking::ConnectionId rewindConnectionId) const override;
|
||||
void AlterTime(HostFrameId frameId, AZ::TimeMs timeMs, AzNetworking::ConnectionId rewindConnectionId) override;
|
||||
void SyncEntitiesToRewindState(const AZ::Aabb& rewindVolume) override;
|
||||
void ClearRewoundEntities() override;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Multiplayer
|
||||
template <typename BASE_TYPE, AZStd::size_t REWIND_SIZE>
|
||||
inline RewindableObject<BASE_TYPE, REWIND_SIZE> &RewindableObject<BASE_TYPE, REWIND_SIZE>::operator =(const RewindableObject<BASE_TYPE, REWIND_SIZE>& rhs)
|
||||
{
|
||||
INetworkTime* networkTime = AZ::Interface<INetworkTime>::Get();
|
||||
INetworkTime* networkTime = GetNetworkTime();
|
||||
SetValueForTime(rhs.GetValueForTime(networkTime->GetHostFrameId()), GetCurrentTimeForProperty());
|
||||
return *this;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ namespace Multiplayer
|
||||
template <typename BASE_TYPE, AZStd::size_t REWIND_SIZE>
|
||||
inline HostFrameId RewindableObject<BASE_TYPE, REWIND_SIZE>::GetCurrentTimeForProperty() const
|
||||
{
|
||||
INetworkTime* networkTime = AZ::Interface<INetworkTime>::Get();
|
||||
INetworkTime* networkTime = GetNetworkTime();
|
||||
return networkTime->GetHostFrameIdForRewindingConnection(m_owningConnectionId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user