From a444382f9bcf8e42ef9fefea20d5ed76fec22095 Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Wed, 20 Apr 2022 11:45:31 -0400 Subject: [PATCH] optimization of AA tile avoidance for astral worldgen --- World/AstralBiome.cs | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/World/AstralBiome.cs b/World/AstralBiome.cs index 892aca972e..9a0831bf58 100644 --- a/World/AstralBiome.cs +++ b/World/AstralBiome.cs @@ -95,6 +95,29 @@ namespace CalamityMod.World UnifiedRandom rand = WorldGen.genRand; float solidTileRequirement = 600f; bool localAbyssSide = WorldGen.dungeonX < Main.maxTilesX / 2; + + // Pre-cache a list of Ancients Awakened tiles to avoid, for performance reasons + IList aaTilesToAvoid = new List(16); + if (ancientsAwakened is not null) + { + string[] aaTileNames = new string[] + { + "InfernoGrass", + "Torchstone", + "Torchsand", + "Torchsandstone", + "Torchsandhardened", + "Torchice", + "Depthstone", + "Depthsand", + "Depthsandstone", + "Depthsandhardened", + "Depthice", + }; + foreach (string tileName in aaTileNames) + aaTilesToAvoid.Add(ancientsAwakened.Find(tileName).Type); + } + while (!meteorDropped) { float worldEdgeMargin = (float)Main.maxTilesX * 0.08f; @@ -132,19 +155,8 @@ namespace CalamityMod.World } // Prevent the Astral biome from overriding or interfering with an AA biome - // TODO -- horrifically unoptimized. Oh my god this is the worst thing I have ever seen - else if (ancientsAwakened != null) - { - if (Main.tile[l, m].TileType == ancientsAwakened.Find("InfernoGrass") .Type|| Main.tile[l, m].TileType == ancientsAwakened.Find("Torchstone") .Type|| - Main.tile[l, m].TileType == ancientsAwakened.Find("Torchsand") .Type|| Main.tile[l, m].TileType == ancientsAwakened.Find("Torchsandstone") .Type|| - Main.tile[l, m].TileType == ancientsAwakened.Find("Torchsandhardened") .Type|| Main.tile[l, m].TileType == ancientsAwakened.Find("Torchice") .Type|| - Main.tile[l, m].TileType == ancientsAwakened.Find("Depthstone") .Type|| Main.tile[l, m].TileType == ancientsAwakened.Find("Depthsand") .Type|| - Main.tile[l, m].TileType == ancientsAwakened.Find("Depthsandstone") .Type|| Main.tile[l, m].TileType == ancientsAwakened.Find("Depthsandhardened") .Type|| - Main.tile[l, m].TileType == ancientsAwakened.Find("Depthice").Type) - { - suitableTiles -= 100; - } - } + else if (ancientsAwakened is not null && aaTilesToAvoid.Contains(Main.tile[l, m].TileType)) + suitableTiles -= 100; } // Liquid aversion makes meteors less likely to fall in lakes