Merge branch 'replicationnode' of https://github.com/Withaust/FlaxEngine into Withaust-replicationnode
This commit is contained in:
@@ -63,6 +63,17 @@ bool NetworkReplicationNode::RemoveObject(ScriptingObject* obj)
|
||||
return !Objects.Remove(obj);
|
||||
}
|
||||
|
||||
bool NetworkReplicationNode::GetObject(ScriptingObject* obj, NetworkReplicationHierarchyObject& result)
|
||||
{
|
||||
const int32 index = Objects.Find(obj);
|
||||
if (index != -1)
|
||||
{
|
||||
result = Objects[index];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetworkReplicationNode::DirtyObject(ScriptingObject* obj)
|
||||
{
|
||||
const int32 index = Objects.Find(obj);
|
||||
@@ -156,6 +167,7 @@ void NetworkReplicationGridNode::AddObject(NetworkReplicationHierarchyObject obj
|
||||
cell->MinCullDistance = obj.CullDistance;
|
||||
}
|
||||
cell->Node->AddObject(obj);
|
||||
_objectToCell[obj.Object] = coord;
|
||||
|
||||
// Cache minimum culling distance for a whole cell to skip it at once
|
||||
cell->MinCullDistance = Math::Min(cell->MinCullDistance, obj.CullDistance);
|
||||
@@ -163,14 +175,35 @@ void NetworkReplicationGridNode::AddObject(NetworkReplicationHierarchyObject obj
|
||||
|
||||
bool NetworkReplicationGridNode::RemoveObject(ScriptingObject* obj)
|
||||
{
|
||||
for (const auto& e : _children)
|
||||
Int3 coord;
|
||||
|
||||
if (!_objectToCell.TryGet(obj, coord))
|
||||
{
|
||||
if (e.Value.Node->RemoveObject(obj))
|
||||
{
|
||||
// TODO: remove empty cells?
|
||||
// TODO: update MinCullDistance for cell?
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_children[coord].Node->RemoveObject(obj))
|
||||
{
|
||||
_objectToCell.Remove(obj);
|
||||
// TODO: remove empty cells?
|
||||
// TODO: update MinCullDistance for cell?
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -200,6 +200,14 @@ API_CLASS(Abstract, Namespace = "FlaxEngine.Networking") class FLAXENGINE_API Ne
|
||||
/// <returns>True on successful removal, otherwise false.</returns>
|
||||
API_FUNCTION() virtual bool RemoveObject(ScriptingObject* obj);
|
||||
|
||||
/// <summary>
|
||||
/// Gets object from the hierarchy.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to get.</param>
|
||||
/// <param name="result">The hierarchy object to retrieve.</param>
|
||||
/// <returns>True on successful retrieval, otherwise false.</returns>
|
||||
API_FUNCTION() virtual bool GetObject(ScriptingObject* obj, NetworkReplicationHierarchyObject& result);
|
||||
|
||||
/// <summary>
|
||||
/// Force replicates the object during the next update. Resets any internal tracking state to force the synchronization.
|
||||
/// </summary>
|
||||
@@ -238,6 +246,7 @@ private:
|
||||
};
|
||||
|
||||
Dictionary<Int3, Cell> _children;
|
||||
Dictionary<ScriptingObject*, Int3> _objectToCell;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
@@ -247,6 +256,7 @@ public:
|
||||
|
||||
void AddObject(NetworkReplicationHierarchyObject obj) override;
|
||||
bool RemoveObject(ScriptingObject* obj) override;
|
||||
bool GetObject(ScriptingObject* obj, NetworkReplicationHierarchyObject& result) override;
|
||||
void Update(NetworkReplicationHierarchyUpdateResult* result) override;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user