From 6d665302d2a5e712aabe129dbf52b7a4d2e10957 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sat, 5 Oct 2024 18:13:30 +0100 Subject: [PATCH] Make Lightmap a class and add AddLayer method --- .../Database/Chunks/WorldRep.cs | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/KeepersCompound.LGS/Database/Chunks/WorldRep.cs b/KeepersCompound.LGS/Database/Chunks/WorldRep.cs index 85a3f86..b08cf8c 100644 --- a/KeepersCompound.LGS/Database/Chunks/WorldRep.cs +++ b/KeepersCompound.LGS/Database/Chunks/WorldRep.cs @@ -150,7 +150,7 @@ public class WorldRep : IChunk } } - public struct Lightmap + public class Lightmap { public List Pixels { get; set; } @@ -174,7 +174,7 @@ public class WorldRep : IChunk Bpp = bytesPerPixel; } - public readonly Vector4 GetPixel(uint layer, uint x, uint y) + public Vector4 GetPixel(uint layer, uint x, uint y) { if (layer >= Layers || x >= Width || y >= Height) { @@ -198,7 +198,7 @@ public class WorldRep : IChunk } } - public readonly byte[] AsBytesRgba(int layer) + public byte[] AsBytesRgba(int layer) { ArgumentOutOfRangeException.ThrowIfLessThan(layer, 0, nameof(layer)); ArgumentOutOfRangeException.ThrowIfGreaterThan(layer, Layers, nameof(layer)); @@ -238,7 +238,7 @@ public class WorldRep : IChunk } // TODO: This ONLY works for rgba (bpp = 4)!!! - public readonly void AddLight(int layer, int x, int y, float r, float g, float b) + public void AddLight(int layer, int x, int y, float r, float g, float b) { var idx = (x + y * Width) * Bpp; var pLayer = Pixels[layer]; @@ -248,7 +248,7 @@ public class WorldRep : IChunk pLayer[idx + 3] = 255; } - public readonly void AddLight(int layer, int x, int y, Vector3 color, float strength, bool hdr) + public void AddLight(int layer, int x, int y, Vector3 color, float strength, bool hdr) { if (hdr) { @@ -276,15 +276,9 @@ public class WorldRep : IChunk public void Reset(Vector3 ambientLight, bool hdr) { - var bytesPerLayer = Width * Height * Bpp; + Layers = 0; Pixels.Clear(); - Pixels.Add(new byte[bytesPerLayer]); - Layers = 1; - - for (var j = 0; j < bytesPerLayer; j++) - { - Pixels[0][j] = 0; - } + AddLayer(); for (var y = 0; y < Height; y++) { @@ -295,7 +289,18 @@ public class WorldRep : IChunk } } - public readonly void Write(BinaryWriter writer) + public void AddLayer() + { + var bytesPerLayer = Width * Height * Bpp; + Pixels.Add(new byte[bytesPerLayer]); + for (var j = 0; j < bytesPerLayer; j++) + { + Pixels[Layers][j] = 0; + } + Layers++; + } + + public void Write(BinaryWriter writer) { foreach (var layer in Pixels) {