Skip to content

Commit

Permalink
Re-use RobustTree pool
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth committed Nov 19, 2023
1 parent abad5a1 commit b6a9fe5
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Robust.Server/GameStates/PvsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ private readonly ObjectPool<Dictionary<NetEntity, PvsEntityVisibility>> _visSetP
private readonly ObjectPool<HashSet<EntityUid>> _uidSetPool
= new DefaultObjectPool<HashSet<EntityUid>>(new SetPolicy<EntityUid>(), MaxVisPoolSize);

private readonly ObjectPool<HashSet<NetEntity>> _nentPool =
new DefaultObjectPool<HashSet<NetEntity>>(new SetPolicy<NetEntity>(), MaxVisPoolSize * 8);

private readonly ObjectPool<Stack<NetEntity>> _stackPool
= new DefaultObjectPool<Stack<NetEntity>>(
new StackPolicy<NetEntity>(), MaxVisPoolSize);
Expand All @@ -95,8 +98,7 @@ private readonly ObjectPool<Stack<NetEntity>> _stackPool
private readonly ObjectPool<HashSet<int>> _playerChunkPool =
new DefaultObjectPool<HashSet<int>>(new SetPolicy<int>(), MaxVisPoolSize);

private readonly ObjectPool<RobustTree<NetEntity>> _treePool =
new DefaultObjectPool<RobustTree<NetEntity>>(new TreePolicy<NetEntity>(), MaxVisPoolSize);
private ObjectPool<RobustTree<NetEntity>> _treePool = default!;

private readonly ObjectPool<Dictionary<MapChunkLocation, int>> _mapChunkPool =
new DefaultObjectPool<Dictionary<MapChunkLocation, int>>(
Expand Down Expand Up @@ -130,6 +132,8 @@ public override void Initialize()
{
base.Initialize();

_treePool = new DefaultObjectPool<RobustTree<NetEntity>>(new TreePolicy<NetEntity>(_nentPool), MaxVisPoolSize);

_eyeQuery = GetEntityQuery<EyeComponent>();
_metaQuery = GetEntityQuery<MetaDataComponent>();
_xformQuery = GetEntityQuery<TransformComponent>();
Expand Down Expand Up @@ -1371,10 +1375,16 @@ private EntityUid[] GetSessionViewers(ICommonSession session)

public sealed class TreePolicy<T> : PooledObjectPolicy<RobustTree<T>> where T : notnull
{
private readonly ObjectPool<HashSet<T>> _pool;

public TreePolicy(ObjectPool<HashSet<T>> pool)
{
_pool = pool;
}

public override RobustTree<T> Create()
{
var pool = new DefaultObjectPool<HashSet<T>>(new SetPolicy<T>(), MaxVisPoolSize);
return new RobustTree<T>(pool);
return new RobustTree<T>(_pool);
}

public override bool Return(RobustTree<T> obj)
Expand Down

0 comments on commit b6a9fe5

Please sign in to comment.