From df54840a88fdb9c1d716840e174f45e59dcd4587 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 8 Oct 2023 09:59:13 -0400 Subject: [PATCH] Completed partial refactor. --- src/engine/InterestManagement/Terrain.java | 6 +-- .../db/handlers/dbHeightMapHandler.java | 43 ------------------- src/engine/devcmd/cmds/GetHeightCmd.java | 3 +- src/engine/devcmd/cmds/ZoneInfoCmd.java | 9 ++-- src/engine/gameManager/DbManager.java | 1 - src/engine/objects/Zone.java | 37 ++++++++-------- 6 files changed, 27 insertions(+), 72 deletions(-) delete mode 100644 src/engine/db/handlers/dbHeightMapHandler.java diff --git a/src/engine/InterestManagement/Terrain.java b/src/engine/InterestManagement/Terrain.java index 73c7aa9e..328ff890 100644 --- a/src/engine/InterestManagement/Terrain.java +++ b/src/engine/InterestManagement/Terrain.java @@ -41,13 +41,13 @@ public class Terrain { Zone terrain_zone = zone; - if (zone.getHeightMap() != null) + if (zone.terrain != null) return zone; if (zone.equals(ZoneManager.getSeaFloor())) return zone; - while (terrain_zone.getHeightMap() == null) + while (terrain_zone.terrain == null) terrain_zone = terrain_zone.parent; return terrain_zone; @@ -74,7 +74,7 @@ public class Terrain { // Interpolate height for this position using pixel array. - float interpolatedTerrainHeight = terrainZone.getHeightMap().getInterpolatedTerrainHeight(terrainLoc); + float interpolatedTerrainHeight = terrainZone.terrain.getInterpolatedTerrainHeight(terrainLoc); interpolatedTerrainHeight += terrainZone.worldAltitude; return interpolatedTerrainHeight; diff --git a/src/engine/db/handlers/dbHeightMapHandler.java b/src/engine/db/handlers/dbHeightMapHandler.java deleted file mode 100644 index 87cb9428..00000000 --- a/src/engine/db/handlers/dbHeightMapHandler.java +++ /dev/null @@ -1,43 +0,0 @@ -package engine.db.handlers; - -import engine.InterestManagement.Terrain; -import engine.gameManager.DbManager; -import org.pmw.tinylog.Logger; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -public class dbHeightMapHandler extends dbHandlerBase { - - public dbHeightMapHandler() { - - - } - - public void LOAD_ALL_HEIGHTMAPS() { - - Terrain thisHeightmap; - Terrain.heightMapsCreated = 0; - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_zone_heightmap INNER JOIN static_zone_size ON static_zone_size.loadNum = static_zone_heightmap.zoneLoadID")) { - - ResultSet rs = preparedStatement.executeQuery(); - - while (rs.next()) { - thisHeightmap = new Terrain(rs); - - if (thisHeightmap.heightmapImage == null) { - Logger.info("Imagemap for " + thisHeightmap.heightMapID + " was null"); - continue; - } - } - - } catch (SQLException e) { - Logger.error(e); - } - } - -} diff --git a/src/engine/devcmd/cmds/GetHeightCmd.java b/src/engine/devcmd/cmds/GetHeightCmd.java index 1d3bc628..9663c5c6 100644 --- a/src/engine/devcmd/cmds/GetHeightCmd.java +++ b/src/engine/devcmd/cmds/GetHeightCmd.java @@ -39,7 +39,8 @@ public class GetHeightCmd extends AbstractDevCmd { float parentHeight = Terrain.getWorldHeight(parentZone, playerCharacter.getLoc()); Vector2f zoneLoc = ZoneManager.worldToZoneSpace(playerCharacter.getLoc(), heightmapZone); - Vector2f gridSquare = heightmapZone.getHeightMap().getTerrainCell(zoneLoc); + + Vector2f gridSquare = heightmapZone.terrain.getTerrainCell(zoneLoc); this.throwbackInfo(playerCharacter, "Current Zone : " + currentZone.zoneName); this.throwbackInfo(playerCharacter, "Heightmap Zone : " + heightmapZone.zoneName); diff --git a/src/engine/devcmd/cmds/ZoneInfoCmd.java b/src/engine/devcmd/cmds/ZoneInfoCmd.java index 2e0292c9..3786d1b4 100644 --- a/src/engine/devcmd/cmds/ZoneInfoCmd.java +++ b/src/engine/devcmd/cmds/ZoneInfoCmd.java @@ -90,14 +90,11 @@ public class ZoneInfoCmd extends AbstractDevCmd { output += "radius: x: " + zone.bounds.getHalfExtents().x + ", z: " + zone.bounds.getHalfExtents().y; output += newline; - if (zone.getHeightMap() != null) { - output += "HeightMap ID: " + zone.getHeightMap().heightMapID; + if (zone.terrain != null) { + output += "Terrain image: " + zone.terrain_image; output += newline; - output += "Bucket Width X : " + zone.getHeightMap().cell_size_x; - output += newline; - output += "Bucket Width Y : " + zone.getHeightMap().cell_size_y; - } + output += "radius: x: " + zone.bounds.getHalfExtents().x + ", z: " + zone.bounds.getHalfExtents().y; output += newline; // output += "minLvl = " + zone.getMinLvl() + " | maxLvl = " + zone.getMaxLvl(); diff --git a/src/engine/gameManager/DbManager.java b/src/engine/gameManager/DbManager.java index 92917a35..cbd52a3d 100644 --- a/src/engine/gameManager/DbManager.java +++ b/src/engine/gameManager/DbManager.java @@ -70,7 +70,6 @@ public enum DbManager { public static final dbBlueprintHandler BlueprintQueries = new dbBlueprintHandler(); public static final dbBoonHandler BoonQueries = new dbBoonHandler(); public static final dbShrineHandler ShrineQueries = new dbShrineHandler(); - public static final dbHeightMapHandler HeightMapQueries = new dbHeightMapHandler(); public static final dbRunegateHandler RunegateQueries = new dbRunegateHandler(); public static final dbPowerHandler PowerQueries = new dbPowerHandler(); diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index bbcafdd1..40212443 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -58,6 +58,7 @@ public class Zone extends AbstractGameObject { public String hash; public float worldAltitude = 0; public float seaLevel = 0f; + public float sea_level_offset = 0; public static final Set respawnQue = Collections.newSetFromMap(new ConcurrentHashMap<>()); public static long lastRespawn = 0; public float major_radius; @@ -224,21 +225,29 @@ public class Zone extends AbstractGameObject { this.setBounds(); this.worldAltitude = ZoneManager.caclulateWorldAltitude(this); + setSeaLevel(); + } + + private void setSeaLevel() { + + int world_sea_level = 0; + if (this.parent == null) { - this.seaLevel = MBServerStatics.SEA_FLOOR_ALTITUDE; + this.sea_level = world_sea_level; return; } - if (this.getHeightMap() == null) { - this.seaLevel = this.parent.seaLevel; - return; + switch (this.sea_level_type) { + case "WORLD": + this.sea_level = world_sea_level + this.sea_level_offset; + break; + case "PARENT": + this.sea_level = this.parent.sea_level + this.sea_level_offset; + break; + case "SELF": + this.sea_level = this.worldAltitude + this.sea_level_offset; + break; } - - if (this.getHeightMap().seaLevel != 0) - this.seaLevel = this.worldAltitude + this.getHeightMap().seaLevel; - else - this.seaLevel = this.parent.seaLevel; - } public boolean isMacroZone() { @@ -315,12 +324,4 @@ public class Zone extends AbstractGameObject { // Return heightmap for this Zone. - public Terrain getHeightMap() { - - if (this.guild_zone) - return Terrain.playerCityTerrain; - - return Terrain.heightmapByLoadNum.get(this.template); - } - }