Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Content.MapRenderer/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.IO;

namespace Content.MapRenderer
{
internal static class Logger
{
private static readonly string LogFilePath = "RenderLog.txt";

public static void Init()
{
try
{
File.WriteAllText(LogFilePath, string.Empty);
Log("Started", sendInConsole: false);
}
catch {}
}

public static void Log(string message, Exception? ex = null, bool sendInConsole = true)
{
try
{
if (sendInConsole)
{
if (ex != null)
Console.Error.WriteLine($"{message}\n{ex}");
else
Console.WriteLine(message);
}

var line = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] {message}{Environment.NewLine}";
if (ex != null)
line += $"Exception details: {ex}{Environment.NewLine}";


File.AppendAllText(LogFilePath, line);
}
catch {}
}
}
}
4 changes: 2 additions & 2 deletions Content.MapRenderer/Painters/DecalPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public void Run(Image canvas, Span<DecalData> decals, Vector2 customOffset = def
Run(canvas, decal, customOffset);
}

Console.WriteLine($"{nameof(DecalPainter)} painted {decals.Length} decals in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
Logger.Log($"{nameof(DecalPainter)} painted {decals.Length} decals in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
}

private void Run(Image canvas, DecalData data, Vector2 customOffset = default)
{
var decal = data.Decal;
if (!_decalTextures.TryGetValue(decal.Id, out var sprite))
{
Console.WriteLine($"Decal {decal.Id} did not have an associated prototype.");
Logger.Log($"Decal {decal.Id} did not have an associated prototype.");
return;
}

Expand Down
4 changes: 2 additions & 2 deletions Content.MapRenderer/Painters/EntityPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void Run(Image canvas, List<EntityData> entities, Vector2 customOffset =
Run(canvas, entity, xformSystem, customOffset);
}

Console.WriteLine($"{nameof(EntityPainter)} painted {entities.Count} entities in {(int)stopwatch.Elapsed.TotalMilliseconds} ms");
Logger.Log($"{nameof(EntityPainter)} painted {entities.Count} entities in {(int)stopwatch.Elapsed.TotalMilliseconds} ms");
}

public void Run(Image canvas, EntityData entity, SharedTransformSystem xformSystem, Vector2 customOffset = default)
Expand Down Expand Up @@ -120,7 +120,7 @@ public void Run(Image canvas, EntityData entity, SharedTransformSystem xformSyst
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.Owner)} at ({entity.X}, {entity.Y})");
Logger.Log($"Invalid layer {rsi!.Path}/{layer.RsiState.Name}.png for entity {_sEntityManager.ToPrettyString(entity.Owner)} at ({entity.X}, {entity.Y})");
return;
}

Expand Down
8 changes: 4 additions & 4 deletions Content.MapRenderer/Painters/GridPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Run(Image gridCanvas, EntityUid gridUid, MapGridComponent grid, Vect

if (!_entities.TryGetValue(gridUid, out var entities))
{
Console.WriteLine($"No entities found on grid {gridUid}");
Logger.Log($"No entities found on grid {gridUid}");
return;
}

Expand All @@ -60,7 +60,7 @@ public void Run(Image gridCanvas, EntityUid gridUid, MapGridComponent grid, Vect


_entityPainter.Run(gridCanvas, entities, customOffset);
Console.WriteLine($"{nameof(GridPainter)} painted grid {gridUid} in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
Logger.Log($"{nameof(GridPainter)} painted grid {gridUid} in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
}

private ConcurrentDictionary<EntityUid, List<EntityData>> GetEntities()
Expand Down Expand Up @@ -96,7 +96,7 @@ private ConcurrentDictionary<EntityUid, List<EntityData>> GetEntities()
}
}

Console.WriteLine($"Found {components.Values.Sum(l => l.Count)} entities on {components.Count} grids in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
Logger.Log($"Found {components.Values.Sum(l => l.Count)} entities on {components.Count} grids in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");

return components;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ private Dictionary<EntityUid, List<DecalData>> GetDecals()
}
}

