Skip to content

Commit

Permalink
Proper cleanup of expired animated and light tiles.
Browse files Browse the repository at this point in the history
Marked some logs as debug logs
More info in debug window
  • Loading branch information
kaczy93 committed Sep 23, 2024
1 parent 601cf9e commit 3caf532
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
10 changes: 6 additions & 4 deletions CentrED/Map/LandObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -785,6 +793,7 @@ public void Reset()
{
LandTiles = new LandObject[Client.Width * 8, Client.Height * 8];
StaticTiles = new List<StaticObject>[Client.Width * 8, Client.Height * 8];
AnimatedStaticTiles.Clear();
GhostLandTiles.Clear();
GhostStaticTiles.Clear();
LightTiles.Clear();
Expand Down
6 changes: 4 additions & 2 deletions CentrED/Map/StaticObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions CentrED/UI/Windows/DebugWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3caf532

Please sign in to comment.