Content update for NetEntities (#18935)
This commit is contained in:
@@ -20,11 +20,14 @@ public sealed class ChunkingSystem : EntitySystem
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
private Box2 _baseViewBounds;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
_configurationManager.OnValueChanged(CVars.NetMaxUpdateRange, OnPvsRangeChanged, true);
|
||||
}
|
||||
|
||||
@@ -36,16 +39,15 @@ public sealed class ChunkingSystem : EntitySystem
|
||||
|
||||
private void OnPvsRangeChanged(float value) => _baseViewBounds = Box2.UnitCentered.Scale(value);
|
||||
|
||||
public Dictionary<EntityUid, HashSet<Vector2i>> GetChunksForSession(
|
||||
public Dictionary<NetEntity, HashSet<Vector2i>> GetChunksForSession(
|
||||
IPlayerSession session,
|
||||
int chunkSize,
|
||||
EntityQuery<TransformComponent> xformQuery,
|
||||
ObjectPool<HashSet<Vector2i>> indexPool,
|
||||
ObjectPool<Dictionary<EntityUid, HashSet<Vector2i>>> viewerPool,
|
||||
ObjectPool<Dictionary<NetEntity, HashSet<Vector2i>>> viewerPool,
|
||||
float? viewEnlargement = null)
|
||||
{
|
||||
var viewers = GetSessionViewers(session);
|
||||
var chunks = GetChunksForViewers(viewers, chunkSize, indexPool, viewerPool, viewEnlargement ?? chunkSize, xformQuery);
|
||||
var chunks = GetChunksForViewers(viewers, chunkSize, indexPool, viewerPool, viewEnlargement ?? chunkSize);
|
||||
return chunks;
|
||||
}
|
||||
|
||||
@@ -65,37 +67,38 @@ public sealed class ChunkingSystem : EntitySystem
|
||||
return viewers;
|
||||
}
|
||||
|
||||
private Dictionary<EntityUid, HashSet<Vector2i>> GetChunksForViewers(
|
||||
private Dictionary<NetEntity, HashSet<Vector2i>> GetChunksForViewers(
|
||||
HashSet<EntityUid> viewers,
|
||||
int chunkSize,
|
||||
ObjectPool<HashSet<Vector2i>> indexPool,
|
||||
ObjectPool<Dictionary<EntityUid, HashSet<Vector2i>>> viewerPool,
|
||||
float viewEnlargement,
|
||||
EntityQuery<TransformComponent> xformQuery)
|
||||
ObjectPool<Dictionary<NetEntity, HashSet<Vector2i>>> viewerPool,
|
||||
float viewEnlargement)
|
||||
{
|
||||
Dictionary<EntityUid, HashSet<Vector2i>> chunks = viewerPool.Get();
|
||||
var chunks = viewerPool.Get();
|
||||
DebugTools.Assert(chunks.Count == 0);
|
||||
|
||||
foreach (var viewerUid in viewers)
|
||||
{
|
||||
if (!xformQuery.TryGetComponent(viewerUid, out var xform))
|
||||
if (!_xformQuery.TryGetComponent(viewerUid, out var xform))
|
||||
{
|
||||
Log.Error($"Player has deleted viewer entities? Viewers: {string.Join(", ", viewers.Select(x => ToPrettyString(x)))}");
|
||||
Log.Error($"Player has deleted viewer entities? Viewers: {string.Join(", ", viewers.Select(ToPrettyString))}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var pos = _transform.GetWorldPosition(xform, xformQuery);
|
||||
var pos = _transform.GetWorldPosition(xform);
|
||||
var bounds = _baseViewBounds.Translated(pos).Enlarged(viewEnlargement);
|
||||
|
||||
foreach (var grid in _mapManager.FindGridsIntersecting(xform.MapID, bounds, true))
|
||||
{
|
||||
if (!chunks.TryGetValue(grid.Owner, out var set))
|
||||
var netGrid = GetNetEntity(grid.Owner);
|
||||
|
||||
if (!chunks.TryGetValue(netGrid, out var set))
|
||||
{
|
||||
chunks[grid.Owner] = set = indexPool.Get();
|
||||
chunks[netGrid] = set = indexPool.Get();
|
||||
DebugTools.Assert(set.Count == 0);
|
||||
}
|
||||
|
||||
var enumerator = new ChunkIndicesEnumerator(_transform.GetInvWorldMatrix(grid.Owner, xformQuery).TransformBox(bounds), chunkSize);
|
||||
var enumerator = new ChunkIndicesEnumerator(_transform.GetInvWorldMatrix(grid.Owner).TransformBox(bounds), chunkSize);
|
||||
|
||||
while (enumerator.MoveNext(out var indices))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user