Compare commits

...

4 Commits

2 changed files with 20 additions and 2 deletions

View File

@ -221,7 +221,11 @@ public partial class Mission : Node3D
}
}
var lightmapTexture = BuildLightmapTexture(cells, packingRects.ToArray(), rectDataMap, surfaceDataMap);
var lightmapTexture = Timing.TimeStage("Build Lightmap", () =>
{
return BuildLightmapTexture(cells, packingRects.ToArray(), rectDataMap, surfaceDataMap);
});
foreach (var (textureId, surface) in surfaceDataMap)
{
if (surface.Empty)
@ -273,7 +277,12 @@ public partial class Mission : Node3D
private static Texture BuildLightmapTexture(WorldRep.Cell[] cells, PackingRectangle[] packingRects, Dictionary<int, LightmapRectData> rectDataMap, Dictionary<int, MeshSurfaceData> surfaceDataMap)
{
RectanglePacker.Pack(packingRects, out var bounds);
var bounds = Timing.TimeStage("RectPack", () =>
{
RectanglePacker.Pack(packingRects, out var bounds, PackingHints.FindBest, 0);
return bounds;
});
GD.Print($"Creating lightmap with bounds: ({bounds.Width}, {bounds.Height})");
var image = Image.CreateEmpty((int)bounds.Width, (int)bounds.Height, false, Image.Format.Rgba8);
foreach (var rect in packingRects)
{

View File

@ -12,4 +12,13 @@ public static class Timing
watch.Stop();
Godot.GD.Print($"[{stagename}]: {watch.Elapsed:g}");
}
public static T TimeStage<T>(string stagename, Func<T> action)
{
var watch = Stopwatch.StartNew();
var value = action();
watch.Stop();
Godot.GD.Print($"[{stagename}]: {watch.Elapsed:g}");
return value;
}
}