Compare commits

...

2 Commits

Author SHA1 Message Date
Jarrod Doyle 2ecf17400e
Replace console writes with logging 2025-01-11 13:16:31 +00:00
Jarrod Doyle 19aefb6ac5
Add Serilog and configure logger 2025-01-11 12:32:13 +00:00
6 changed files with 60 additions and 10 deletions

View File

@ -1,3 +1,5 @@
using Serilog;
namespace KeepersCompound.LGS.Database.Chunks; namespace KeepersCompound.LGS.Database.Chunks;
public record LinkId public record LinkId
@ -96,7 +98,7 @@ public class LinkChunk : IChunk, IMergable
if (links.Count != count) if (links.Count != count)
{ {
Console.WriteLine($"Trimmed links: {count} -> {links.Count}"); Log.Information("Trimming excess Links in GAM: {StartCount} -> {EndCount}", count, links.Count);
} }
links.AddRange(((LinkChunk)other).links); links.AddRange(((LinkChunk)other).links);
@ -162,7 +164,7 @@ public class LinkDataMetaProp : IChunk, IMergable
if (linkData.Count != count) if (linkData.Count != count)
{ {
Console.WriteLine($"Trimmed link data: {count} -> {linkData.Count}"); Log.Information("Trimming excess LinkData in GAM: {StartCount} -> {EndCount}", count, linkData.Count);
} }
linkData.AddRange(((LinkDataMetaProp)other).linkData); linkData.AddRange(((LinkDataMetaProp)other).linkData);

View File

@ -7,4 +7,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog" Version="4.2.0" />
</ItemGroup>
</Project> </Project>

View File

@ -14,6 +14,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="DotMake.CommandLine" Version="1.8.8" /> <PackageReference Include="DotMake.CommandLine" Version="1.8.8" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="TinyEmbree" Version="1.0.3" /> <PackageReference Include="TinyEmbree" Version="1.0.3" />
</ItemGroup> </ItemGroup>

View File

@ -2,6 +2,7 @@ using System.Numerics;
using KeepersCompound.LGS; using KeepersCompound.LGS;
using KeepersCompound.LGS.Database; using KeepersCompound.LGS.Database;
using KeepersCompound.LGS.Database.Chunks; using KeepersCompound.LGS.Database.Chunks;
using Serilog;
using TinyEmbree; using TinyEmbree;
namespace KeepersCompound.Lightmapper; namespace KeepersCompound.Lightmapper;
@ -191,10 +192,28 @@ public class LightMapper
} }
} }
var infinite = _lights.Count(light => light.Radius == float.MaxValue); var infinite = 0;
foreach (var light in _lights)
{
if (light.Radius != float.MaxValue)
{
continue;
}
if (light.ObjId != -1)
{
Log.Warning("Infinite light from object {Id}", light.ObjId);
}
else
{
Log.Warning("Infinite light from brush near {Position}", light.Position);
}
infinite++;
}
if (infinite > 0) if (infinite > 0)
{ {
Console.WriteLine($"WARNING: Infinite radius lights found: {infinite}/{_lights.Count}"); Log.Warning("Mission contains {Count} infinite lights", infinite);
} }
} }
@ -221,6 +240,7 @@ public class LightMapper
R2 = float.MaxValue, R2 = float.MaxValue,
LightTableIndex = lightTable.LightCount, LightTableIndex = lightTable.LightCount,
SpotlightInnerAngle = -1f, SpotlightInnerAngle = -1f,
ObjId = -1,
}; };
_lights.Add(light); _lights.Add(light);
@ -483,7 +503,7 @@ public class LightMapper
if (cell.LightIndexCount > 97) if (cell.LightIndexCount > 97)
{ {
// Console.WriteLine($"WARNING: Too many lights in cell at ({cell.SphereCenter}): {cell.LightIndexCount - 1} / 96"); Log.Warning("Cell {Id} sees too many lights ({Count})", i, cell.LightIndices[0]);
} }
}); });
@ -505,10 +525,10 @@ public class LightMapper
if (overLit > 0) if (overLit > 0)
{ {
Console.WriteLine($"WARNING: Overlit cells detected: {overLit}/{worldRep.Cells.Length}"); Log.Warning("{Count}/{CellCount} cells are overlit. Overlit cells can cause Object/Light Gem lighting issues.", overLit, worldRep.Cells.Length);
} }
Console.WriteLine($"MaxLights: {maxLights} / 96"); Log.Information("Max cell lights found ({Count}/96)", maxLights);
} }
} }

View File

@ -1,11 +1,31 @@
using DotMake.CommandLine; using DotMake.CommandLine;
using Serilog;
using Serilog.Sinks.SystemConsole.Themes;
namespace KeepersCompound.Lightmapper; namespace KeepersCompound.Lightmapper;
internal static class Program internal static class Program
{ {
public static async Task<int> Main(string[] args) => private static void ConfigureLogger()
await Cli.RunAsync<LightCommand>(args); {
const string outputTemplate = "{Timestamp:HH:mm:ss.fff} [{Level}] {Message:lj}{NewLine}{Exception}";
var logPath = $"{AppDomain.CurrentDomain.BaseDirectory}/logs/{DateTime.Now:yyyyMMdd_HHmmss}.log";
var config = new LoggerConfiguration();
#if DEBUG
config.MinimumLevel.Debug();
#endif
Log.Logger = config
.WriteTo.Console(theme: AnsiConsoleTheme.Sixteen, outputTemplate: outputTemplate)
.WriteTo.File(logPath, outputTemplate: outputTemplate)
.CreateLogger();
}
public static async Task<int> Main(string[] args)
{
ConfigureLogger();
return await Cli.RunAsync<LightCommand>(args);
}
} }
[CliCommand(Description = "Compute lightmaps for a NewDark .MIS/.COW")] [CliCommand(Description = "Compute lightmaps for a NewDark .MIS/.COW")]

View File

@ -1,4 +1,5 @@
using System.Diagnostics; using System.Diagnostics;
using Serilog;
namespace KeepersCompound.Lightmapper; namespace KeepersCompound.Lightmapper;
@ -32,7 +33,7 @@ public static class Timing
{ {
foreach (var (stagename, time) in _stages) foreach (var (stagename, time) in _stages)
{ {
Console.WriteLine($"[{stagename}]: {time:g}"); Log.Information("Timing {StageName}: {Time:g}", stagename, time);
} }
} }