Skip to content

Commit 4511629

Browse files
feat: add DungeonMapColorParser caching from upstream
1 parent 0552b40 commit 4511629

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/cataclysmicmap/handlers/DungeonMapColorParser.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import net.minecraft.world.storage.MapData
2525
object DungeonMapColorParser {
2626
private var centerColors: ByteArray = ByteArray(121)
2727
private var sideColors: ByteArray = ByteArray(121)
28+
private var cachedTiles: Array<Tile?> = Array(121) { null }
2829

2930
private var halfRoom = -1
3031
private var halfTile = -1
@@ -39,9 +40,12 @@ object DungeonMapColorParser {
3940

4041
centerColors = ByteArray(121)
4142
sideColors = ByteArray(121)
43+
cachedTiles = Array(121) { null }
4244
}
4345

4446
fun updateMap(mapData: MapData) {
47+
cachedTiles = Array(121) { null }
48+
4549
for (y in 0..10) {
4650
for (x in 0..10) {
4751
val mapX = startX + x * halfTile
@@ -71,10 +75,13 @@ object DungeonMapColorParser {
7175

7276
fun getTile(arrayX: Int, arrayY: Int): Tile {
7377
val index = arrayY * 11 + arrayX
74-
if (index >= 121) return Unknown(0, 0)
75-
val xPos = DungeonScanner.startX + arrayX * (DungeonScanner.roomSize shr 1)
76-
val zPos = DungeonScanner.startZ + arrayY * (DungeonScanner.roomSize shr 1)
77-
return scanTile(arrayX, arrayY, xPos, zPos)
78+
val cached = cachedTiles.getOrElse(index) { return Unknown(0, 0) }
79+
if (cached == null) {
80+
val xPos = DungeonScanner.startX + arrayX * (DungeonScanner.roomSize shr 1)
81+
val zPos = DungeonScanner.startZ + arrayY * (DungeonScanner.roomSize shr 1)
82+
cachedTiles[index] = scanTile(arrayX, arrayY, xPos, zPos)
83+
}
84+
return cachedTiles[index] ?: Unknown(0, 0)
7885
}
7986

8087
private fun scanTile(arrayX: Int, arrayY: Int, worldX: Int, worldZ: Int): Tile {

0 commit comments

Comments
 (0)