Fix some MapPainter warnings (#17639)
This commit is contained in:
@@ -1,20 +1,15 @@
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.MapRenderer.Painters
|
||||
namespace Content.MapRenderer.Painters;
|
||||
|
||||
public readonly record struct EntityData(EntityUid Owner, SpriteComponent Sprite, float X, float Y)
|
||||
{
|
||||
public sealed class EntityData
|
||||
{
|
||||
public EntityData(SpriteComponent sprite, float x, float y)
|
||||
{
|
||||
Sprite = sprite;
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
public readonly EntityUid Owner = Owner;
|
||||
|
||||
public SpriteComponent Sprite { get; }
|
||||
public readonly SpriteComponent Sprite = Sprite;
|
||||
|
||||
public float X { get; }
|
||||
public readonly float X = X;
|
||||
|
||||
public float Y { get; }
|
||||
}
|
||||
public readonly float Y = Y;
|
||||
}
|
||||
|
||||
@@ -38,23 +38,24 @@ public sealed class EntityPainter
|
||||
|
||||
// TODO cache this shit what are we insane
|
||||
entities.Sort(Comparer<EntityData>.Create((x, y) => x.Sprite.DrawDepth.CompareTo(y.Sprite.DrawDepth)));
|
||||
var xformSystem = _sEntityManager.System<SharedTransformSystem>();
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
Run(canvas, entity);
|
||||
Run(canvas, entity, xformSystem);
|
||||
}
|
||||
|
||||
Console.WriteLine($"{nameof(EntityPainter)} painted {entities.Count} entities in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
|
||||
public void Run(Image canvas, EntityData entity)
|
||||
public void Run(Image canvas, EntityData entity, SharedTransformSystem xformSystem)
|
||||
{
|
||||
if (!entity.Sprite.Visible || entity.Sprite.ContainerOccluded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var worldRotation = _sEntityManager.GetComponent<TransformComponent>(entity.Sprite.Owner).WorldRotation;
|
||||
var worldRotation = xformSystem.GetWorldRotation(entity.Owner);
|
||||
foreach (var layer in entity.Sprite.AllLayers)
|
||||
{
|
||||
if (!layer.Visible)
|
||||
@@ -70,7 +71,7 @@ public sealed class EntityPainter
|
||||
var rsi = layer.ActualRsi;
|
||||
Image image;
|
||||
|
||||
if (rsi == null || rsi.Path == null || !rsi.TryGetState(layer.RsiState, out var state))
|
||||
if (rsi == null || !rsi.TryGetState(layer.RsiState, out var state))
|
||||
{
|
||||
image = _errorImage;
|
||||
}
|
||||
@@ -89,7 +90,7 @@ public sealed class EntityPainter
|
||||
|
||||
image = image.CloneAs<Rgba32>();
|
||||
|
||||
(int, int, int, int) GetRsiFrame(RSI? rsi, Image image, EntityData entity, ISpriteLayer layer, int direction)
|
||||
static (int, int, int, int) GetRsiFrame(RSI? rsi, Image image, EntityData entity, ISpriteLayer layer, int direction)
|
||||
{
|
||||
if (rsi is null)
|
||||
return (0, 0, EyeManager.PixelsPerMeter, EyeManager.PixelsPerMeter);
|
||||
@@ -115,7 +116,7 @@ public sealed class EntityPainter
|
||||
var rect = new Rectangle(x, y, width, height);
|
||||
if (!new Rectangle(Point.Empty, image.Size()).Contains(rect))
|
||||
{
|
||||
Console.WriteLine($"Invalid layer {rsi!.Path}/{layer.RsiState.Name}.png for entity {_sEntityManager.ToPrettyString(entity.Sprite.Owner)} at ({entity.X}, {entity.Y})");
|
||||
Console.WriteLine($"Invalid layer {rsi!.Path}/{layer.RsiState.Name}.png for entity {_sEntityManager.ToPrettyString(entity.Owner)} at ({entity.X}, {entity.Y})");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,24 +45,24 @@ namespace Content.MapRenderer.Painters
|
||||
_decals = GetDecals();
|
||||
}
|
||||
|
||||
public void Run(Image gridCanvas, MapGridComponent grid)
|
||||
public void Run(Image gridCanvas, EntityUid gridUid, MapGridComponent grid)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
|
||||
if (!_entities.TryGetValue(grid.Owner, out var entities))
|
||||
if (!_entities.TryGetValue(gridUid, out var entities))
|
||||
{
|
||||
Console.WriteLine($"No entities found on grid {grid.Owner}");
|
||||
Console.WriteLine($"No entities found on grid {gridUid}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Decals are always painted before entities, and are also optional.
|
||||
if (_decals.TryGetValue(grid.Owner, out var decals))
|
||||
if (_decals.TryGetValue(gridUid, out var decals))
|
||||
_decalPainter.Run(gridCanvas, CollectionsMarshal.AsSpan(decals));
|
||||
|
||||
|
||||
_entityPainter.Run(gridCanvas, entities);
|
||||
Console.WriteLine($"{nameof(GridPainter)} painted grid {grid.Owner} in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
|
||||
Console.WriteLine($"{nameof(GridPainter)} painted grid {gridUid} in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
|
||||
private ConcurrentDictionary<EntityUid, List<EntityData>> GetEntities()
|
||||
@@ -91,7 +91,7 @@ namespace Content.MapRenderer.Painters
|
||||
var position = transform.LocalPosition;
|
||||
|
||||
var (x, y) = TransformLocalPosition(position, grid);
|
||||
var data = new EntityData(sprite, x, y);
|
||||
var data = new EntityData(entity, sprite, x, y);
|
||||
|
||||
components.GetOrAdd(transform.GridUid.Value, _ => new List<EntityData>()).Add(data);
|
||||
}
|
||||
@@ -108,21 +108,22 @@ namespace Content.MapRenderer.Painters
|
||||
stopwatch.Start();
|
||||
|
||||
var decals = new Dictionary<EntityUid, List<DecalData>>();
|
||||
var query = _sEntityManager.AllEntityQueryEnumerator<MapGridComponent>();
|
||||
|
||||
foreach (var grid in _sMapManager.GetAllGrids())
|
||||
while (query.MoveNext(out var uid, out var grid))
|
||||
{
|
||||
// TODO this needs to use the client entity manager because the client
|
||||
// actually has the correct z-indices for decals for some reason when the server doesn't,
|
||||
// BUT can't do that yet because the client hasn't actually received everything yet
|
||||
// for some reason decal moment i guess.
|
||||
if (_sEntityManager.TryGetComponent<DecalGridComponent>(grid.Owner, out var comp))
|
||||
if (_sEntityManager.TryGetComponent<DecalGridComponent>(uid, out var comp))
|
||||
{
|
||||
foreach (var chunk in comp.ChunkCollection.ChunkCollection.Values)
|
||||
{
|
||||
foreach (var decal in chunk.Decals.Values)
|
||||
{
|
||||
var (x, y) = TransformLocalPosition(decal.Coordinates, grid);
|
||||
decals.GetOrNew(grid.Owner).Add(new DecalData(decal, x, y));
|
||||
decals.GetOrNew(uid).Add(new DecalData(decal, x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +60,9 @@ namespace Content.MapRenderer.Painters
|
||||
|
||||
var tilePainter = new TilePainter(client, server);
|
||||
var entityPainter = new GridPainter(client, server);
|
||||
MapGridComponent[] grids = null!;
|
||||
(EntityUid Uid, MapGridComponent Grid)[] grids = null!;
|
||||
var xformQuery = sEntityManager.GetEntityQuery<TransformComponent>();
|
||||
var xformSystem = sEntityManager.System<SharedTransformSystem>();
|
||||
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
@@ -73,12 +74,12 @@ namespace Content.MapRenderer.Painters
|
||||
}
|
||||
|
||||
var mapId = sMapManager.GetAllMapIds().Last();
|
||||
grids = sMapManager.GetAllMapGrids(mapId).ToArray();
|
||||
grids = sMapManager.GetAllMapGrids(mapId).Select(o => (o.Owner, o)).ToArray();
|
||||
|
||||
foreach (var grid in grids)
|
||||
{
|
||||
var gridXform = xformQuery.GetComponent(grid.Owner);
|
||||
gridXform.WorldRotation = Angle.Zero;
|
||||
var gridXform = xformQuery.GetComponent(grid.Uid);
|
||||
xformSystem.SetWorldRotation(gridXform, Angle.Zero);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -88,16 +89,16 @@ namespace Content.MapRenderer.Painters
|
||||
foreach (var grid in grids)
|
||||
{
|
||||
// Skip empty grids
|
||||
if (grid.LocalAABB.IsEmpty())
|
||||
if (grid.Grid.LocalAABB.IsEmpty())
|
||||
{
|
||||
Console.WriteLine($"Warning: Grid {grid.Owner} was empty. Skipping image rendering.");
|
||||
Console.WriteLine($"Warning: Grid {grid.Uid} was empty. Skipping image rendering.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var tileXSize = grid.TileSize * TilePainter.TileImageSize;
|
||||
var tileYSize = grid.TileSize * TilePainter.TileImageSize;
|
||||
var tileXSize = grid.Grid.TileSize * TilePainter.TileImageSize;
|
||||
var tileYSize = grid.Grid.TileSize * TilePainter.TileImageSize;
|
||||
|
||||
var bounds = grid.LocalAABB;
|
||||
var bounds = grid.Grid.LocalAABB;
|
||||
|
||||
var left = bounds.Left;
|
||||
var right = bounds.Right;
|
||||
@@ -111,16 +112,16 @@ namespace Content.MapRenderer.Painters
|
||||
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
tilePainter.Run(gridCanvas, grid);
|
||||
entityPainter.Run(gridCanvas, grid);
|
||||
tilePainter.Run(gridCanvas, grid.Uid, grid.Grid);
|
||||
entityPainter.Run(gridCanvas, grid.Uid, grid.Grid);
|
||||
|
||||
gridCanvas.Mutate(e => e.Flip(FlipMode.Vertical));
|
||||
});
|
||||
|
||||
var renderedImage = new RenderedGridImage<Rgba32>(gridCanvas)
|
||||
{
|
||||
GridUid = grid.Owner,
|
||||
Offset = xformQuery.GetComponent(grid.Owner).WorldPosition
|
||||
GridUid = grid.Uid,
|
||||
Offset = xformSystem.GetWorldPosition(grid.Uid),
|
||||
};
|
||||
|
||||
yield return renderedImage;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -26,7 +27,7 @@ namespace Content.MapRenderer.Painters
|
||||
_cResourceCache = client.ResolveDependency<IResourceCache>();
|
||||
}
|
||||
|
||||
public void Run(Image gridCanvas, MapGridComponent grid)
|
||||
public void Run(Image gridCanvas, EntityUid gridUid, MapGridComponent grid)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
@@ -55,7 +56,7 @@ namespace Content.MapRenderer.Painters
|
||||
i++;
|
||||
});
|
||||
|
||||
Console.WriteLine($"{nameof(TilePainter)} painted {i} tiles on grid {grid.Owner} in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
|
||||
Console.WriteLine($"{nameof(TilePainter)} painted {i} tiles on grid {gridUid} in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
|
||||
}
|
||||
|
||||
private Dictionary<string, List<Image>> GetTileImages(
|
||||
@@ -87,7 +88,8 @@ namespace Content.MapRenderer.Painters
|
||||
|
||||
for (var i = 0; i < definition.Variants; i++)
|
||||
{
|
||||
var tileImage = tileSheet.Clone(o => o.Crop(new Rectangle(tileSize * i, 0, 32, 32)));
|
||||
var index = i;
|
||||
var tileImage = tileSheet.Clone(o => o.Crop(new Rectangle(tileSize * index, 0, 32, 32)));
|
||||
images[path].Add(tileImage);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user