Fix networked objects dirtying for replication

This commit is contained in:
Wojtek Figat
2024-03-29 13:02:23 +01:00
parent 5525e895cf
commit 09f5ac0ed6
2 changed files with 14 additions and 7 deletions

View File

@@ -167,7 +167,7 @@ void NetworkReplicationGridNode::AddObject(NetworkReplicationHierarchyObject obj
cell->MinCullDistance = obj.CullDistance;
}
cell->Node->AddObject(obj);
_objectToCell[obj.Object] = coord;
_objectToCell[obj.Object.Get()] = coord;
// Cache minimum culling distance for a whole cell to skip it at once
cell->MinCullDistance = Math::Min(cell->MinCullDistance, obj.CullDistance);
@@ -176,12 +176,10 @@ void NetworkReplicationGridNode::AddObject(NetworkReplicationHierarchyObject obj
bool NetworkReplicationGridNode::RemoveObject(ScriptingObject* obj)
{
Int3 coord;
if (!_objectToCell.TryGet(obj, coord))
{
return false;
}
if (_children[coord].Node->RemoveObject(obj))
{
_objectToCell.Remove(obj);
@@ -195,12 +193,10 @@ bool NetworkReplicationGridNode::RemoveObject(ScriptingObject* obj)
bool NetworkReplicationGridNode::GetObject(ScriptingObject* obj, NetworkReplicationHierarchyObject& result)
{
Int3 coord;
if (!_objectToCell.TryGet(obj, coord))
{
return false;
}
if (_children[coord].Node->GetObject(obj, result))
{
return true;
@@ -208,6 +204,16 @@ bool NetworkReplicationGridNode::GetObject(ScriptingObject* obj, NetworkReplicat
return false;
}
bool NetworkReplicationGridNode::DirtyObject(ScriptingObject* obj)
{
Int3 coord;
if (_objectToCell.TryGet(obj, coord))
{
return _children[coord].Node->DirtyObject(obj);
}
return NetworkReplicationNode::DirtyObject(obj);
}
void NetworkReplicationGridNode::Update(NetworkReplicationHierarchyUpdateResult* result)
{
CHECK(result);

View File

@@ -20,11 +20,11 @@ API_STRUCT(NoDefault, Namespace = "FlaxEngine.Networking") struct FLAXENGINE_API
// The object to replicate.
API_FIELD() ScriptingObjectReference<ScriptingObject> Object;
// The target amount of the replication updates per second (frequency of the replication). Constrained by NetworkManager::NetworkFPS. Use 0 for 'always relevant' object and less than 0 (eg. -1) for 'never relevant' objects that would only get synched on client join once.
// The target amount of the replication updates per second (frequency of the replication). Constrained by NetworkManager::NetworkFPS. Use 0 for 'always relevant' object and less than 0 (eg. -1) for 'never relevant' objects that would only get synced on client join once (or upon DirtyObject).
API_FIELD() float ReplicationFPS = 60;
// The minimum distance from the player to the object at which it can process replication. For example, players further away won't receive object data. Use 0 if unused.
API_FIELD() float CullDistance = 15000;
// Runtime value for update frames left for the next replication of this object. Matches NetworkManager::NetworkFPS calculated from ReplicationFPS.
// Runtime value for update frames left for the next replication of this object. Matches NetworkManager::NetworkFPS calculated from ReplicationFPS. Set to 1 if ReplicationFPS less than 0 to indicate dirty object.
API_FIELD(Attributes="HideInEditor") uint16 ReplicationUpdatesLeft = 0;
FORCE_INLINE NetworkReplicationHierarchyObject(const ScriptingObjectReference<ScriptingObject>& obj)
@@ -257,6 +257,7 @@ public:
void AddObject(NetworkReplicationHierarchyObject obj) override;
bool RemoveObject(ScriptingObject* obj) override;
bool GetObject(ScriptingObject* obj, NetworkReplicationHierarchyObject& result) override;
bool DirtyObject(ScriptingObject* obj) override;
void Update(NetworkReplicationHierarchyUpdateResult* result) override;
};