From 3caf532516b59825c98bfb60d1a9fca008ab01a2 Mon Sep 17 00:00:00 2001 From: kaczy Date: Mon, 23 Sep 2024 15:29:56 +0200 Subject: [PATCH] Proper cleanup of expired animated and light tiles. Marked some logs as debug logs More info in debug window --- CentrED/Map/LandObject.cs | 10 ++++++---- CentrED/Map/MapManager.cs | 9 +++++++++ CentrED/Map/StaticObject.cs | 6 ++++-- CentrED/UI/Windows/DebugWindow.cs | 2 ++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CentrED/Map/LandObject.cs b/CentrED/Map/LandObject.cs index f3811ad..949698f 100644 --- a/CentrED/Map/LandObject.cs +++ b/CentrED/Map/LandObject.cs @@ -67,13 +67,14 @@ public void UpdateCorners(ushort id) public void UpdateId(ushort newId) { + var mapManager = Application.CEDGame.MapManager; SpriteInfo spriteInfo = default; var isStretched = !IsFlat (Vertices[0].Position.Z, Vertices[1].Position.Z, Vertices[2].Position.Z, Vertices[3].Position.Z); var isTexMapValid = TexmapsLoader.Instance.GetValidRefEntry(newId).Length > 0; var isLandTileValid = ArtLoader.Instance.GetValidRefEntry(newId).Length > 0; var alwaysFlat = AlwaysFlat(newId); - if (Application.CEDGame.MapManager.FlatView) + if (mapManager.FlatView) { isStretched = false; for (int i = 0; i < 4; i++) @@ -94,18 +95,19 @@ public void UpdateId(ushort newId) { if (useTexMap) { - spriteInfo = Application.CEDGame.MapManager.Texmaps.GetTexmap(TileDataLoader.Instance.LandData[newId].TexID); + spriteInfo = mapManager.Texmaps.GetTexmap(TileDataLoader.Instance.LandData[newId].TexID); } else { - spriteInfo = Application.CEDGame.MapManager.Arts.GetLand(newId); + spriteInfo = mapManager.Arts.GetLand(newId); } } if (spriteInfo.Equals(SpriteInfo.Empty)) { - Console.WriteLine($"No texture found for land {Tile.X},{Tile.Y},{Tile.Z}:0x{newId:X}, texmap:{useTexMap}"); + if(mapManager.DebugLogging) + Console.WriteLine($"No texture found for land {Tile.X},{Tile.Y},{Tile.Z}:0x{newId:X}, texmap:{useTexMap}"); //VOID texture is by default all pink, so it should be noticeable that something is not right spriteInfo = Application.CEDGame.MapManager.Texmaps.GetTexmap(0x0001); } diff --git a/CentrED/Map/MapManager.cs b/CentrED/Map/MapManager.cs index b0db7c4..aee66af 100644 --- a/CentrED/Map/MapManager.cs +++ b/CentrED/Map/MapManager.cs @@ -530,6 +530,14 @@ public void RemoveTiles(ushort x, ushort y) foreach (var staticObject in so) { AllTiles.Remove(staticObject.ObjectId); + if (staticObject.IsAnimated) + { + AnimatedStaticTiles.Remove(staticObject); + } + if (staticObject.IsLight) + { + LightTiles.Remove(staticObject); + } } } } @@ -785,6 +793,7 @@ public void Reset() { LandTiles = new LandObject[Client.Width * 8, Client.Height * 8]; StaticTiles = new List[Client.Width * 8, Client.Height * 8]; + AnimatedStaticTiles.Clear(); GhostLandTiles.Clear(); GhostStaticTiles.Clear(); LightTiles.Clear(); diff --git a/CentrED/Map/StaticObject.cs b/CentrED/Map/StaticObject.cs index ffbf167..e4ca497 100644 --- a/CentrED/Map/StaticObject.cs +++ b/CentrED/Map/StaticObject.cs @@ -42,10 +42,12 @@ public void UpdateId() public void UpdateId(ushort newId) { ref var index = ref ArtLoader.Instance.GetValidRefEntry(newId + 0x4000); - var spriteInfo = Application.CEDGame.MapManager.Arts.GetArt((uint)(newId + index.AnimOffset)); + var mapManager = Application.CEDGame.MapManager; + var spriteInfo = mapManager.Arts.GetArt((uint)(newId + index.AnimOffset)); if (spriteInfo.Equals(SpriteInfo.Empty)) { - Console.WriteLine($"No texture found for static {Tile.X},{Tile.Y},{Tile.Z}:0x{newId:X}"); + if(mapManager.DebugLogging) + Console.WriteLine($"No texture found for static {Tile.X},{Tile.Y},{Tile.Z}:0x{newId:X}"); //VOID texture of land is by default all pink, so it should be noticeable that something is not right spriteInfo = Application.CEDGame.MapManager.Texmaps.GetTexmap(0x0001); } diff --git a/CentrED/UI/Windows/DebugWindow.cs b/CentrED/UI/Windows/DebugWindow.cs index 397d7e8..2dc215a 100644 --- a/CentrED/UI/Windows/DebugWindow.cs +++ b/CentrED/UI/Windows/DebugWindow.cs @@ -44,6 +44,8 @@ private void DrawGeneralTab() ); ImGui.Text($"Land tiles: {mapManager.LandTilesCount}"); ImGui.Text($"Static tiles: {mapManager.StaticTilesCount}"); + ImGui.Text($"Animated Static tiles: {mapManager.AnimatedStaticTiles.Count}"); + ImGui.Text($"Light Tiles: {mapManager.LightTiles.Count}"); ImGui.Text($"Camera focus tile {mapManager.Camera.LookAt / TileObject.TILE_SIZE}"); var mousePos = ImGui.GetMousePos(); ImGui.Text