Browse Source

bonus code cleanup

hull4
FatBoy-DOTC 1 year ago
parent
commit
6cc6713650
  1. 2
      src/engine/math/Bounds.java
  2. 12
      src/engine/mobileAI/utilities/MovementUtilities.java
  3. 1
      src/engine/objects/Building.java
  4. 9
      src/engine/objects/MeshBounds.java
  5. 10
      src/engine/objects/Regions.java
  6. 25
      src/engine/objects/Zone.java

2
src/engine/math/Bounds.java

@ -41,7 +41,7 @@ public class Bounds {
private boolean flipExtents; private boolean flipExtents;
private ArrayList<Regions> regions = new ArrayList<>(); private ArrayList<Regions> regions = new ArrayList<>();
private ArrayList<Colliders> colliders = new ArrayList<>(); public ArrayList<Colliders> colliders = new ArrayList<>();
// Default constructor // Default constructor

12
src/engine/mobileAI/utilities/MovementUtilities.java

@ -18,6 +18,7 @@ import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager; import engine.gameManager.BuildingManager;
import engine.gameManager.ChatManager; import engine.gameManager.ChatManager;
import engine.gameManager.MovementManager; import engine.gameManager.MovementManager;
import engine.gameManager.ZoneManager;
import engine.math.Bounds; import engine.math.Bounds;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.mobileAI.Threads.MobAIThread; import engine.mobileAI.Threads.MobAIThread;
@ -432,20 +433,19 @@ private static final int cellGap = 4;
public static boolean pointIsBlocked(Vector3fImmutable point) { public static boolean pointIsBlocked(Vector3fImmutable point) {
//TODO figure out best way to decide if a walking point intersects a mesh collider from a building
Building building = BuildingManager.getBuildingAtLocation(point); Building building = BuildingManager.getBuildingAtLocation(point);
if(building == null) if(building == null)
return false;//no building at this location means nothing obstructing the walking path return false;//no building at this location means nothing obstructing the walking path
if(!collidesWithBuilding(building,point))
return false;
if(Regions.getRegionAtLocation(point) != null) if(Regions.getRegionAtLocation(point) != null)
return false; return false;
Zone currentZone = ZoneManager.findSmallestZone(point);
if(currentZone == null)
return false; return false;
else
return currentZone.navMesh.contains(point.x,point.z);
//return false;
} }
private static boolean collidesWithBuilding(Building building, Vector3fImmutable end){ private static boolean collidesWithBuilding(Building building, Vector3fImmutable end){

1
src/engine/objects/Building.java

@ -33,7 +33,6 @@ import engine.net.client.msg.ApplyBuildingEffectMsg;
import engine.net.client.msg.UpdateObjectMsg; import engine.net.client.msg.UpdateObjectMsg;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.LocalDateTime; import java.time.LocalDateTime;

9
src/engine/objects/MeshBounds.java

@ -12,6 +12,8 @@ package engine.objects;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.math.Bounds; import engine.math.Bounds;
import java.awt.*;
import java.awt.geom.Area;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -45,5 +47,10 @@ public class MeshBounds {
Bounds.meshBoundsCache = DbManager.BuildingQueries.LOAD_MESH_BOUNDS(); Bounds.meshBoundsCache = DbManager.BuildingQueries.LOAD_MESH_BOUNDS();
} }
public Area getArea(){
Polygon area = new Polygon();
area.addPoint((int) this.minX, (int) this.minZ);
area.addPoint((int) this.maxX, (int) this.maxZ);
return new Area(area);
}
} }

10
src/engine/objects/Regions.java

@ -17,6 +17,8 @@ import engine.math.Vector3f;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import java.awt.*;
import java.awt.geom.Area;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -360,4 +362,12 @@ public class Regions {
public boolean isExit() { public boolean isExit() {
return exit; return exit;
} }
public Area getArea(){
Polygon area = new Polygon();
for( Vector3f point : this.regionPoints){
area.addPoint((int) point.x, (int) point.z);
}
return new Area(area);
}
} }

25
src/engine/objects/Zone.java

@ -9,17 +9,19 @@
package engine.objects; package engine.objects;
import java.awt.geom.Area;
import engine.Enum; import engine.Enum;
import engine.InterestManagement.Terrain; import engine.InterestManagement.Terrain;
import engine.db.archive.DataWarehouse; import engine.db.archive.DataWarehouse;
import engine.gameManager.ZoneManager; import engine.gameManager.ZoneManager;
import engine.math.Bounds; import engine.math.Bounds;
import engine.math.Vector2f; import engine.math.Vector2f;
import engine.math.Vector3f;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.net.ByteBufferWriter; import engine.net.ByteBufferWriter;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.awt.*;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
@ -65,6 +67,8 @@ public class Zone extends AbstractWorldObject {
public Terrain terrain = null; public Terrain terrain = null;
public Area navMesh;
/** /**
* ResultSet Constructor * ResultSet Constructor
*/ */
@ -181,8 +185,27 @@ public class Zone extends AbstractWorldObject {
ZoneManager.populateZoneCollections(this); ZoneManager.populateZoneCollections(this);
this.bakeNavMesh();
} }
public void bakeNavMesh(){
int xPoint = (int)(this.loc.x - this.bounds.getHalfExtents().x);
int zPoint = (int) (this.loc.z - this.bounds.getHalfExtents().y);
int extentsX = (int) (this.bounds.getHalfExtents().x * 2);
int extentsZ = (int) (this.bounds.getHalfExtents().y * 2);
this.navMesh = new Area(new Rectangle(xPoint, zPoint, extentsX, extentsZ));
for(Building building : this.zoneBuildingSet){
for(Regions region : building.getBounds().getRegions())
this.navMesh.add(region.getArea());
MeshBounds meshBounds = Bounds.meshBoundsCache.get(building.getMeshUUID());
if(meshBounds != null)
this.navMesh.subtract(meshBounds.getArea());
}
}
/* Method sets a default value for player cities /* Method sets a default value for player cities
* otherwise using values derived from the loadnum * otherwise using values derived from the loadnum
* field in the obj_zone database table. * field in the obj_zone database table.

Loading…
Cancel
Save