From a94a400102cbcf3fb820c9c5b8d780c08bd72d52 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 13 Jan 2024 19:51:37 -0600 Subject: [PATCH 1/4] cleanup and comment --- src/engine/CollisionEngine/Mesh.java | 4 +++- src/engine/db/handlers/dbBuildingHandler.java | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/engine/CollisionEngine/Mesh.java b/src/engine/CollisionEngine/Mesh.java index c4d9727f..0870bfb8 100644 --- a/src/engine/CollisionEngine/Mesh.java +++ b/src/engine/CollisionEngine/Mesh.java @@ -26,8 +26,10 @@ public class Mesh { if(!this.BoundsCollides(line)) return false; + boolean feetcollides = (charY + charHeight) < this.minY; + boolean headcollides = charY > this.maxY; //check to see if the mesh collides between the characters feet and head locations - if((charY + charHeight) < this.minY && charY > this.maxY){ + if(feetcollides && headcollides){ return false; } diff --git a/src/engine/db/handlers/dbBuildingHandler.java b/src/engine/db/handlers/dbBuildingHandler.java index 935c7387..4f336f8a 100644 --- a/src/engine/db/handlers/dbBuildingHandler.java +++ b/src/engine/db/handlers/dbBuildingHandler.java @@ -19,9 +19,9 @@ import engine.math.Vector2f; import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.objects.*; +import javafx.geometry.Bounds; import org.joda.time.DateTime; import org.pmw.tinylog.Logger; - import java.awt.geom.Rectangle2D; import java.sql.Connection; import java.sql.PreparedStatement; @@ -30,7 +30,6 @@ import java.sql.SQLException; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; @@ -881,7 +880,7 @@ public class dbBuildingHandler extends dbHandlerBase { public void LOAD_MESH_DATA() { try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `new-static_mesh_triangles`")) { + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_mesh_triangles`")) { ResultSet rs = preparedStatement.executeQuery(); BuildingManager.mesh_triangle_points = new HashMap<>(); @@ -934,8 +933,10 @@ public class dbBuildingHandler extends dbHandlerBase { float refX = Float.parseFloat(rs.getString("ref").split(";")[0]); float refZ = Float.parseFloat(rs.getString("ref").split(";")[1]); + //Bounds bound = new Bounds(endX,0,endZ,0,0,0); + - Vector2f topLeft = new Vector2f(centerX - refX,centerZ + refZ); + Vector2f topLeft = new Vector2f(centerX + refX,centerZ + refZ); float width = Math.abs(endX-refX); float height = Math.abs(endZ-refZ); Rectangle2D boundRect = new Rectangle2D.Float(); From 0b05e661c77f571776ae23b9cdae34541859d618 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 13 Jan 2024 19:53:50 -0600 Subject: [PATCH 2/4] cleanup and comment --- src/engine/db/handlers/dbBuildingHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine/db/handlers/dbBuildingHandler.java b/src/engine/db/handlers/dbBuildingHandler.java index 4f336f8a..9b61d71b 100644 --- a/src/engine/db/handlers/dbBuildingHandler.java +++ b/src/engine/db/handlers/dbBuildingHandler.java @@ -19,7 +19,6 @@ import engine.math.Vector2f; import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.objects.*; -import javafx.geometry.Bounds; import org.joda.time.DateTime; import org.pmw.tinylog.Logger; import java.awt.geom.Rectangle2D; From 306c64d236098b2c933c7c61adcfed182ad7338a Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 13 Jan 2024 21:27:26 -0600 Subject: [PATCH 3/4] Triangle check --- src/engine/CollisionEngine/CollisionManager.java | 6 +++--- src/engine/CollisionEngine/Mesh.java | 14 +++++++------- src/engine/db/handlers/dbBuildingHandler.java | 10 +++++----- src/engine/devcmd/cmds/InfoCmd.java | 2 +- src/engine/devcmd/cmds/RegionCmd.java | 11 ----------- src/engine/gameManager/BuildingManager.java | 7 ++++--- src/engine/objects/Building.java | 3 ++- 7 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/engine/CollisionEngine/CollisionManager.java b/src/engine/CollisionEngine/CollisionManager.java index 6e1733c0..0a711142 100644 --- a/src/engine/CollisionEngine/CollisionManager.java +++ b/src/engine/CollisionEngine/CollisionManager.java @@ -11,11 +11,11 @@ public class CollisionManager { Rectangle.Float boundsRect = new Rectangle.Float(); Vector3f topLeft = new Vector3f(building.loc.x - building.getBounds().getHalfExtents().x,building.loc.y,building.loc.z - building.getBounds().getHalfExtents().y); - boundsRect.setRect(topLeft.x, topLeft.z, building.getBounds().getHalfExtents().x * 2,building.getBounds().getHalfExtents().y * 2); + boundsRect.setRect(topLeft.x, topLeft.z, building.getBounds().getHalfExtents().x * 2,building.getBounds().getHalfExtents().y * 2); if(travelLine.intersects(boundsRect)){ //collided with building - for(Mesh mesh : building.buildingMeshes) { - if (mesh.MeshCollides(travelLine,charHeight, charY)) { + for(Triangle tri : building.buildingTriangles) { + if (tri.collides(travelLine)) { //ChatManager.chatSystemInfo(pc, "Collision Detected"); //MovementManager.movement(msg, pc); return true; diff --git a/src/engine/CollisionEngine/Mesh.java b/src/engine/CollisionEngine/Mesh.java index 0870bfb8..96c99604 100644 --- a/src/engine/CollisionEngine/Mesh.java +++ b/src/engine/CollisionEngine/Mesh.java @@ -23,15 +23,15 @@ public class Mesh { public boolean MeshCollides(Line2D line, float charHeight, float charY){ //check if movement path intersects this mesh - if(!this.BoundsCollides(line)) - return false; + //if(!this.BoundsCollides(line)) + // return false; - boolean feetcollides = (charY + charHeight) < this.minY; - boolean headcollides = charY > this.maxY; + //boolean feetcollides = (charY + charHeight) < this.minY; + //boolean headcollides = charY > this.maxY; //check to see if the mesh collides between the characters feet and head locations - if(feetcollides && headcollides){ - return false; - } + //if(feetcollides && headcollides){ + // return false; + //} //check if any triangles intersect the movement path for(Triangle tri : triangles) diff --git a/src/engine/db/handlers/dbBuildingHandler.java b/src/engine/db/handlers/dbBuildingHandler.java index 9b61d71b..2bcc146f 100644 --- a/src/engine/db/handlers/dbBuildingHandler.java +++ b/src/engine/db/handlers/dbBuildingHandler.java @@ -896,18 +896,18 @@ public class dbBuildingHandler extends dbHandlerBase { triPoints.add(new Vector3f(floatPoints.get(i),floatPoints.get(i+1),floatPoints.get(i+2))); } - if(BuildingManager.mesh_triangle_points.containsKey(rs.getInt("meshID")) == false){ + if(BuildingManager.mesh_triangle_points.containsKey(rs.getInt("propId")) == false){ ArrayList> newPoints = new ArrayList<>(); newPoints.add(triPoints); - BuildingManager.mesh_triangle_points.put(rs.getInt("meshID"),newPoints); + BuildingManager.mesh_triangle_points.put(rs.getInt("propId"),newPoints); } else { - BuildingManager.mesh_triangle_points.get(rs.getInt("meshID")).add(triPoints); + BuildingManager.mesh_triangle_points.get(rs.getInt("propId")).add(triPoints); } - if(BuildingManager.mesh_heights.containsKey(rs.getInt("meshID")) == false){ + if(BuildingManager.mesh_heights.containsKey(rs.getInt("propId")) == false){ Vector2f heights = new Vector2f(rs.getFloat("maxY"),rs.getFloat("minY")); - BuildingManager.mesh_heights.put(rs.getInt("meshID"),heights); + BuildingManager.mesh_heights.put(rs.getInt("propId"),heights); } } diff --git a/src/engine/devcmd/cmds/InfoCmd.java b/src/engine/devcmd/cmds/InfoCmd.java index 313c21ce..04ed3f4e 100644 --- a/src/engine/devcmd/cmds/InfoCmd.java +++ b/src/engine/devcmd/cmds/InfoCmd.java @@ -244,7 +244,7 @@ public class InfoCmd extends AbstractDevCmd { for (Regions regions : targetBuilding.getBounds().getRegions()) { //TODO ADD REGION INFO } - output += "Mesh Count: " + targetBuilding.buildingMeshes.size(); + output += "Triangle Count: " + targetBuilding.buildingTriangles.size(); break; case PlayerCharacter: output += newline; diff --git a/src/engine/devcmd/cmds/RegionCmd.java b/src/engine/devcmd/cmds/RegionCmd.java index a3d284f5..d5576d4a 100644 --- a/src/engine/devcmd/cmds/RegionCmd.java +++ b/src/engine/devcmd/cmds/RegionCmd.java @@ -47,17 +47,6 @@ public class RegionCmd extends AbstractDevCmd { output += "is Outside: " + region.isOutside(); this.throwbackInfo(pc, output); } - if(building != null){ - for(Mesh mesh : building.buildingMeshes){ - if(mesh.boundsRect.contains(new Point2D.Float(((AbstractCharacter) target).loc.x,((AbstractCharacter) target).loc.z))){ - if(((AbstractCharacter) target).loc.y < mesh.maxY) { - this.throwbackInfo(pc, "Inside Mesh Bounds"); - return; - } - } - } - this.throwbackInfo(pc, "Outside Mesh Bounds"); - } } @Override diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index af749ba8..5823c96c 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -982,7 +982,7 @@ public enum BuildingManager { if (building == null) return; - building.buildingMeshes = new ArrayList<>(); + building.buildingTriangles = new ArrayList<>(); float rotation = building.getRot().getRotation(); Vector3f buildingLoc = new Vector3f(building.loc.x, building.loc.y, building.loc.z); if (!prop_meshes.containsKey(building.meshUUID)) @@ -1040,9 +1040,10 @@ public enum BuildingManager { tri.sides.add(new Line2D.Float(p1, p2)); tri.sides.add(new Line2D.Float(p2, p3)); tri.sides.add(new Line2D.Float(p3, p1)); - generatedMesh.triangles.add(tri); + //generatedMesh.triangles.add(tri); + building.buildingTriangles.add(tri); } - building.buildingMeshes.add(generatedMesh); + //building.buildingTriangles.add(generatedMesh); } } catch(Exception e){ diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index 9b2fc9db..bec63817 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -9,6 +9,7 @@ package engine.objects; +import engine.CollisionEngine.Triangle; import engine.Enum; import engine.Enum.*; import engine.InterestManagement.RealmMap; @@ -100,7 +101,7 @@ public class Building extends AbstractWorldObject { private ConcurrentHashMap condemned; private ArrayList children = null; - public ArrayList buildingMeshes; + public ArrayList buildingTriangles; /** * ResultSet Constructor From 5a57677013d1e3e2587ef2a0b59fa1cd7fe00193 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 13 Jan 2024 21:34:36 -0600 Subject: [PATCH 4/4] Triangle check --- src/engine/gameManager/BuildingManager.java | 70 ++++++++++----------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 5823c96c..7b23e1d7 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -985,44 +985,44 @@ public enum BuildingManager { building.buildingTriangles = new ArrayList<>(); float rotation = building.getRot().getRotation(); Vector3f buildingLoc = new Vector3f(building.loc.x, building.loc.y, building.loc.z); - if (!prop_meshes.containsKey(building.meshUUID)) + if (!mesh_triangle_points.containsKey(building.meshUUID)) return; //no data for this prop ID - ArrayList meshes = prop_meshes.get(building.meshUUID); - for (int mesh : meshes) { + //ArrayList meshes = prop_meshes.get(building.meshUUID); + //for (int mesh : meshes) { - if (!mesh_heights.containsKey(mesh) || !mesh_triangle_points.containsKey(mesh)) - return; //no data for this mesh + //if (!mesh_heights.containsKey(mesh) || !mesh_triangle_points.containsKey(mesh)) + //return; //no data for this mesh - Mesh generatedMesh = new Mesh(); - generatedMesh.maxY = building.loc.y + mesh_heights.get(mesh).x; - generatedMesh.minY = building.loc.y + mesh_heights.get(mesh).y; - ArrayList> triPoints = mesh_triangle_points.get(mesh); + //Mesh generatedMesh = new Mesh(); + //generatedMesh.maxY = building.loc.y + mesh_heights.get(mesh).x; + //generatedMesh.minY = building.loc.y + mesh_heights.get(mesh).y; + ArrayList> triPoints = mesh_triangle_points.get(building.meshUUID); - if (mesh_bounding_boxes.containsKey(mesh)) { - Rectangle2D boundingBox = mesh_bounding_boxes.get(mesh); + //if (mesh_bounding_boxes.containsKey(mesh)) { + //Rectangle2D boundingBox = mesh_bounding_boxes.get(mesh); //Bounds buildingBounds = building.getBounds(); - float halfX = (float) boundingBox.getWidth() * 0.5f; - float halfZ = (float)boundingBox.getHeight() * 0.5f; - Vector3f bottomRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z + halfZ); - Vector3f topLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z - halfZ); - Vector3f topRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z - halfZ); - Vector3f bottomLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z + halfZ); - - generatedMesh.BoundingLines = new ArrayList<>(); - Point2D.Float p1 = new Point2D.Float(topLeft.x, topLeft.z); - Point2D.Float p2 = new Point2D.Float(topRight.x, topRight.z); - Point2D.Float p3 = new Point2D.Float(bottomRight.x, bottomRight.z); - Point2D.Float p4 = new Point2D.Float(bottomLeft.x, bottomLeft.z); - float rectWidth = topLeft.distance(topRight); - float rectHeight = topLeft.distance(bottomLeft); - boundingBox.setRect(p1.x,p1.y,rectWidth, rectHeight); - generatedMesh.BoundingLines.add(new Line2D.Float(p1, p2)); - generatedMesh.BoundingLines.add(new Line2D.Float(p2, p3)); - generatedMesh.BoundingLines.add(new Line2D.Float(p3, p4)); - generatedMesh.BoundingLines.add(new Line2D.Float(p4, p1)); - generatedMesh.boundsRect = boundingBox; - } - generatedMesh.triangles = new ArrayList<>(); + //float halfX = (float) boundingBox.getWidth() * 0.5f; + //float halfZ = (float)boundingBox.getHeight() * 0.5f; + //Vector3f bottomRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z + halfZ); + //Vector3f topLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z - halfZ); + //Vector3f topRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z - halfZ); + //Vector3f bottomLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z + halfZ); + + //generatedMesh.BoundingLines = new ArrayList<>(); + //Point2D.Float p1 = new Point2D.Float(topLeft.x, topLeft.z); + //Point2D.Float p2 = new Point2D.Float(topRight.x, topRight.z); + //Point2D.Float p3 = new Point2D.Float(bottomRight.x, bottomRight.z); + //Point2D.Float p4 = new Point2D.Float(bottomLeft.x, bottomLeft.z); + //float rectWidth = topLeft.distance(topRight); + //float rectHeight = topLeft.distance(bottomLeft); + //boundingBox.setRect(p1.x,p1.y,rectWidth, rectHeight); + //generatedMesh.BoundingLines.add(new Line2D.Float(p1, p2)); + //generatedMesh.BoundingLines.add(new Line2D.Float(p2, p3)); + //generatedMesh.BoundingLines.add(new Line2D.Float(p3, p4)); + //generatedMesh.BoundingLines.add(new Line2D.Float(p4, p1)); + //generatedMesh.boundsRect = boundingBox; + //} + //generatedMesh.triangles = new ArrayList<>(); for (ArrayList pointList : triPoints) { ArrayList rotatedPoints = new ArrayList<>(); @@ -1043,8 +1043,8 @@ public enum BuildingManager { //generatedMesh.triangles.add(tri); building.buildingTriangles.add(tri); } - //building.buildingTriangles.add(generatedMesh); - } + //building.buildingMeshes.add(generatedMesh); + //} } catch(Exception e){ Logger.info("Failed To Bake Building Mesh Data For Structure: " + building.meshUUID);