Decal rendering improvements (#6704)

Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2022-02-20 17:39:33 +11:00
committed by GitHub
parent 45413fd75a
commit 5b53b69191
3 changed files with 69 additions and 28 deletions

View File

@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
@@ -17,6 +12,7 @@ namespace Content.Shared.Decals
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] protected readonly IMapManager MapManager = default!;
[Dependency] protected readonly SharedTransformSystem Transforms = default!;
protected readonly Dictionary<GridId, Dictionary<uint, Vector2i>> ChunkIndex = new();
@@ -101,15 +97,19 @@ namespace Content.Shared.Decals
protected Dictionary<GridId, HashSet<Vector2i>> GetChunksForViewers(HashSet<EntityUid> viewers)
{
var chunks = new Dictionary<GridId, HashSet<Vector2i>>();
var xformQuery = GetEntityQuery<TransformComponent>();
foreach (var viewerUid in viewers)
{
var (bounds, mapId) = CalcViewBounds(viewerUid);
MapManager.FindGridsIntersectingEnumerator(mapId, bounds, out var gridsEnumerator, true);
while(gridsEnumerator.MoveNext(out var grid))
foreach (var grid in MapManager.FindGridsIntersecting(mapId, bounds))
{
if(!chunks.ContainsKey(grid.Index))
chunks[grid.Index] = new();
var enumerator = new ChunkIndicesEnumerator(grid.InvWorldMatrix.TransformBox(bounds), ChunkSize);
if (!chunks.ContainsKey(grid.Index))
chunks[grid.Index] = new HashSet<Vector2i>();
var enumerator = new ChunkIndicesEnumerator(Transforms.GetInvWorldMatrix(grid.GridEntityId, xformQuery).TransformBox(bounds), ChunkSize);
while (enumerator.MoveNext(out var indices))
{
chunks[grid.Index].Add(indices.Value);
@@ -120,7 +120,8 @@ namespace Content.Shared.Decals
}
}
internal struct ChunkIndicesEnumerator
// TODO: Pretty sure paul was moving this somewhere but just so people know
public struct ChunkIndicesEnumerator
{
private Vector2i _chunkLB;
private Vector2i _chunkRT;
@@ -128,7 +129,7 @@ namespace Content.Shared.Decals
private int _xIndex;
private int _yIndex;
internal ChunkIndicesEnumerator(Box2 localAABB, int chunkSize)
public ChunkIndicesEnumerator(Box2 localAABB, int chunkSize)
{
_chunkLB = new Vector2i((int)Math.Floor(localAABB.Left / chunkSize), (int)Math.Floor(localAABB.Bottom / chunkSize));
_chunkRT = new Vector2i((int)Math.Floor(localAABB.Right / chunkSize), (int)Math.Floor(localAABB.Top / chunkSize));