From 045ee73b61a8c426a5160d447d9454aeb0e65a5a Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 12 Sep 2023 14:51:04 -0400 Subject: [PATCH] rework of world altitude calculation. --- src/engine/InterestManagement/HeightMap.java | 6 +-- src/engine/devcmd/cmds/GetHeightCmd.java | 5 -- src/engine/devcmd/cmds/ZoneInfoCmd.java | 2 +- src/engine/gameManager/ZoneManager.java | 20 ++++++++ .../client/handlers/PlaceAssetMsgHandler.java | 3 +- src/engine/objects/Zone.java | 49 +------------------ src/engine/server/world/WorldServer.java | 3 +- 7 files changed, 28 insertions(+), 60 deletions(-) diff --git a/src/engine/InterestManagement/HeightMap.java b/src/engine/InterestManagement/HeightMap.java index 8193fdf1..869d806a 100644 --- a/src/engine/InterestManagement/HeightMap.java +++ b/src/engine/InterestManagement/HeightMap.java @@ -232,7 +232,7 @@ public class HeightMap { float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); - float worldAltitude = currentZone.getWorldAltitude(); + float worldAltitude = currentZone.worldAltitude; float realWorldAltitude = interaltitude + worldAltitude; @@ -272,7 +272,7 @@ public class HeightMap { float secondScale = parentCenterAltitude * scaleChild; float outsetALt = firstScale + secondScale; - outsetALt += currentZone.getParent().getWorldAltitude(); + outsetALt += currentZone.getParent().worldAltitude; realWorldAltitude = outsetALt; } else if (offsetZ > outsideGridSizeZ) { @@ -291,7 +291,7 @@ public class HeightMap { float secondScale = parentCenterAltitude * scaleChild; float outsetALt = firstScale + secondScale; - outsetALt += currentZone.getParent().getWorldAltitude(); + outsetALt += currentZone.getParent().worldAltitude; realWorldAltitude = outsetALt; } } diff --git a/src/engine/devcmd/cmds/GetHeightCmd.java b/src/engine/devcmd/cmds/GetHeightCmd.java index 5e3c73aa..f2d61089 100644 --- a/src/engine/devcmd/cmds/GetHeightCmd.java +++ b/src/engine/devcmd/cmds/GetHeightCmd.java @@ -36,11 +36,6 @@ public class GetHeightCmd extends AbstractDevCmd { heightmapZone = HeightMap.getNextZoneWithTerrain(currentZone); parentZone = HeightMap.getNextZoneWithTerrain(currentZone.getParent()); - // Any argument rebuilds altitude - - if (words[0].isEmpty() == false) - currentZone.generateWorldAltitude(); - float currentHeight = HeightMap.getWorldHeight(currentZone, playerCharacter.getLoc()); float parentHeight = HeightMap.getWorldHeight(parentZone, playerCharacter.getLoc()); diff --git a/src/engine/devcmd/cmds/ZoneInfoCmd.java b/src/engine/devcmd/cmds/ZoneInfoCmd.java index 09f03b83..37325aef 100644 --- a/src/engine/devcmd/cmds/ZoneInfoCmd.java +++ b/src/engine/devcmd/cmds/ZoneInfoCmd.java @@ -104,7 +104,7 @@ public class ZoneInfoCmd extends AbstractDevCmd { output += newline; output += "Sea Level = " + zone.getSeaLevel(); output += newline; - output += "World Altitude = " + zone.getWorldAltitude(); + output += "World Altitude = " + zone.worldAltitude; throwbackInfo(player, output); City city = ZoneManager.getCityAtLocation(player.getLoc()); diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 8802744e..925c75a9 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -9,6 +9,7 @@ package engine.gameManager; import engine.Enum; +import engine.InterestManagement.HeightMap; import engine.db.archive.CityRecord; import engine.db.archive.DataWarehouse; import engine.math.Bounds; @@ -453,4 +454,23 @@ public enum ZoneManager { } } } + + public static float caclulateWorldAltitude(Zone zone) { + + float worldAlttitude = MBServerStatics.SEA_FLOOR_ALTITUDE; + + if (getSeaFloor().getObjectUUID() == zone.getObjectUUID()) { + return worldAlttitude; + } + + Zone parentZone = zone.getParent(); + + if (getSeaFloor().getObjectUUID() == parentZone.getObjectUUID()) { + return worldAlttitude + zone.getYCoord(); + } + + worldAlttitude = HeightMap.getWorldHeight(parentZone, zone.getLoc()); + + return worldAlttitude; + } } diff --git a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java index 382b6547..1fca649b 100644 --- a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java +++ b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java @@ -792,10 +792,11 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler { ZoneManager.addPlayerCityZone(zoneObject); serverZone.addNode(zoneObject); - zoneObject.generateWorldAltitude(); + zoneObject.worldAltitude = ZoneManager.caclulateWorldAltitude(zoneObject); cityObject.setParent(zoneObject); cityObject.setObjectTypeMask(MBServerStatics.MASK_CITY); // *** Refactor : should have it already + //Link the tree of life with the new zone treeObject.setObjectTypeMask(MBServerStatics.MASK_BUILDING); diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index 45314553..21dc294e 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -56,7 +56,7 @@ public class Zone extends AbstractGameObject { private boolean isNPCCity = false; private boolean isPlayerCity = false; private String hash; - private float worldAltitude = 0; + public float worldAltitude = 0; private float seaLevel = 0; //public static ArrayList respawnQue = new ArrayList<>(); public static final Set respawnQue = Collections.newSetFromMap(new ConcurrentHashMap<>()); @@ -220,49 +220,6 @@ public class Zone extends AbstractGameObject { return Icon1; } - public void generateWorldAltitude() { - - if (ZoneManager.getSeaFloor().getObjectUUID() == this.getObjectUUID()) { - this.worldAltitude = MBServerStatics.SEA_FLOOR_ALTITUDE; - return; - } - - Zone parentZone = this.parent; - - Zone currentZone = this; - float altitude = this.absY; - - //seafloor only zone with null parent; - - while (parentZone != ZoneManager.getSeaFloor()) { - - if (parentZone.getHeightMap() != null) { - - Vector2f zoneLoc = ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone); - altitude += parentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); - - } - currentZone = parentZone; - parentZone = parentZone.parent; - - } - - this.worldAltitude = altitude; - - if (ZoneManager.getSeaFloor().equals(this)) - this.seaLevel = 0; - else if - (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() == 0) { - this.seaLevel = this.parent.seaLevel; - - } else if (this.getHeightMap() != null) { - this.seaLevel = this.worldAltitude + this.getHeightMap().getSeaLevel(); - } else { - this.seaLevel = this.parent.seaLevel; - } - - } - public Zone getParent() { return this.parent; } @@ -420,8 +377,4 @@ public class Zone extends AbstractGameObject { return seaLevel; } - public float getWorldAltitude() { - return worldAltitude; - } - } diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 1eb95eb2..413fc74b 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -566,8 +566,7 @@ public class WorldServer { for (Zone zone : rootParent) { ZoneManager.addZone(zone.getLoadNum(), zone); - zone.generateWorldAltitude(); - + zone.worldAltitude = ZoneManager.caclulateWorldAltitude(zone); //Handle Buildings