From d9b513e88c4befd2a717aae6136fef7e4bc2b190 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 7 Oct 2023 20:32:08 -0400 Subject: [PATCH] cell count cached --- src/engine/InterestManagement/HeightMap.java | 32 ++++++++------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/engine/InterestManagement/HeightMap.java b/src/engine/InterestManagement/HeightMap.java index 566977cd..03d3df1f 100644 --- a/src/engine/InterestManagement/HeightMap.java +++ b/src/engine/InterestManagement/HeightMap.java @@ -56,6 +56,8 @@ public class HeightMap { public float bucketWidthY; public float seaLevel = 0; public int[][] pixelColorValues; + public int bucketCountX; + public int bucketCountY; public float zone_minBlend; public float zone_maxBlend; @@ -95,13 +97,11 @@ public class HeightMap { // Calculate the data we do not load from table - float numOfBucketsX = this.heightmapImage.getWidth() - 1; - float calculatedWidthX = this.fullExtentsX / numOfBucketsX; - this.bucketWidthX = calculatedWidthX; + bucketCountX = this.heightmapImage.getWidth() - 1; + this.bucketWidthX = this.fullExtentsX / bucketCountX; - float numOfBucketsY = this.heightmapImage.getHeight() - 1; - float calculatedWidthY = this.fullExtentsY / numOfBucketsY; - this.bucketWidthY = calculatedWidthY; + bucketCountY = this.heightmapImage.getHeight() - 1; + this.bucketWidthY = this.fullExtentsY / bucketCountY; // Generate pixel array from image data @@ -325,22 +325,16 @@ public class HeightMap { public Vector2f getGridSquare(Vector2f zoneLoc) { - // Clamp values. - - if (zoneLoc.x < 0) - zoneLoc.setX(0); - - if (zoneLoc.x >= this.fullExtentsX) - zoneLoc.setX(this.fullExtentsX); + float xBucket = (zoneLoc.x / this.bucketWidthX); + float yBucket = (zoneLoc.y / this.bucketWidthY); - if (zoneLoc.y < 0) - zoneLoc.setY(0); + // Standing on the pole - if (zoneLoc.y > this.fullExtentsY) - zoneLoc.setY(this.fullExtentsY); + if (xBucket == this.bucketCountX) + xBucket--; - float xBucket = (zoneLoc.x / this.bucketWidthX); - float yBucket = (zoneLoc.y / this.bucketWidthY); + if (yBucket == this.bucketCountY) + yBucket--; return new Vector2f(xBucket, yBucket); }