From 4c3dc758438a60fb4b90408c4163671bb96864a3 Mon Sep 17 00:00:00 2001 From: glutzer Date: Tue, 3 Jun 2025 13:42:30 -0500 Subject: [PATCH] Add helper methods for map data --- Datastructures/IntDataMap2D.cs | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Datastructures/IntDataMap2D.cs b/Datastructures/IntDataMap2D.cs index f3ec9d5e8..14b567687 100644 --- a/Datastructures/IntDataMap2D.cs +++ b/Datastructures/IntDataMap2D.cs @@ -154,6 +154,43 @@ public int GetColorLerpedCorrectly(float x, float z) ); } + /// + /// Takes global chunk coordinates, returns the values of the 4 corners in that region. + /// + public IntMapChunkData GetValues(int chunkX, int chunkZ) + { + if (Data.Length == 0) return new IntMapChunkData(); + + int rlX = chunkX % 16; + int rlZ = chunkZ % 16; + float factor = (float)InnerSize / 16; + + IntMapChunkData mapData; + + mapData.UpperLeft = GetUnpaddedInt((int)(rlX * factor), (int)(rlZ * factor)); + mapData.UpperRight = GetUnpaddedInt((int)((rlX * factor) + factor), (int)(rlZ * factor)); + mapData.BottomLeft = GetUnpaddedInt((int)(rlX * factor), (int)((rlZ * factor) + factor)); + mapData.BottomRight = GetUnpaddedInt((int)((rlX * factor) + factor), (int)((rlZ * factor) + factor)); + + return mapData; + } + + public struct IntMapChunkData + { + public int UpperLeft; + public int UpperRight; + public int BottomLeft; + public int BottomRight; + + public readonly float LerpForChunk(int localChunkX, int localChunkZ) + { + const float chunkBlockDelta = 1f / 32; + + float result = GameMath.BiLerp(UpperLeft, UpperRight, BottomLeft, BottomRight, localChunkX * chunkBlockDelta, localChunkZ * chunkBlockDelta); + + return result; + } + } } }