Console.WriteLine($"Found {decals.Values.Sum(l => l.Count)} decals on {decals.Count} grids in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
Logger.Log($"Found {decals.Values.Sum(l => l.Count)} decals on {decals.Count} grids in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
return decals;
}

Expand Down
42 changes: 39 additions & 3 deletions Content.MapRenderer/Painters/MapPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Robust.Shared.Map.Components;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
Expand All @@ -44,21 +45,27 @@ public async Task Initialize()
{
var stopwatch = RStopwatch.StartNew();

Logger.Log($"Map type: {_map.GetType().Name}");
Logger.Log($"Map: {_map}");

var poolSettings = new PoolSettings
{
DummyTicker = false,
Connected = true,
Destructive = true,
Fresh = true,
// Seriously whoever made MapPainter use GameMapPrototype I wish you step on a lego one time.
Map = _map is RenderMapPrototype prototype ? prototype.Prototype : PoolManager.TestMap,
};

Logger.Log($"Pool map setting: {poolSettings.Map}");

_pair = await PoolManager.GetServerClient(poolSettings, _testContextLike);

Console.WriteLine($"Loaded client and server in {(int)stopwatch.Elapsed.TotalMilliseconds} ms");
Logger.Log($"Loaded client and server in {(int)stopwatch.Elapsed.TotalMilliseconds} ms");

if (_map is RenderMapFile mapFile)
{
Logger.Log($"Loading RenderMapFile: {mapFile.FileName}");
using var stream = File.OpenRead(mapFile.FileName);

await _pair.Server.WaitPost(() =>
Expand All @@ -76,8 +83,37 @@ await _pair.Server.WaitPost(() =>
throw new IOException($"File {mapFile.FileName} could not be read");

_grids = loadResult.Grids.ToArray();
Logger.Log($"Loaded {_grids.Length} grids from RenderMapFile");
});
}
else if (_map is RenderMapGrid gridFile)
{
Logger.Log($"Loading RenderMapGrid: {gridFile.FileName}");
await _pair.Server.WaitPost(() =>
{
var mapSystem = _pair.Server.System<SharedMapSystem>();
var mapManager = _pair.Server.ResolveDependency<IMapManager>();
var mapLoader = _pair.Server.System<MapLoaderSystem>();

Logger.Log($"Creating empty map");
var mapUid = mapSystem.CreateMap(out var mapId, false);
Logger.Log($"Created map entity {mapUid} with ID: {mapId}");

var path = new ResPath(gridFile.FileName);
var opts = new DeserializationOptions { StoreYamlUids = true };

Logger.Log($"Loading grid from: {path}");
if (!mapLoader.TryLoadGrid(mapId, path, out var loadedGrid, opts))
throw new IOException($"Grid file {gridFile.FileName} could not be loaded");

_grids = mapManager.GetAllGrids(mapId).ToArray();
Logger.Log($"Loaded {_grids.Length} grids from RenderMapGrid");
});
}
else
{
Logger.Log($"Using RenderMapPrototype with default map loading");
}
}

public async Task SetupView(bool showMarkers)
Expand Down Expand Up @@ -192,7 +228,7 @@ await server.WaitPost(() =>
var tiles = mapSys.GetAllTiles(uid, grid).ToList();
if (tiles.Count == 0)
{
Console.WriteLine($"Warning: Grid {uid} was empty. Skipping image rendering.");
Logger.Log($"Warning: Grid {uid} was empty. Skipping image rendering.");
continue;
}
var tileXSize = grid.TileSize * TilePainter.TileImageSize;
Expand Down
4 changes: 2 additions & 2 deletions Content.MapRenderer/Painters/TilePainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void Run(Image gridCanvas, EntityUid gridUid, MapGridComponent grid, Vect
i++;
});

Console.WriteLine($"{nameof(TilePainter)} painted {i} tiles on grid {gridUid} in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
Logger.Log($"{nameof(TilePainter)} painted {i} tiles on grid {gridUid} in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
}

private Dictionary<string, List<Image>> GetTileImages(
Expand Down Expand Up @@ -119,7 +119,7 @@ private Dictionary<string, List<Image>> GetTileImages(
}
}

Console.WriteLine($"Indexed all tile images in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");
Logger.Log($"Indexed all tile images in {(int) stopwatch.Elapsed.TotalMilliseconds} ms");

return images;
}
Expand Down
Loading
Loading