Browse Source

Start terrain refactor

magicbox-1.5.2
MagicBot 1 year ago
parent
commit
0d75e6db9b
  1. 36
      src/engine/InterestManagement/Terrain.java
  2. 8
      src/engine/db/handlers/dbHeightMapHandler.java
  3. 10
      src/engine/devcmd/cmds/GetHeightCmd.java
  4. 6
      src/engine/gameManager/PowersManager.java
  5. 6
      src/engine/gameManager/ZoneManager.java
  6. 1
      src/engine/objects/AbstractCharacter.java
  7. 4
      src/engine/objects/AbstractWorldObject.java
  8. 4
      src/engine/objects/Building.java
  9. 4
      src/engine/objects/City.java
  10. 8
      src/engine/objects/PlayerCharacter.java
  11. 14
      src/engine/objects/Zone.java
  12. 4
      src/engine/server/world/WorldServer.java

36
src/engine/InterestManagement/HeightMap.java → src/engine/InterestManagement/Terrain.java

@ -30,17 +30,17 @@ import java.sql.SQLException; @@ -30,17 +30,17 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.stream.Stream;
public class HeightMap {
public class Terrain {
// Class variables
public static final HashMap<Integer, HeightMap> heightmapByLoadNum = new HashMap<>();
public static final HashMap<Integer, Terrain> heightmapByLoadNum = new HashMap<>();
public static final HashMap<Integer, short[][]> _pixelData = new HashMap<>();
// Bootstrap Tracking
public static int heightMapsCreated = 0;
public static HeightMap PlayerCityHeightMap;
public static Terrain playerCityTerrain;
// Heightmap data for this heightmap
public final int heightMapID;
@ -60,7 +60,7 @@ public class HeightMap { @@ -60,7 +60,7 @@ public class HeightMap {
public float terrain_scale;
public HeightMap(ResultSet rs) throws SQLException {
public Terrain(ResultSet rs) throws SQLException {
this.heightMapID = rs.getInt("heightMapID");
this.maxHeight = rs.getInt("maxHeight");
@ -107,13 +107,13 @@ public class HeightMap { @@ -107,13 +107,13 @@ public class HeightMap {
generatePixelData(this);
HeightMap.heightmapByLoadNum.put(this.zoneLoadID, this);
Terrain.heightmapByLoadNum.put(this.zoneLoadID, this);
heightMapsCreated++;
}
//Created for PlayerCities
public HeightMap() {
public Terrain() {
this.heightMapID = 999999;
this.maxHeight = 5; // for real...
@ -149,7 +149,7 @@ public class HeightMap { @@ -149,7 +149,7 @@ public class HeightMap {
this.terrain_scale = this.maxHeight / 255f;
}
public HeightMap(Zone zone) {
public Terrain(Zone zone) {
this.heightMapID = 999999;
this.maxHeight = 0;
@ -185,15 +185,15 @@ public class HeightMap { @@ -185,15 +185,15 @@ public class HeightMap {
public static void GeneratePlayerCityHeightMap() {
HeightMap.PlayerCityHeightMap = new HeightMap();
Terrain.playerCityTerrain = new Terrain();
}
public static void GenerateCustomHeightMap(Zone zone) {
HeightMap heightMap = new HeightMap(zone);
Terrain heightMap = new Terrain(zone);
HeightMap.heightmapByLoadNum.put(zone.template, heightMap);
Terrain.heightmapByLoadNum.put(zone.template, heightMap);
}
@ -260,9 +260,9 @@ public class HeightMap { @@ -260,9 +260,9 @@ public class HeightMap {
//generate static player city heightmap.
HeightMap.GeneratePlayerCityHeightMap();
Terrain.GeneratePlayerCityHeightMap();
Logger.info(HeightMap.heightmapByLoadNum.size() + " Heightmaps cached.");
Logger.info(Terrain.heightmapByLoadNum.size() + " Heightmaps cached.");
// Load pixel data for heightmaps
@ -305,19 +305,19 @@ public class HeightMap { @@ -305,19 +305,19 @@ public class HeightMap {
}
private static void generatePixelData(HeightMap heightMap) {
private static void generatePixelData(Terrain terrain) {
Color color;
// Generate altitude lookup table for this heightmap
heightMap.pixelColorValues = new short[heightMap.heightmapImage.getWidth()][heightMap.heightmapImage.getHeight()];
terrain.pixelColorValues = new short[terrain.heightmapImage.getWidth()][terrain.heightmapImage.getHeight()];
for (int y = 0; y < heightMap.heightmapImage.getHeight(); y++) {
for (int x = 0; x < heightMap.heightmapImage.getWidth(); x++) {
for (int y = 0; y < terrain.heightmapImage.getHeight(); y++) {
for (int x = 0; x < terrain.heightmapImage.getWidth(); x++) {
color = new Color(heightMap.heightmapImage.getRGB(x, y));
heightMap.pixelColorValues[x][y] = (short) color.getRed();
color = new Color(terrain.heightmapImage.getRGB(x, y));
terrain.pixelColorValues[x][y] = (short) color.getRed();
}
}

8
src/engine/db/handlers/dbHeightMapHandler.java

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
package engine.db.handlers;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.Terrain;
import engine.gameManager.DbManager;
import org.pmw.tinylog.Logger;
@ -18,8 +18,8 @@ public class dbHeightMapHandler extends dbHandlerBase { @@ -18,8 +18,8 @@ public class dbHeightMapHandler extends dbHandlerBase {
public void LOAD_ALL_HEIGHTMAPS() {
HeightMap thisHeightmap;
HeightMap.heightMapsCreated = 0;
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")) {
@ -27,7 +27,7 @@ public class dbHeightMapHandler extends dbHandlerBase { @@ -27,7 +27,7 @@ public class dbHeightMapHandler extends dbHandlerBase {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
thisHeightmap = new HeightMap(rs);
thisHeightmap = new Terrain(rs);
if (thisHeightmap.heightmapImage == null) {
Logger.info("Imagemap for " + thisHeightmap.heightMapID + " was null");

10
src/engine/devcmd/cmds/GetHeightCmd.java

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
package engine.devcmd.cmds;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.Terrain;
import engine.devcmd.AbstractDevCmd;
import engine.gameManager.ZoneManager;
import engine.math.Bounds;
@ -33,11 +33,11 @@ public class GetHeightCmd extends AbstractDevCmd { @@ -33,11 +33,11 @@ public class GetHeightCmd extends AbstractDevCmd {
Zone heightmapZone;
currentZone = ZoneManager.findSmallestZone(playerCharacter.getLoc());
heightmapZone = HeightMap.getNextZoneWithTerrain(currentZone);
parentZone = HeightMap.getNextZoneWithTerrain(currentZone.parent);
heightmapZone = Terrain.getNextZoneWithTerrain(currentZone);
parentZone = Terrain.getNextZoneWithTerrain(currentZone.parent);
float currentHeight = HeightMap.getWorldHeight(currentZone, playerCharacter.getLoc());
float parentHeight = HeightMap.getWorldHeight(parentZone, playerCharacter.getLoc());
float currentHeight = Terrain.getWorldHeight(currentZone, playerCharacter.getLoc());
float parentHeight = Terrain.getWorldHeight(parentZone, playerCharacter.getLoc());
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(playerCharacter.getLoc(), heightmapZone);
Vector2f gridSquare = heightmapZone.getHeightMap().getTerrainCell(zoneLoc);

6
src/engine/gameManager/PowersManager.java

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
package engine.gameManager;
import engine.Enum.*;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.Terrain;
import engine.InterestManagement.WorldGrid;
import engine.db.handlers.dbEffectsBaseHandler;
import engine.db.handlers.dbPowerHandler;
@ -1772,7 +1772,7 @@ public enum PowersManager { @@ -1772,7 +1772,7 @@ public enum PowersManager {
} else {
targetLoc = tl;
try {
targetLoc = targetLoc.setY(HeightMap.getWorldHeight(targetLoc)); //on ground
targetLoc = targetLoc.setY(Terrain.getWorldHeight(targetLoc)); //on ground
} catch (Exception e) {
Logger.error(e);
targetLoc = tl;
@ -1974,7 +1974,7 @@ public enum PowersManager { @@ -1974,7 +1974,7 @@ public enum PowersManager {
} else {
targetLoc = tl;
try {
targetLoc = targetLoc.setY(HeightMap.getWorldHeight(targetLoc)); //on ground
targetLoc = targetLoc.setY(Terrain.getWorldHeight(targetLoc)); //on ground
} catch (Exception e) {
Logger.error(e);
}

6
src/engine/gameManager/ZoneManager.java

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
package engine.gameManager;
import engine.Enum;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.Terrain;
import engine.db.archive.CityRecord;
import engine.db.archive.DataWarehouse;
import engine.math.Bounds;
@ -468,7 +468,7 @@ public enum ZoneManager { @@ -468,7 +468,7 @@ public enum ZoneManager {
// return height from heightmap engine at zone location
worldAlttitude = HeightMap.getWorldHeight(zone.parent, zone.getLoc());
worldAlttitude = Terrain.getWorldHeight(zone.parent, zone.getLoc());
// Add zone offset to value
@ -479,7 +479,7 @@ public enum ZoneManager { @@ -479,7 +479,7 @@ public enum ZoneManager {
public static boolean isLocUnderwater(Vector3fImmutable currentLoc) {
float localAltitude = HeightMap.getWorldHeight(currentLoc);
float localAltitude = Terrain.getWorldHeight(currentLoc);
Zone zone = findSmallestZone(currentLoc);
return localAltitude < zone.seaLevel;

1
src/engine/objects/AbstractCharacter.java

@ -11,7 +11,6 @@ package engine.objects; @@ -11,7 +11,6 @@ package engine.objects;
import engine.Enum;
import engine.Enum.*;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.InterestManager;
import engine.InterestManagement.WorldGrid;
import engine.exception.SerializationException;

4
src/engine/objects/AbstractWorldObject.java

@ -13,7 +13,7 @@ import engine.Enum.DispatchChannel; @@ -13,7 +13,7 @@ import engine.Enum.DispatchChannel;
import engine.Enum.EffectSourceType;
import engine.Enum.GameObjectType;
import engine.Enum.GridObjectType;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.Terrain;
import engine.InterestManagement.WorldGrid;
import engine.job.AbstractScheduleJob;
import engine.job.JobContainer;
@ -506,7 +506,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject { @@ -506,7 +506,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject {
if(this instanceof AbstractCharacter && this.region != null){
this.loc = this.loc.setY(this.region.lerpY(this) + this.getAltitude());
} else{
this.loc = this.loc.setY(HeightMap.getWorldHeight(this.getLoc()) + this.getAltitude());
this.loc = this.loc.setY(Terrain.getWorldHeight(this.getLoc()) + this.getAltitude());
}

4
src/engine/objects/Building.java

@ -11,8 +11,8 @@ package engine.objects; @@ -11,8 +11,8 @@ package engine.objects;
import engine.Enum;
import engine.Enum.*;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.RealmMap;
import engine.InterestManagement.Terrain;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.CityRecord;
import engine.db.archive.DataWarehouse;
@ -206,7 +206,7 @@ public class Building extends AbstractWorldObject { @@ -206,7 +206,7 @@ public class Building extends AbstractWorldObject {
// Altitude of this building is derived from the heightmap engine.
Vector3fImmutable tempLoc = new Vector3fImmutable(this.statLat + this.parentZone.absX, 0, this.statLon + this.parentZone.absZ);
tempLoc = new Vector3fImmutable(tempLoc.x, HeightMap.getWorldHeight(tempLoc), tempLoc.z);
tempLoc = new Vector3fImmutable(tempLoc.x, Terrain.getWorldHeight(tempLoc), tempLoc.z);
this.setLoc(tempLoc);
}
}

4
src/engine/objects/City.java

@ -11,8 +11,8 @@ package engine.objects; @@ -11,8 +11,8 @@ package engine.objects;
import engine.Enum;
import engine.Enum.*;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.RealmMap;
import engine.InterestManagement.Terrain;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.CityRecord;
import engine.db.archive.DataWarehouse;
@ -588,7 +588,7 @@ public class City extends AbstractWorldObject { @@ -588,7 +588,7 @@ public class City extends AbstractWorldObject {
this.setBounds(cityBounds);
if (zone.getHeightMap() == null && this.isNpc == 1 && this.getObjectUUID() != 1213) {
HeightMap.GenerateCustomHeightMap(zone);
Terrain.GenerateCustomHeightMap(zone);
Logger.info(zone.zoneName + " created custom heightmap");
}
} catch (Exception e) {

8
src/engine/objects/PlayerCharacter.java

@ -11,9 +11,9 @@ package engine.objects; @@ -11,9 +11,9 @@ package engine.objects;
import engine.Enum;
import engine.Enum.*;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.InterestManager;
import engine.InterestManagement.RealmMap;
import engine.InterestManagement.Terrain;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.CharacterRecord;
import engine.db.archive.DataWarehouse;
@ -4760,7 +4760,7 @@ public class PlayerCharacter extends AbstractCharacter { @@ -4760,7 +4760,7 @@ public class PlayerCharacter extends AbstractCharacter {
// If char is flying they aren't quite swimming
try {
float localAltitude = HeightMap.getWorldHeight(currentLoc);
float localAltitude = Terrain.getWorldHeight(currentLoc);
Zone zone = ZoneManager.findSmallestZone(currentLoc);
@ -4832,7 +4832,7 @@ public class PlayerCharacter extends AbstractCharacter { @@ -4832,7 +4832,7 @@ public class PlayerCharacter extends AbstractCharacter {
} else
this.altitude = this.getDesiredAltitude();
this.loc = this.loc.setY(HeightMap.getWorldHeight(this.getLoc()) + this.getAltitude());
this.loc = this.loc.setY(Terrain.getWorldHeight(this.getLoc()) + this.getAltitude());
this.setTakeOffTime(0);
MovementManager.finishChangeAltitude(this, this.getDesiredAltitude());
@ -4840,7 +4840,7 @@ public class PlayerCharacter extends AbstractCharacter { @@ -4840,7 +4840,7 @@ public class PlayerCharacter extends AbstractCharacter {
return;
}
this.loc = this.loc.setY(HeightMap.getWorldHeight(this.getLoc()) + this.getAltitude());
this.loc = this.loc.setY(Terrain.getWorldHeight(this.getLoc()) + this.getAltitude());
}
public boolean hasBoon() {

14
src/engine/objects/Zone.java

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
package engine.objects;
import engine.Enum;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.Terrain;
import engine.db.archive.DataWarehouse;
import engine.gameManager.DbManager;
import engine.gameManager.ZoneManager;
@ -193,15 +193,15 @@ public class Zone extends AbstractGameObject { @@ -193,15 +193,15 @@ public class Zone extends AbstractGameObject {
else
bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(Enum.CityBoundsType.ZONE.halfExtents, Enum.CityBoundsType.ZONE.halfExtents), 0.0f);
HeightMap heightMap = this.getHeightMap();
Terrain terrain = this.getHeightMap();
// Set heightmap blending bounds
if (heightMap == null) {
if (terrain == null) {
this.blendBounds = bounds;
} else {
this.blendBounds = Bounds.borrow();
this.blendBounds.setBounds(new Vector2f(this.absX, this.absZ), bounds.getHalfExtents().subtract(heightMap.zone_minBlend, heightMap.zone_minBlend), 0.0f);
this.blendBounds.setBounds(new Vector2f(this.absX, this.absZ), bounds.getHalfExtents().subtract(terrain.zone_minBlend, terrain.zone_minBlend), 0.0f);
}
}
@ -325,12 +325,12 @@ public class Zone extends AbstractGameObject { @@ -325,12 +325,12 @@ public class Zone extends AbstractGameObject {
// Return heightmap for this Zone.
public HeightMap getHeightMap() {
public Terrain getHeightMap() {
if (this.guild_zone)
return HeightMap.PlayerCityHeightMap;
return Terrain.playerCityTerrain;
return HeightMap.heightmapByLoadNum.get(this.template);
return Terrain.heightmapByLoadNum.get(this.template);
}
}

4
src/engine/server/world/WorldServer.java

@ -13,8 +13,8 @@ import engine.Enum; @@ -13,8 +13,8 @@ import engine.Enum;
import engine.Enum.DispatchChannel;
import engine.Enum.MinionType;
import engine.Enum.SupportMsgType;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.RealmMap;
import engine.InterestManagement.Terrain;
import engine.InterestManagement.WorldGrid;
import engine.db.archive.DataWarehouse;
import engine.db.handlers.dbRuneBaseHandler;
@ -385,7 +385,7 @@ public class WorldServer { @@ -385,7 +385,7 @@ public class WorldServer {
Blueprint.loadAllBlueprints();
Logger.info("Initializing Heightmap data");
HeightMap.loadAlHeightMaps();
Terrain.loadAlHeightMaps();
Logger.info("Loading Race data");
Enum.RaceType.initRaceTypeTables();

Loading…
Cancel
Save