Compare commits

...

3 Commits

Author SHA1 Message Date
Jarrod Doyle 38a360793a
Faster GIF loading 2024-08-30 18:22:40 +01:00
Jarrod Doyle eca63077b8
Cleaner model return 2024-08-30 17:56:28 +01:00
Jarrod Doyle 89cc70345e
Add more detailed model loading timings 2024-08-30 17:47:19 +01:00
3 changed files with 8 additions and 15 deletions

View File

@ -245,7 +245,7 @@ public partial class Mission : Node3D
var rawRot = brush.angle; var rawRot = brush.angle;
var rot = new Vector3(rawRot.Y, rawRot.Z, rawRot.X) * 360 / ushort.MaxValue; var rot = new Vector3(rawRot.Y, rawRot.Z, rawRot.X) * 360 / ushort.MaxValue;
var scale = scaleProp == null ? Vector3.One : scaleProp.scale.ToGodotVec3(false); var scale = scaleProp == null ? Vector3.One : scaleProp.scale.ToGodotVec3(false);
var model = Timing.TimeStage("Load Models", () => { return _modelLoader.Load(_campaignName, modelName); }); var model = Timing.TimeStage("Get Models", () => { return _modelLoader.Load(_campaignName, modelName); });
if (model != null) if (model != null)
{ {
model.Position = pos; model.Position = pos;

View File

@ -23,18 +23,18 @@ public class ModelLoader
{ {
if (_cache.TryGetValue((campaignName, modelName), out var fmModel)) if (_cache.TryGetValue((campaignName, modelName), out var fmModel))
{ {
return fmModel == null ? fmModel : fmModel.Duplicate() as MeshInstance3D; return fmModel?.Duplicate() as MeshInstance3D;
} }
else if (_cache.TryGetValue(("", modelName), out var omModel)) else if (_cache.TryGetValue(("", modelName), out var omModel))
{ {
return omModel == null ? omModel : omModel.Duplicate() as MeshInstance3D; return omModel?.Duplicate() as MeshInstance3D;
} }
} }
// We don't care if this is null actually, we'll still cache that it's null lol // We don't care if this is null actually, we'll still cache that it's null lol
var model = LoadModel(_pathManager, ref campaignName, modelName); var model = Timing.TimeStage("Load Models", () => { return LoadModel(_pathManager, ref campaignName, modelName); });
_cache[(campaignName, modelName)] = model; _cache[(campaignName, modelName)] = model;
return model == null ? model : model.Duplicate() as MeshInstance3D; return model;
} }
public static MeshInstance3D LoadModel(ResourcePathManager pathManager, ref string campaignName, string modelName) public static MeshInstance3D LoadModel(ResourcePathManager pathManager, ref string campaignName, string modelName)

View File

@ -14,16 +14,9 @@ public partial class TextureLoader
var width = gifImage.Width; var width = gifImage.Width;
var height = gifImage.Height; var height = gifImage.Height;
var image = Image.CreateEmpty(width, height, false, Image.Format.Rgba8); var bytes = new byte[width * height * 4];
for (var y = 0; y < height; y++) gifImage.CopyPixelDataTo(bytes);
{ var image = Image.CreateFromData(width, height, false, Image.Format.Rgba8, bytes);
for (var x = 0; x < width; x++)
{
var pixel = gifImage[x, y].ToVector4();
image.SetPixel(x, y, new Color(pixel.X, pixel.Y, pixel.Z, pixel.W));
}
}
return ImageTexture.CreateFromImage(image); return ImageTexture.CreateFromImage(image);
} }
} }