Compare commits

...

13 Commits

Author SHA1 Message Date
MagicBot 9d2d2b9e3d Minor reformat 2023-12-03 16:46:14 -05:00
MagicBot d3306005a5 moveTo handled inside the loop. 2023-12-03 16:31:25 -05:00
FatBoy ab1b7db86c hull 7 2023-12-03 10:29:54 -06:00
FatBoy 87125ed45d hull 7 2023-12-03 10:20:53 -06:00
MagicBot 221ef76ece Comments and formatting 2023-12-03 11:14:00 -05:00
FatBoy 70f3e5e688 hull 7 2023-12-03 10:11:25 -06:00
FatBoy 36095e5336 hull 7 2023-12-03 10:10:41 -06:00
FatBoy 13ee088b89 hull 7 2023-12-03 10:08:41 -06:00
FatBoy d097e744b9 hull 7 2023-12-03 10:03:40 -06:00
FatBoy 53adbc77fb hull 7 2023-12-03 09:48:57 -06:00
MagicBot f5d7caab65 Rework of db handler 2023-12-03 10:43:59 -05:00
MagicBot a28c6f272b Helper method for path creation 2023-12-03 10:30:28 -05:00
MagicBot aad37055d0 Helper method for path creation 2023-12-03 10:29:39 -05:00
7 changed files with 100 additions and 121 deletions
+8 -43
View File
@@ -15,12 +15,12 @@ import engine.Enum.ProtectionState;
import engine.Enum.TaxType;
import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager;
import engine.math.Vector2f;
import engine.math.Vector3fImmutable;
import engine.objects.*;
import org.joda.time.DateTime;
import org.pmw.tinylog.Logger;
import java.awt.geom.Path2D;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -549,35 +549,12 @@ public class dbBuildingHandler extends dbHandlerBase {
return false;
}
public void POPULATE_RENDER_LOOKUP() {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_structure_renders`")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
int structureID = rs.getInt("structureID");
int renderID = rs.getInt("renderID");
if (!BuildingManager._render_lookup.containsKey(structureID))
BuildingManager._render_lookup.put(structureID, new ArrayList<>());
BuildingManager._render_lookup.get(structureID).add(renderID);
}
} catch (SQLException e) {
Logger.error(e);
}
}
public void LOAD_MESH_HULLS() {
int recordsRead = 0;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_verts")) {
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_convex_hulls")) {
ResultSet rs = preparedStatement.executeQuery();
@@ -586,39 +563,27 @@ public class dbBuildingHandler extends dbHandlerBase {
recordsRead++;
int propID = rs.getInt("propID");
String[] vertStrings = rs.getString("vertices").split(";");
ArrayList<Vector2f> vertArrayList = new ArrayList<>();
String[] HullStrings = rs.getString("vertices").split(";");
// Filter things that couldn't be wrapped
if (vertStrings.length < 3) {
if (HullStrings.length < 3) {
Logger.error("Prop : " + propID + " has less than 3 vertices.");
continue;
}
ArrayList<Vector2f> vectors = new ArrayList<>();
ArrayList<Float> floats = new ArrayList<>();
for(String read : vertStrings){
floats.add(Float.parseFloat(read));
if(floats.size() == 2) {
vectors.add(new Vector2f(floats.get(0), floats.get(1)));
floats = new ArrayList<>();
}
}
Path2D.Float prop_path = BuildingManager.hullToPath2d(HullStrings);
//for (int i = 0; i < vertStrings.length; i += 2)
// vertArrayList.add(new Vector2f(Float.parseFloat(vertStrings[i]), Float.parseFloat(vertStrings[1 + 1])));
ArrayList<ArrayList<Vector2f>> meshList;
ArrayList<Path2D.Float> meshList;
if (BuildingManager._hull_data.get(propID) == null) {
meshList = new ArrayList<>();
meshList.add(vectors);
meshList.add(prop_path);
BuildingManager._hull_data.put(propID, meshList);
} else {
meshList = BuildingManager._hull_data.get(propID);
meshList.add(vectors);
meshList.add(prop_path);
}
}
-8
View File
@@ -63,14 +63,6 @@ public class RegionCmd extends AbstractDevCmd {
output += "NavMesh Data" + newline;
this.throwbackInfo(pc, output);
}
//Zone zone = ZoneManager.findSmallestZone(((AbstractCharacter) target).loc);
//if(zone != null) {
// output += "zone: " + zone.zoneName + newline;
// output += "on navmesh: " + zone.navMesh.contains(((AbstractCharacter) target).loc.x,((AbstractCharacter) target).loc.z) + newline;
//}else {
// output += "zone: null" + newline;
//}
output += "pointBlocked: " + NavigationManager.pointIsBlocked(((AbstractCharacter)target).loc);
+77 -41
View File
@@ -29,6 +29,7 @@ import engine.objects.*;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -41,14 +42,14 @@ public enum BuildingManager {
BUILDINGMANAGER;
public static HashMap<Integer, ArrayList<Integer>> _render_lookup = new HashMap<>();
public static HashMap<Integer, ArrayList<ArrayList<Vector2f>>> _hull_data = new HashMap<>();
public static HashMap<Integer, ArrayList<Path2D.Float>> _hull_data = new HashMap<>();
public static HashMap<Integer, ArrayList<BuildingLocation>> _stuckLocations = new HashMap<>();
public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations = new HashMap<>();
public static HashMap<Integer, ConcurrentHashMap<Integer, BuildingFriends>> _buildingFriends = new HashMap<>();
public static HashMap<Integer, ConcurrentHashMap<Integer, Condemned>> _buildingCondemned = new HashMap<>();
public static HashMap<Integer, ArrayList<Vector3fImmutable>> _buildingPatrolPoints = new HashMap<>();
public static int getAvailableSlot(Building building) {
ArrayList<BuildingLocation> slotLocations = _slotLocations.get(building.meshUUID);
@@ -145,10 +146,7 @@ public enum BuildingManager {
if (Guild.sameGuild(building.getGuild(), player.getGuild()) && GuildStatusController.isInnerCouncil(player.getGuildStatus()))
return true;
if (Guild.sameGuild(building.getGuild(), player.getGuild()) && GuildStatusController.isGuildLeader(player.getGuildStatus()))
return true;
return false;
return Guild.sameGuild(building.getGuild(), player.getGuild()) && GuildStatusController.isGuildLeader(player.getGuildStatus());
//TODO test friends list once added
//does not meet above criteria. Cannot access.
@@ -966,62 +964,100 @@ public enum BuildingManager {
}
public static void bakeNavMesh(Building building) {
building.meshes = new ArrayList<>();
if (building.parentZone == null) {
Logger.error("Attempt to bake navmesh with no parent: " + building.getObjectUUID());
//Logger.error("Attempt to bake navmesh with no parent: " + building.getObjectUUID());
return;
}
// Build up navmesh by stencil of the
// convex hull meshes that comprise the prop.
ArrayList<ArrayList<Vector2f>> convexHullList;
ArrayList<Path2D.Float> convexHullList;
convexHullList = _hull_data.get(building.meshUUID);
if (convexHullList == null) {
Logger.error("Attempt to bake navmesh with no meshes: " + building.getObjectUUID());
//Logger.error("Attempt to bake navmesh with no meshes: " + building.getObjectUUID());
return;
}
for (ArrayList<Vector2f> meshEntry : convexHullList) {
Path2D.Float meshBound = new Path2D.Float();
Vector3fImmutable offsetVect = new Vector3fImmutable(meshEntry.get(0).x + building.loc.x, building.loc.y,meshEntry.get(0).y + building.loc.z);
Vector3fImmutable rotatedStart = Vector3fImmutable.rotateAroundPoint(building.loc,offsetVect,building.getRot().y);
meshBound.moveTo(rotatedStart.x,rotatedStart.z);
for (Vector2f vect : meshEntry) {
if(meshEntry.indexOf(vect) == 0){
continue;
}
Vector3fImmutable pos = new Vector3fImmutable(vect.x + building.loc.x, building.loc.y,vect.y + building.loc.z);
Vector3fImmutable rotatedPos = Vector3fImmutable.rotateAroundPoint(building.loc,pos,building.getRot().getRotation());
meshBound.lineTo(rotatedPos.x,rotatedPos.z);
}
meshBound.lineTo(rotatedStart.x,rotatedStart.z);
meshBound.closePath();
building.meshes.add(meshBound);
building.parentZone.navObstacles.add(meshBound);
}
//add navNodes to parent zone list
float X = building.getBounds().getHalfExtents().x;
float Y = building.getBounds().getHalfExtents().y;
ArrayList<Vector2f> cornersAndFaces = new ArrayList<>();
cornersAndFaces.add(new Vector2f(building.loc.x - X,building.loc.z - Y));
cornersAndFaces.add(new Vector2f(building.loc.x + X,building.loc.z + Y));
cornersAndFaces.add(new Vector2f(building.loc.x + X,building.loc.z - Y));
cornersAndFaces.add(new Vector2f(building.loc.x - X,building.loc.z + Y));
cornersAndFaces.add(new Vector2f(building.loc.x - X,building.loc.z));
cornersAndFaces.add(new Vector2f(building.loc.x + X,building.loc.z));
cornersAndFaces.add(new Vector2f(building.loc.x,building.loc.z - Y));
cornersAndFaces.add(new Vector2f(building.loc.x,building.loc.z + Y));
for(Vector2f point : cornersAndFaces){
if(!NavigationManager.pointIsBlocked(new Vector3fImmutable(point.x,building.loc.y,point.y))){
building.parentZone.navNodes.add(new PathingUtilities.Node(point,null,building));
cornersAndFaces.add(new Vector2f(building.loc.x - X, building.loc.z - Y));
cornersAndFaces.add(new Vector2f(building.loc.x + X, building.loc.z + Y));
cornersAndFaces.add(new Vector2f(building.loc.x + X, building.loc.z - Y));
cornersAndFaces.add(new Vector2f(building.loc.x - X, building.loc.z + Y));
cornersAndFaces.add(new Vector2f(building.loc.x - X, building.loc.z));
cornersAndFaces.add(new Vector2f(building.loc.x + X, building.loc.z));
cornersAndFaces.add(new Vector2f(building.loc.x, building.loc.z - Y));
cornersAndFaces.add(new Vector2f(building.loc.x, building.loc.z + Y));
for (Vector2f point : cornersAndFaces) {
if (!NavigationManager.pointIsBlocked(new Vector3fImmutable(point.x, building.loc.y, point.y))) {
building.parentZone.navNodes.add(new PathingUtilities.Node(point, null, building));
}
}
//add region centers to the zones navNodes list
for(Regions region : building.getBounds().getRegions()){
building.parentZone.navNodes.add(new PathingUtilities.Node(new Vector2f(region.center.x,region.center.z),region,building));
for (Regions region : building.getBounds().getRegions()) {
building.parentZone.navNodes.add(new PathingUtilities.Node(new Vector2f(region.center.x, region.center.z), region, building));
}
}
public static Path2D.Float hullToPath2d(String[] hullString) {
// Method builds convex hull from database vertices
ArrayList<Vector2f> vertices = new ArrayList<>();
ArrayList<Float> floats = new ArrayList<>();
Path2D.Float outPath = new Path2D.Float();
// Build Arraylist of vertices
for (String floatString : hullString) {
floats.add(Float.parseFloat(floatString));
if (floats.size() == 2) {
vertices.add(new Vector2f(floats.get(0), floats.get(1)));
floats.clear();
}
}
// Build Path from vertices
for (Vector2f vertex : vertices)
if (outPath.getCurrentPoint() == null)
outPath.moveTo(vertex.x, vertex.y);
else
outPath.lineTo(vertex.x, vertex.y);
outPath.closePath();
return outPath;
}
public static void loadColliders(Building building) {
// Load colliders for this building
building.meshes = new ArrayList<>();
if (_hull_data.get(building.meshUUID) == null ||
_hull_data.get(building.meshUUID).size() < 1)
return;
for (Path2D.Float path : _hull_data.get(building.meshUUID)) {
Path2D.Float translatedPath = new Path2D.Float(path);
AffineTransform offset = AffineTransform.getTranslateInstance(building.loc.x, building.loc.y);
translatedPath.transform(offset);
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(building.getBounds().getQuaternion().angleY), building.loc.x, building.loc.z);
translatedPath.transform(rotate);
building.meshes.add(translatedPath);
}
}
}
+8 -20
View File
@@ -111,27 +111,15 @@ public class NavigationManager {
return false;
}
public static boolean pointIsBlocked(Vector3fImmutable point) {
Zone zone = ZoneManager.findSmallestZone(point);
if(zone != null){
for(Path2D.Float obstacle : zone.navObstacles)
if (obstacle.contains(point.x,point.z)) {
return true;
}
}
//Building building = BuildingManager.getBuildingAtLocation(point);
//if(building != null) {
//for (Path2D.Float mesh : building.meshes) {
//if (mesh.contains(point.x,point.z)) {
//return true;
//}
//}
//for (Regions region : building.getBounds().getRegions()) {
//if (region.isPointInPolygon(point))
//if (Math.abs(region.lerpY(point) - point.y) > stepHeight) // get the height distance between current height and target location height
//return true;
//}
//}
Building building = BuildingManager.getBuildingAtLocation(point);
if(building != null) {
for (Path2D.Float mesh : building.meshes) {
if (mesh.contains(point.x,point.z)) {
return true;
}
}
}
return false;
}
}
+6 -6
View File
@@ -308,7 +308,7 @@ public class MobAI {
aiMove(mob, true,0);
} catch (Exception e) {
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackTarget" + " " + e.getMessage());
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: Patrol" + " " + e.getMessage());
}
}
@@ -1349,11 +1349,11 @@ public class MobAI {
if(mob.isMoving()) {
return;
}
if(!mob.isPathing){
ArrayList<PathingUtilities.Node> path = PathingUtilities.getPath(mob, mob.destination);
if(path != null && path.size() > 0)
PathingUtilities.followPath(mob,path);
}
//if(!mob.isPathing){
// ArrayList<PathingUtilities.Node> path = PathingUtilities.getPath(mob, mob.destination);
// if(path != null && path.size() > 0)
// PathingUtilities.followPath(mob,path);
//}
}
public static void directMove(AbstractCharacter mob,boolean isWalking){
+1
View File
@@ -1008,6 +1008,7 @@ public class Building extends AbstractWorldObject {
if (this.upgradeDateTime != null)
BuildingManager.submitUpgradeJob(this);
BuildingManager.loadColliders(this); // load building colliders
BuildingManager.bakeNavMesh(this); // update the navmesh of the parent zone
}
-3
View File
@@ -403,9 +403,6 @@ public class WorldServer {
Logger.info("Loading building slot/stuck location data.");
BuildingLocation.loadBuildingLocations();
Logger.info("Populating structure to render lookup.");
DbManager.BuildingQueries.POPULATE_RENDER_LOOKUP();
Logger.info("Loading mesh hulls.");
DbManager.BuildingQueries.LOAD_MESH_HULLS();