From 7bf31f9a475720c9894c15be8078f5b32d0734cc Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 11 Sep 2023 11:01:09 -0400 Subject: [PATCH] Rework of class interface. --- src/engine/InterestManagement/HeightMap.java | 170 ++----------------- src/engine/devcmd/cmds/GetHeightCmd.java | 2 +- src/engine/objects/AbstractWorldObject.java | 2 +- src/engine/objects/PlayerCharacter.java | 4 +- 4 files changed, 14 insertions(+), 164 deletions(-) diff --git a/src/engine/InterestManagement/HeightMap.java b/src/engine/InterestManagement/HeightMap.java index 3909028d..ea5edd99 100644 --- a/src/engine/InterestManagement/HeightMap.java +++ b/src/engine/InterestManagement/HeightMap.java @@ -14,7 +14,6 @@ import engine.gameManager.DbManager; import engine.gameManager.ZoneManager; import engine.math.Vector2f; import engine.math.Vector3fImmutable; -import engine.objects.AbstractWorldObject; import engine.objects.Zone; import engine.util.MapLoader; import org.pmw.tinylog.Logger; @@ -222,27 +221,29 @@ public class HeightMap { return nextZone; } - public static float getWorldHeight(AbstractWorldObject worldObject) { + public static float getWorldHeight(Zone currentZone, Vector3fImmutable worldLoc) { Vector2f parentLoc = new Vector2f(-1, -1); - Zone currentZone = ZoneManager.findSmallestZone(worldObject.getLoc()); if (currentZone == null) - return worldObject.getAltitude(); + return 0; currentZone = getNextZoneWithTerrain(currentZone); if (currentZone == ZoneManager.getSeaFloor()) - return currentZone.getAbsY() + worldObject.getAltitude(); + return currentZone.getAbsY(); Zone parentZone = getNextZoneWithTerrain(currentZone.getParent()); HeightMap heightMap = currentZone.getHeightMap(); - Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldObject.getLoc(), currentZone); - Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldObject.getLoc(), currentZone); + if ((heightMap == null) || (currentZone == ZoneManager.getSeaFloor())) + return currentZone.getAbsY(); + + Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldLoc, currentZone); + Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldLoc, currentZone); if ((parentZone != null) && (parentZone.getHeightMap() != null)) - parentLoc = ZoneManager.worldToZoneSpace(worldObject.getLoc(), parentZone); + parentLoc = ZoneManager.worldToZoneSpace(worldLoc, parentZone); float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); @@ -263,18 +264,6 @@ public class HeightMap { float bucketScaleX = heightMap.outsetX / parentXRadius; float bucketScaleZ = heightMap.outsetZ / parentZRadius; - if (bucketScaleX <= 0.40000001) - bucketScaleX = heightMap.outsetZ / parentXRadius; - - if (bucketScaleX > 0.40000001) - bucketScaleX = 0.40000001f; - - if (bucketScaleZ <= 0.40000001) - bucketScaleZ = heightMap.outsetX / parentZRadius; - - if (bucketScaleZ > 0.40000001) - bucketScaleZ = 0.40000001f; - float outsideGridSizeX = 1 - bucketScaleX; //32/256 float outsideGridSizeZ = 1 - bucketScaleZ; float weight; @@ -327,100 +316,12 @@ public class HeightMap { public static float getWorldHeight(Vector3fImmutable worldLoc) { - Vector2f parentLoc = new Vector2f(-1, -1); Zone currentZone = ZoneManager.findSmallestZone(worldLoc); if (currentZone == null) return 0; + return getWorldHeight(currentZone, worldLoc); - currentZone = getNextZoneWithTerrain(currentZone); - - if (currentZone == ZoneManager.getSeaFloor()) - return currentZone.getAbsY(); - - Zone parentZone = getNextZoneWithTerrain(currentZone.getParent()); - HeightMap heightMap = currentZone.getHeightMap(); - - if ((heightMap == null) || (currentZone == ZoneManager.getSeaFloor())) - return currentZone.getAbsY(); - - Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldLoc, currentZone); - Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldLoc, currentZone); - - if ((parentZone != null) && (parentZone.getHeightMap() != null)) - parentLoc = ZoneManager.worldToZoneSpace(worldLoc, parentZone); - - float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); - - float worldAltitude = currentZone.getWorldAltitude(); - - float realWorldAltitude = interaltitude + worldAltitude; - - //OUTSET - - if (parentZone != null) { - - // if (currentZone.getHeightMap() != null && parentZone.getHeightMap() != null && parentZone.getParent() != null && parentZone.getParent().getHeightMap() != null) - // return realWorldAltitude; - - float parentXRadius = currentZone.getBounds().getHalfExtents().x; - float parentZRadius = currentZone.getBounds().getHalfExtents().y; - - float offsetX = Math.abs((localLocFromCenter.x / parentXRadius)); - float offsetZ = Math.abs((localLocFromCenter.z / parentZRadius)); - - float bucketScaleX = heightMap.outsetX / parentXRadius; - float bucketScaleZ = heightMap.outsetZ / parentZRadius; - - float outsideGridSizeX = 1 - bucketScaleX; //32/256 - float outsideGridSizeZ = 1 - bucketScaleZ; - float weight; - - double scale; - - - if (offsetX > outsideGridSizeX && offsetX > offsetZ) { - weight = (offsetX - outsideGridSizeX) / bucketScaleX; - scale = Math.atan2((.5 - weight) * 3.1415927, 1); - - float scaleChild = (float) ((scale + 1) * .5); - float scaleParent = 1 - scaleChild; - - float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc); - float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone)); - - parentCenterAltitude += currentZone.getYCoord(); - parentCenterAltitude += interaltitude; - - float firstScale = parentAltitude * scaleParent; - float secondScale = parentCenterAltitude * scaleChild; - float outsetALt = firstScale + secondScale; - - outsetALt += currentZone.getParent().getWorldAltitude(); - realWorldAltitude = outsetALt; - - } else if (offsetZ > outsideGridSizeZ) { - - weight = (offsetZ - outsideGridSizeZ) / bucketScaleZ; - scale = Math.atan2((.5 - weight) * 3.1415927, 1); - - float scaleChild = (float) ((scale + 1) * .5); - float scaleParent = 1 - scaleChild; - float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc); - float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone)); - - parentCenterAltitude += currentZone.getYCoord(); - parentCenterAltitude += interaltitude; - float firstScale = parentAltitude * scaleParent; - float secondScale = parentCenterAltitude * scaleChild; - float outsetALt = firstScale + secondScale; - - outsetALt += currentZone.getParent().getWorldAltitude(); - realWorldAltitude = outsetALt; - } - } - - return realWorldAltitude; } public static float getOutsetHeight(float interpolatedAltitude, Zone zone, Vector3fImmutable worldLocation) { @@ -496,15 +397,6 @@ public class HeightMap { return outsetALt; } - public static Vector2f getGridOffset(Vector2f gridSquare) { - - int floorX = (int) gridSquare.x; - int floorY = (int) gridSquare.y; - - return new Vector2f(gridSquare.x - floorX, gridSquare.y - floorY); - - } - public static void loadAlHeightMaps() { // Load the heightmaps into staging hashmap keyed by HashMapID @@ -618,48 +510,6 @@ public class HeightMap { return interpolatedHeight; } - public float getInterpolatedTerrainHeight(Vector3fImmutable zoneLoc3f) { - - Vector2f zoneLoc = new Vector2f(zoneLoc3f.x, zoneLoc3f.z); - - Vector2f gridSquare; - - if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX) - return -1; - - if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY) - return -1; - - //flip the Y so it grabs from the bottom left instead of top left. - //zoneLoc.setY(maxZoneHeight - zoneLoc.y); - - gridSquare = getGridSquare(zoneLoc); - - int gridX = (int) gridSquare.x; - int gridY = (int) (gridSquare.y); - - float offsetX = (gridSquare.x - gridX); - float offsetY = gridSquare.y - gridY; - - //get height of the 4 vertices. - - float topLeftHeight = pixelColorValues[gridX][gridY]; - float topRightHeight = pixelColorValues[gridX + 1][gridY]; - float bottomLeftHeight = pixelColorValues[gridX][gridY + 1]; - float bottomRightHeight = pixelColorValues[gridX + 1][gridY + 1]; - - float interpolatedHeight; - - interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX); - interpolatedHeight += (bottomRightHeight * offsetY * offsetX); - interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY); - interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY)); - - interpolatedHeight *= (float) this.maxHeight / 256; // Scale height - - return interpolatedHeight; - } - private void generatePixelData() { Color color; diff --git a/src/engine/devcmd/cmds/GetHeightCmd.java b/src/engine/devcmd/cmds/GetHeightCmd.java index a9bed6ad..a5dc2a1f 100644 --- a/src/engine/devcmd/cmds/GetHeightCmd.java +++ b/src/engine/devcmd/cmds/GetHeightCmd.java @@ -28,7 +28,7 @@ public class GetHeightCmd extends AbstractDevCmd { AbstractGameObject target) { - float height = HeightMap.getWorldHeight(pc); + float height = HeightMap.getWorldHeight(pc.getLoc()); this.throwbackInfo(pc, "Altitude : " + height); diff --git a/src/engine/objects/AbstractWorldObject.java b/src/engine/objects/AbstractWorldObject.java index 5f087a55..4525dc65 100644 --- a/src/engine/objects/AbstractWorldObject.java +++ b/src/engine/objects/AbstractWorldObject.java @@ -502,7 +502,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject { return; this.lastLoc = new Vector3fImmutable(this.loc); this.loc = loc; - this.loc = this.loc.setY(HeightMap.getWorldHeight(this) + this.getAltitude()); + this.loc = this.loc.setY(HeightMap.getWorldHeight(this.getLoc()) + this.getAltitude()); //lets not add mob to world grid if he is currently despawned. if (this.getObjectType().equals(GameObjectType.Mob) && ((Mob) this).despawned) diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index c013f277..cc09fd56 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -4834,7 +4834,7 @@ public class PlayerCharacter extends AbstractCharacter { } else this.altitude = this.getDesiredAltitude(); - this.loc = this.loc.setY(HeightMap.getWorldHeight(this) + this.getAltitude()); + this.loc = this.loc.setY(HeightMap.getWorldHeight(this.getLoc()) + this.getAltitude()); this.setTakeOffTime(0); MovementManager.finishChangeAltitude(this, this.getDesiredAltitude()); @@ -4842,7 +4842,7 @@ public class PlayerCharacter extends AbstractCharacter { return; } - this.loc = this.loc.setY(HeightMap.getWorldHeight(this) + this.getAltitude()); + this.loc = this.loc.setY(HeightMap.getWorldHeight(this.getLoc()) + this.getAltitude()); } public boolean hasBoon() {