Compare commits
No commits in common. "8237a46989e589514914b802b81d939db9131407" and "ec79e07ec7b282fb8c56c9acf026fa5fed519908" have entirely different histories.
8237a46989
...
ec79e07ec7
|
@ -74,9 +74,7 @@ public partial class Mission : Node3D
|
|||
{
|
||||
if (Build)
|
||||
{
|
||||
Timing.Reset();
|
||||
Timing.TimeStage("Build", () => RebuildMap());
|
||||
Timing.LogAll();
|
||||
Build = false;
|
||||
}
|
||||
if (Clear)
|
||||
|
@ -245,7 +243,7 @@ public partial class Mission : Node3D
|
|||
var rawRot = brush.angle;
|
||||
var rot = new Vector3(rawRot.Y, rawRot.Z, rawRot.X) * 360 / ushort.MaxValue;
|
||||
var scale = scaleProp == null ? Vector3.One : scaleProp.scale.ToGodotVec3(false);
|
||||
var model = Timing.TimeStage("Load Models", () => { return _modelLoader.Load(_campaignName, modelName); });
|
||||
var model = _modelLoader.Load(_campaignName, modelName);
|
||||
if (model != null)
|
||||
{
|
||||
model.Position = pos;
|
||||
|
@ -394,35 +392,28 @@ public partial class Mission : Node3D
|
|||
var layerCount = lightmap.Layers;
|
||||
var srcRect = new Rect2I(0, 0, width, height);
|
||||
var dst = new Vector2I(rect.X, rect.Y);
|
||||
Timing.TimeStage("Blit LM Data", () =>
|
||||
for (var i = 0; i < layerCount; i++)
|
||||
{
|
||||
for (var i = 0; i < layerCount; i++)
|
||||
{
|
||||
var bytes = Timing.TimeStage("Get LM Data", () => { return lightmap.AsBytesRgba(i); });
|
||||
var cellLm = Image.CreateFromData(width, height, false, lightmapFormat, bytes);
|
||||
lmImages[i].BlitRect(cellLm, srcRect, dst);
|
||||
}
|
||||
});
|
||||
var cellLm = Image.CreateFromData(width, height, false, lightmapFormat, lightmap.AsBytesRgba(i));
|
||||
lmImages[i].BlitRect(cellLm, srcRect, dst);
|
||||
}
|
||||
|
||||
Timing.TimeStage("Transform LM UVs", () =>
|
||||
if (!surfaceDataMap.ContainsKey(info.textureId)) GD.Print("Invalid SurfaceDataMap key");
|
||||
surfaceDataMap[info.textureId].TransformUv2s(info.uvStart, info.uvEnd, (uv) =>
|
||||
{
|
||||
if (!surfaceDataMap.ContainsKey(info.textureId)) GD.Print("Invalid SurfaceDataMap key");
|
||||
surfaceDataMap[info.textureId].TransformUv2s(info.uvStart, info.uvEnd, (uv) =>
|
||||
{
|
||||
var u = uv.X;
|
||||
var v = uv.Y;
|
||||
var u = uv.X;
|
||||
var v = uv.Y;
|
||||
|
||||
// Clamp uv range to [0..1]
|
||||
u %= 1;
|
||||
v %= 1;
|
||||
if (u < 0) u = Math.Abs(u);
|
||||
if (v < 0) v = Math.Abs(v);
|
||||
// Clamp uv range to [0..1]
|
||||
u %= 1;
|
||||
v %= 1;
|
||||
if (u < 0) u = Math.Abs(u);
|
||||
if (v < 0) v = Math.Abs(v);
|
||||
|
||||
// Transform!
|
||||
u = (rect.X + rect.Width * u) / bounds.Width;
|
||||
v = (rect.Y + rect.Height * v) / bounds.Height;
|
||||
return new Vector2(u, v);
|
||||
});
|
||||
// Transform!
|
||||
u = (rect.X + rect.Width * u) / bounds.Width;
|
||||
v = (rect.Y + rect.Height * v) / bounds.Height;
|
||||
return new Vector2(u, v);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -445,7 +436,7 @@ public partial class Mission : Node3D
|
|||
// TODO: This is a mess lol
|
||||
var textureId = renderPoly.TextureId;
|
||||
|
||||
var texture = Timing.TimeStage("Load Textures", () => { return _textureLoader.Get(textureId); });
|
||||
var texture = _textureLoader.Get(textureId);
|
||||
var texU = renderPoly.TextureVectors.Item1.ToGodotVec3();
|
||||
var texV = renderPoly.TextureVectors.Item2.ToGodotVec3();
|
||||
var baseU = renderPoly.TextureBases.Item1;
|
||||
|
|
|
@ -1,24 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace KeepersCompound.TMV;
|
||||
|
||||
public static class Timing
|
||||
{
|
||||
static readonly Dictionary<string, TimeSpan> _stages = new();
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
_stages.Clear();
|
||||
}
|
||||
|
||||
public static void TimeStage(string stagename, Action action)
|
||||
{
|
||||
var watch = Stopwatch.StartNew();
|
||||
action();
|
||||
watch.Stop();
|
||||
AddOrIncrement(stagename, watch.Elapsed);
|
||||
Godot.GD.Print($"[{stagename}]: {watch.Elapsed:g}");
|
||||
}
|
||||
|
||||
public static T TimeStage<T>(string stagename, Func<T> action)
|
||||
|
@ -26,24 +18,7 @@ public static class Timing
|
|||
var watch = Stopwatch.StartNew();
|
||||
var value = action();
|
||||
watch.Stop();
|
||||
AddOrIncrement(stagename, watch.Elapsed);
|
||||
Godot.GD.Print($"[{stagename}]: {watch.Elapsed:g}");
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void LogAll()
|
||||
{
|
||||
foreach (var (stagename, time) in _stages)
|
||||
{
|
||||
Godot.GD.Print($"[{stagename}]: {time:g}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddOrIncrement(string stagename, TimeSpan elapsed)
|
||||
{
|
||||
if (_stages.TryGetValue(stagename, out var time))
|
||||
{
|
||||
elapsed += time;
|
||||
}
|
||||
_stages[stagename] = elapsed;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue