Compare commits

...

54 Commits

Author SHA1 Message Date
FatBoy 6fe4f32302 load mesh data and structure meshes 2024-01-18 19:50:49 -06:00
FatBoy d6ad0ecbd3 load mesh data and structure meshes 2024-01-18 19:43:47 -06:00
FatBoy efdf19f22e load mesh data and structure meshes 2024-01-18 19:15:49 -06:00
FatBoy 76a71b5984 load mesh data and structure meshes 2024-01-18 19:12:52 -06:00
FatBoy cf09f447bd load mesh data and structure meshes 2024-01-18 18:53:57 -06:00
FatBoy 8dc6a0627c load mesh data and structure meshes 2024-01-17 22:03:35 -06:00
FatBoy 8b095976ef load mesh data and structure meshes 2024-01-17 21:47:15 -06:00
FatBoy 83606046ba load mesh data and structure meshes 2024-01-17 20:55:04 -06:00
FatBoy adcf3fd9b6 load mesh data and structure meshes 2024-01-17 20:34:47 -06:00
FatBoy e983a32b5d load mesh data and structure meshes 2024-01-16 20:10:10 -06:00
FatBoy 9d8f800c2a load mesh data and structure meshes 2024-01-16 10:40:07 -06:00
FatBoy 05e90d495f load mesh data and structure meshes 2024-01-16 09:59:41 -06:00
FatBoy 18f70b6d5c load mesh data and structure meshes 2024-01-16 09:51:07 -06:00
FatBoy 86c8e985be load mesh data and structure meshes 2024-01-16 09:25:31 -06:00
FatBoy b6b5db41bd load mesh data and structure meshes 2024-01-15 20:37:33 -06:00
FatBoy d573534f6d load mesh data and structure meshes 2024-01-15 20:36:11 -06:00
FatBoy 06df109a18 load mesh data and structure meshes 2024-01-15 20:28:49 -06:00
FatBoy f077370034 load mesh data and structure meshes 2024-01-15 20:09:05 -06:00
FatBoy 94e16bdf3d load mesh data and structure meshes 2024-01-15 20:07:21 -06:00
FatBoy a52f0941b7 load mesh data and structure meshes 2024-01-15 19:47:33 -06:00
FatBoy 840dc83987 load mesh data and structure meshes 2024-01-15 19:43:08 -06:00
FatBoy 5b9d1dd6eb load mesh data and structure meshes 2024-01-15 19:32:49 -06:00
FatBoy 6215e15e82 load mesh data and structure meshes 2024-01-15 19:15:41 -06:00
FatBoy e8a39e596e load mesh data and structure meshes 2024-01-15 19:08:38 -06:00
FatBoy 90b516bbb9 load mesh data and structure meshes 2024-01-15 18:57:18 -06:00
FatBoy 561170eb44 load mesh data and structure meshes 2024-01-14 19:36:54 -06:00
FatBoy 68920f150d load mesh data and structure meshes 2024-01-14 19:30:28 -06:00
FatBoy a54e8c2176 Merge remote-tracking branch 'origin/feature_mesh_collision' into feature_mesh_collision
# Conflicts:
#	src/engine/db/handlers/dbBuildingHandler.java
2024-01-14 19:10:23 -06:00
FatBoy c77f38dec1 load mesh data and structure meshes 2024-01-14 19:10:07 -06:00
FatBoy 5a57677013 Triangle check 2024-01-13 21:34:36 -06:00
FatBoy 306c64d236 Triangle check 2024-01-13 21:27:26 -06:00
FatBoy 0b05e661c7 cleanup and comment 2024-01-13 19:53:50 -06:00
FatBoy a94a400102 cleanup and comment 2024-01-13 19:51:37 -06:00
FatBoy 4bff36d7bb cleanup and comment 2024-01-07 19:14:18 -06:00
FatBoy 969b36e6fd mesh count to building info command 2024-01-07 19:11:29 -06:00
FatBoy 688553e6c6 invert X axis instead of Z axis 2024-01-07 19:07:55 -06:00
FatBoy 4f057ee851 utilize min and max Y values for meshes 2024-01-05 23:32:32 -06:00
FatBoy fd47c90f4f utilize min and max Y values for meshes 2024-01-05 23:03:51 -06:00
FatBoy 253ca2344e add Y axis of building to mesh height 2024-01-05 22:44:58 -06:00
FatBoy 95f09a255e add Y axis of building to mesh height 2024-01-05 22:41:41 -06:00
FatBoy 31ea74f98c reverse Z axis 2024-01-05 22:38:39 -06:00
FatBoy 67c474dbdf collision work 2024-01-05 20:29:11 -06:00
FatBoy c65a713bae collision work 2024-01-05 20:13:27 -06:00
FatBoy e3641872d0 added COllisionManager 2024-01-05 19:28:43 -06:00
FatBoy c25fdf3823 added COllisionManager 2024-01-05 19:21:24 -06:00
FatBoy 7c28efb47c offset cleanup 2024-01-05 19:06:56 -06:00
FatBoy c92316f03e data load fixes 2024-01-03 20:39:18 -06:00
FatBoy e330f190fe data load fixes 2024-01-03 20:11:28 -06:00
FatBoy ae52735131 data load fixes 2024-01-03 20:08:52 -06:00
FatBoy 59025c2585 collision handler 2024-01-03 19:55:12 -06:00
FatBoy 6354eb2893 collision handler 2024-01-03 19:50:40 -06:00
FatBoy 3ad97a7ce3 collision handler 2024-01-03 19:47:30 -06:00
FatBoy f8cbeb4cc6 debug dev command for collision 2024-01-03 19:33:34 -06:00
FatBoy f1e41e47cf database mesh data loaded into hashmaps 2024-01-03 19:25:59 -06:00
13 changed files with 495 additions and 6 deletions
@@ -0,0 +1,27 @@
package engine.CollisionEngine;
import engine.math.Vector3f;
import engine.objects.Building;
import java.awt.*;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.HashMap;
public class CollisionManager {
public static HashMap<Integer, ArrayList<MeshData>> structure_meshes;
public static HashMap<Integer,ArrayList<Triangle>> mesh_triangles;
public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight, float charY){
if(building.buildingRect != null)
if(!travelLine.intersects(building.buildingRect) && !building.buildingRect.contains(travelLine.getP1()) && !building.buildingRect.contains(travelLine.getP2()))
return false;
for(Mesh mesh : building.buildingMeshes)
if(mesh.collides(travelLine))
return true;
return false;
}
}
+87
View File
@@ -0,0 +1,87 @@
package engine.CollisionEngine;
import engine.gameManager.BuildingManager;
import engine.math.Vector2f;
import engine.math.Vector3f;
import engine.math.Vector3fImmutable;
import engine.objects.Building;
import org.pmw.tinylog.Logger;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
public class Mesh {
public ArrayList<Triangle> triangles;
public Vector3f mesh_end_point;
public Vector3f mesh_ref_point;
public Vector3f mesh_location;
public float mesh_max_y;
public float mesh_min_y;
public Vector3f mesh_scale;
public int mesh_id;
public int parent_prop_id;
public int parent_structure_id;
public int parentUUID;
public Rectangle2D.Float mesh_bounds;
public MeshData meshData;
public void update(){
this.BakeTriangles();
}
public Vector3f getLocation(){
Building parentBuilding = BuildingManager.getBuilding(this.parentUUID);
int degrees = (int)Math.toDegrees(parentBuilding.getBounds().getQuaternion().angleY);
Vector3f parentLoc = new Vector3f(parentBuilding.loc.x,parentBuilding.loc.y,parentBuilding.loc.z);
Vector3f offsetLoc = parentLoc.add(this.meshData.loc);
Vector3f rotatedPoint = Vector3f.rotateAroundPoint(offsetLoc,parentLoc,degrees);
return rotatedPoint;
}
public void BakeTriangles(){
if(CollisionManager.mesh_triangles.containsKey(this.meshData.meshID) == false){
Logger.error("Failed To Bake Triangles For Mesh: " + this.meshData.meshID);
return;
}
Building parentBuilding = BuildingManager.getBuilding(this.parentUUID);
int degrees = (int)Math.toDegrees(parentBuilding.getBounds().getQuaternion().angleY);
Vector3f parentLoc = new Vector3f(parentBuilding.loc.x,parentBuilding.loc.y,parentBuilding.loc.z);
Vector3f offsetLoc = parentLoc.add(this.meshData.loc);
for(Triangle tri : CollisionManager.mesh_triangles.get(this.meshData.meshID)) {
Triangle newTri = new Triangle();
Vector3f Point1 = offsetLoc.add(new Vector3f(tri.point1.x,offsetLoc.y,tri.point1.y));
Vector3f Point2 = offsetLoc.add(new Vector3f(tri.point2.x,offsetLoc.y,tri.point2.y));
Vector3f Point3 = offsetLoc.add(new Vector3f(tri.point3.x,offsetLoc.y,tri.point3.y));
Vector3f rotatedPoint1 = Vector3f.rotateAroundPoint(Point1,offsetLoc,degrees);
Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(Point2,offsetLoc,degrees);
Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(Point3,offsetLoc,degrees);
newTri.point1 = new Point2D.Float(rotatedPoint1.x,rotatedPoint1.z);
newTri.point2 = new Point2D.Float(rotatedPoint2.x,rotatedPoint2.z);
newTri.point3 = new Point2D.Float(rotatedPoint3.x,rotatedPoint3.z);
newTri.sides = new ArrayList<>();
newTri.sides.add(new Line2D.Float(newTri.point1,newTri.point2));
newTri.sides.add(new Line2D.Float(newTri.point2,newTri.point3));
newTri.sides.add(new Line2D.Float(newTri.point3,newTri.point1));
this.triangles.add(newTri);
}
}
public Boolean collides(Line2D line){
for(Triangle tri : this.triangles)
if(tri.collides(line))
return true;
return false;
}
}
+14
View File
@@ -0,0 +1,14 @@
package engine.CollisionEngine;
import engine.math.Vector3f;
public class MeshData {
public int propID;
public int meshID;
public Vector3f loc;
public Vector3f scale;
public Vector3f refPoint;
public Vector3f endPoint;
public float maxY;
public float minY;
}
+21
View File
@@ -0,0 +1,21 @@
package engine.CollisionEngine;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;
public class Triangle {
public Point2D.Float point1;
public Point2D.Float point2;
public Point2D.Float point3;
public ArrayList<Line2D> sides;
public boolean collides(Line2D line)
{
for(Line2D side : sides)
if(side.intersectsLine(line))
return true;
return false;
}
}
@@ -9,17 +9,25 @@
package engine.db.handlers;
import engine.CollisionEngine.CollisionManager;
import engine.CollisionEngine.MeshData;
import engine.CollisionEngine.Triangle;
import engine.Enum;
import engine.Enum.DbObjectType;
import engine.Enum.ProtectionState;
import engine.Enum.TaxType;
import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager;
import engine.math.Vector2f;
import engine.math.Vector3f;
import engine.math.Vector3fImmutable;
import engine.objects.*;
import org.joda.time.DateTime;
import org.pmw.tinylog.Logger;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -27,6 +35,7 @@ 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;
@@ -849,4 +858,167 @@ public class dbBuildingHandler extends dbHandlerBase {
return false;
}
public void LOAD_MESH_DATA(){
CollisionManager.structure_meshes = new HashMap<>();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `final_structure_meshes`")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
MeshData md = new MeshData();
md.propID = rs.getInt("propID");
md.meshID = rs.getInt("meshID");
md.loc = new Vector3f(rs.getFloat("locX"), rs.getFloat("locY"),rs.getFloat("locz"));
md.scale = new Vector3f(rs.getFloat("scaleX"), rs.getFloat("scaleY"),rs.getFloat("scaleZ"));
md.refPoint = new Vector3f(rs.getFloat("refX"), rs.getFloat("refY"),rs.getFloat("refZ"));
md.endPoint = new Vector3f(rs.getFloat("endX"), rs.getFloat("endY"),rs.getFloat("endZ"));
md.minY = rs.getFloat("minY");
md.maxY = rs.getFloat("maxY");
if(CollisionManager.structure_meshes.containsKey(rs.getInt("propID"))){
CollisionManager.structure_meshes.get(rs.getInt("propID")).add(md);
} else{
ArrayList<MeshData> meshData = new ArrayList<>();
meshData.add(md);
CollisionManager.structure_meshes.put(rs.getInt("propID"),meshData);
}
}
} catch (SQLException e) {
Logger.error(e);
}
}
public void LOAD_MESH_TRIANGLE_DATA(){
CollisionManager.mesh_triangles = new HashMap<>();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `final_mesh_triangles`")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
Triangle tri = new Triangle();
tri.point1 = new Point2D.Float(rs.getFloat("P1X"),rs.getFloat("P1Z"));
tri.point2 = new Point2D.Float(rs.getFloat("P2X"),rs.getFloat("P2Z"));
tri.point3 = new Point2D.Float(rs.getFloat("P3X"),rs.getFloat("P3Z"));
if(CollisionManager.mesh_triangles.containsKey(rs.getInt("meshID"))){
CollisionManager.mesh_triangles.get(rs.getInt("meshID")).add(tri);
} else{
ArrayList<Triangle> triData = new ArrayList<>();
triData.add(tri);
CollisionManager.mesh_triangles.put(rs.getInt("meshID"),triData);
}
}
} catch (SQLException e) {
Logger.error(e);
}
}
public void LOAD_PROP_MESHES() {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_structure_meshes`")) {
ResultSet rs = preparedStatement.executeQuery();
BuildingManager.prop_meshes = new HashMap<>();
while (rs.next()) {
if(BuildingManager.prop_meshes.containsKey(rs.getInt("propID")) == false){
ArrayList<Integer> meshList = new ArrayList<>();
meshList.add(rs.getInt("meshID"));
BuildingManager.prop_meshes.put(rs.getInt("propID"),meshList);
}
else
{
ArrayList<Integer> meshes = BuildingManager.prop_meshes.get(rs.getInt("propID"));
meshes.add(rs.getInt("meshID"));
//BuildingManager.prop_meshes.get(rs.getInt("propID")).add(rs.getInt("meshID"));
}
}
} catch (SQLException e) {
Logger.error(e);
}
}
public void LOAD_MESH_DATA_OLD() {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_mesh_triangles`")) {
ResultSet rs = preparedStatement.executeQuery();
BuildingManager.mesh_triangle_points = new HashMap<>();
while (rs.next()) {
ArrayList<Float> floatPoints = new ArrayList<>();
for(String f : rs.getString("vertices").split(";"))
{
floatPoints.add(Float.parseFloat(f));
}
ArrayList<Vector3f> triPoints = new ArrayList<>();
for(int i = 0; i < floatPoints.size(); i += 3){
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){
ArrayList<ArrayList<Vector3f>> newPoints = new ArrayList<>();
newPoints.add(triPoints);
BuildingManager.mesh_triangle_points.put(rs.getInt("meshID"),newPoints);
}
else
{
BuildingManager.mesh_triangle_points.get(rs.getInt("meshID")).add(triPoints);
}
}
} catch (SQLException e) {
Logger.error(e);
}
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_mesh_heights`")) {
ResultSet rs = preparedStatement.executeQuery();
BuildingManager.mesh_heights = new HashMap<>();
while (rs.next()) {
if(BuildingManager.mesh_heights.containsKey(rs.getInt("meshID")) == false){
Vector2f heights = new Vector2f(rs.getFloat("maxY"),rs.getFloat("minY"));
BuildingManager.mesh_heights.put(rs.getInt("meshID"),heights);
}
}
} catch (SQLException e) {
Logger.error(e);
}
}
public void LOAD_MESH_BOUNDING_BOXES() {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_mesh_bounding_boxes`")) {
ResultSet rs = preparedStatement.executeQuery();
BuildingManager.mesh_bounding_boxes = new HashMap<>();
while (rs.next()) {
int meshID = rs.getInt("meshId");
if(BuildingManager.mesh_bounding_boxes.containsKey(meshID) == false){
float endX = Float.parseFloat(rs.getString("mesh_end_point").split(";")[0]);
float endZ = Float.parseFloat(rs.getString("mesh_end_point").split(";")[1]);
float refX = Float.parseFloat(rs.getString("mesh_ref_point").split(";")[0]);
float refZ = Float.parseFloat(rs.getString("mesh_ref_point").split(";")[1]);
Vector2f topLeft = new Vector2f(refX,refZ);
float width = Math.abs(Math.abs(endX)-Math.abs(refX));
float height = Math.abs(Math.abs(endZ)-Math.abs(refZ));
Rectangle2D boundRect = new Rectangle2D.Float();
boundRect.setRect(topLeft.x,topLeft.y,width,height);
BuildingManager.mesh_bounding_boxes.put(meshID,boundRect);
}
}
} catch (SQLException e) {
Logger.error(e);
}
}
}
+60
View File
@@ -0,0 +1,60 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.devcmd.cmds;
import engine.CollisionEngine.Mesh;
import engine.Enum;
import engine.devcmd.AbstractDevCmd;
import engine.objects.*;
public class ColliderCmd extends AbstractDevCmd {
public ColliderCmd() {
super("collider");
}
@Override
protected void _doCmd(PlayerCharacter pc, String[] words,
AbstractGameObject target) {
String newline = "\r\n ";
String output;
if(target.getObjectType().equals(Enum.GameObjectType.Building) == false){
throwbackInfo(pc,"Please Select A Building To Show Collider Data");
}
Building building = (Building)target;
output = "Collision Info:" + newline;
output += "Total Meshes: " + building.buildingMeshes.size() + newline;
for(Mesh mesh : building.buildingMeshes){
output += "-----------------------------" + newline;
output += "Mesh ID: " + mesh.mesh_id + newline;
output += "Mesh Location: " + mesh.mesh_location + newline;
output += "Mesh Scale: " + mesh.mesh_scale + newline;
output += "Mesh Min/Max: " + mesh.mesh_min_y + "/" + mesh.mesh_max_y + newline;
output += "Mesh Triangle Count: " + mesh.triangles.size() + newline;
output += "Mesh Rect: " + mesh.mesh_bounds + newline;
output += "-----------------------------" + newline;
}
throwbackInfo(pc,output);
}
@Override
protected String _getHelpString() {
return "Displays Information About Colliders";
}
@Override
protected String _getUsageString() {
return "' /collider displays collision info when selected on a building";
}
}
+1 -1
View File
@@ -9,6 +9,7 @@
package engine.devcmd.cmds;
import engine.CollisionEngine.Mesh;
import engine.Enum;
import engine.Enum.BuildingGroup;
import engine.Enum.GameObjectType;
@@ -244,7 +245,6 @@ public class InfoCmd extends AbstractDevCmd {
for (Regions regions : targetBuilding.getBounds().getRegions()) {
//TODO ADD REGION INFO
}
break;
case PlayerCharacter:
output += newline;
+2 -4
View File
@@ -9,12 +9,12 @@
package engine.devcmd.cmds;
import engine.Enum;
import engine.CollisionEngine.Mesh;
import engine.devcmd.AbstractDevCmd;
import engine.gameManager.BuildingManager;
import engine.objects.*;
import java.lang.reflect.Field;
import java.awt.geom.Point2D;
public class RegionCmd extends AbstractDevCmd {
@@ -37,7 +37,6 @@ public class RegionCmd extends AbstractDevCmd {
Regions region = ((AbstractCharacter)target).region;
if (region == null) {
this.throwbackInfo(pc, "No Region Found.");
return;
}
if(region != null) {
@@ -48,7 +47,6 @@ public class RegionCmd extends AbstractDevCmd {
output += "is Outside: " + region.isOutside();
this.throwbackInfo(pc, output);
}
}
@Override
@@ -9,15 +9,21 @@
package engine.gameManager;
import engine.CollisionEngine.CollisionManager;
import engine.CollisionEngine.MeshData;
import engine.Enum;
import engine.Enum.BuildingGroup;
import engine.Enum.GameObjectType;
import engine.InterestManagement.InterestManager;
import engine.InterestManagement.WorldGrid;
import engine.CollisionEngine.Mesh;
import engine.CollisionEngine.Triangle;
import engine.job.JobContainer;
import engine.job.JobScheduler;
import engine.jobs.UpgradeBuildingJob;
import engine.math.Bounds;
import engine.math.Vector2f;
import engine.math.Vector3f;
import engine.math.Vector3fImmutable;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ErrorPopupMsg;
@@ -27,6 +33,9 @@ import engine.objects.*;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
@@ -38,6 +47,12 @@ public enum BuildingManager {
BUILDINGMANAGER;
public static HashMap<Integer,ArrayList<Integer>> prop_meshes = new HashMap<>();
public static HashMap<Integer, Vector2f> mesh_heights = new HashMap<>();
public static HashMap<Integer,ArrayList<ArrayList<Vector3f>>> mesh_triangle_points = new HashMap<>();
public static HashMap<Integer, Rectangle2D> mesh_bounding_boxes = new HashMap<>();
public static HashMap<Integer, ArrayList<BuildingLocation>> _stuckLocations = new HashMap<>();
public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations = new HashMap<>();
@@ -942,6 +957,9 @@ public enum BuildingManager {
cleanupHirelings(building);
//rebake colliders for change in rank
//BuildingManager.BakeBuildingMeshes(building);
BuildingManager.BakeBuildingColliders(building);
building.isDeranking.compareAndSet(true, false);
}
@@ -960,4 +978,46 @@ public enum BuildingManager {
return null;
}
public static void BakeBuildingColliders(Building building){
if(CollisionManager.structure_meshes.containsKey(building.meshUUID) == false) {
Logger.error("No Meshes Found For Structure: " + building.meshUUID);
return;
}
//create the empty array of meshes
building.buildingMeshes = new ArrayList<>();
//create the actual meshes from the stored mesh data
for(MeshData meshData : CollisionManager.structure_meshes.get(building.meshUUID)){
if(meshData.meshID == 0)
continue;
int degrees = (int)Math.toDegrees(building.getBounds().getQuaternion().angleY);
Mesh generatedMesh = new Mesh();
generatedMesh.meshData = meshData;
Vector3f buildingLoc = new Vector3f(building.loc.x,building.loc.y,building.loc.z);
Vector3f offset_mesh_loc = buildingLoc.add(meshData.loc);
Vector3f offset_mesh_end = buildingLoc.add(meshData.endPoint);
Vector3f offset_mesh_ref = buildingLoc.add(meshData.refPoint);
generatedMesh.mesh_location = Vector3f.rotateAroundPoint(offset_mesh_loc,buildingLoc,degrees);
generatedMesh.mesh_end_point = Vector3f.rotateAroundPoint(offset_mesh_end,buildingLoc,degrees);
generatedMesh.mesh_ref_point = Vector3f.rotateAroundPoint(offset_mesh_ref,buildingLoc,degrees);
generatedMesh.mesh_max_y = building.loc.y + meshData.maxY;
generatedMesh.mesh_min_y = building.loc.y + meshData.minY;
generatedMesh.mesh_scale = meshData.scale;
generatedMesh.mesh_id = meshData.meshID;
generatedMesh.parent_prop_id = meshData.propID;
generatedMesh.parent_structure_id = building.meshUUID;
generatedMesh.parentUUID = building.getObjectUUID();
generatedMesh.update();
building.buildingMeshes.add(generatedMesh);
}
}
}
@@ -140,6 +140,7 @@ public enum DevCmdManager {
DevCmdManager.registerDevCmd(new BoundsCmd());
DevCmdManager.registerDevCmd(new GotoBoundsCmd());
DevCmdManager.registerDevCmd(new RegionCmd());
DevCmdManager.registerDevCmd(new ColliderCmd());
DevCmdManager.registerDevCmd(new SetMaintCmd());
DevCmdManager.registerDevCmd(new ApplyBonusCmd());
DevCmdManager.registerDevCmd(new AuditFailedItemsCmd());
@@ -9,14 +9,22 @@
package engine.net.client.handlers;
import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager;
import engine.gameManager.ChatManager;
import engine.CollisionEngine.CollisionManager;
import engine.gameManager.MovementManager;
import engine.math.Vector3fImmutable;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.MoveToPointMsg;
import engine.objects.*;
import engine.server.MBServerStatics;
import java.awt.geom.Line2D;
import java.util.HashSet;
public class MoveToPointHandler extends AbstractClientMsgHandler {
@@ -32,6 +40,32 @@ public class MoveToPointHandler extends AbstractClientMsgHandler {
if(pc == null)
return true;
//check for collisions
Line2D travelLine = new Line2D.Float();
Vector3fImmutable endLoc = new Vector3fImmutable(msg.getEndLat(),msg.getEndAlt(),msg.getEndLon());
travelLine.setLine(pc.loc.x,pc.loc.z,endLoc.x,endLoc.z);
if(BuildingManager.getBuildingAtLocation(pc.loc) != null){
Building current = BuildingManager.getBuildingAtLocation(pc.loc);
if (CollisionManager.CollisionDetected(current, travelLine, pc.getCharacterHeight(), pc.loc.y)) {
ChatManager.chatSystemInfo(pc, "Collision Detected With : " + current.getName() + " Rect: " + current.buildingRect);
//msg.setEndCoord();
MovementManager.movement(msg, pc);
return true;
}
}
HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(pc.loc, 1000, MBServerStatics.MASK_BUILDING);
for(AbstractWorldObject awo : awoList){
Building building = (Building)awo;
if(travelLine.intersects(building.buildingRect) || building.buildingRect.contains(travelLine.getP1()) || building.buildingRect.contains(travelLine.getP2())) {
if (CollisionManager.CollisionDetected(building, travelLine, pc.getCharacterHeight(), pc.loc.y)) {
ChatManager.chatSystemInfo(pc, "Collision Detected With : " + building.getName() + " Rect: " + building.buildingRect);
//msg.setEndCoord();
MovementManager.movement(msg, pc);
return true;
}
}
}
//ChatManager.chatSystemInfo(pc, "No Collision Detected");
MovementManager.movement(msg, pc);
return true;
}
+9
View File
@@ -9,11 +9,13 @@
package engine.objects;
import engine.CollisionEngine.Triangle;
import engine.Enum;
import engine.Enum.*;
import engine.InterestManagement.RealmMap;
import engine.InterestManagement.Terrain;
import engine.InterestManagement.WorldGrid;
import engine.CollisionEngine.Mesh;
import engine.db.archive.CityRecord;
import engine.db.archive.DataWarehouse;
import engine.db.archive.MineRecord;
@@ -34,6 +36,7 @@ import engine.net.client.msg.UpdateObjectMsg;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.awt.geom.Rectangle2D;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
@@ -99,6 +102,9 @@ public class Building extends AbstractWorldObject {
private ConcurrentHashMap<Integer, Condemned> condemned;
private ArrayList<Building> children = null;
public ArrayList<Mesh> buildingMeshes;
public Rectangle2D.Float buildingRect;
/**
* ResultSet Constructor
*/
@@ -1003,6 +1009,9 @@ public class Building extends AbstractWorldObject {
if (this.upgradeDateTime != null)
BuildingManager.submitUpgradeJob(this);
//BuildingManager.BakeBuildingMeshes(this);
BuildingManager.BakeBuildingColliders(this);
}
public synchronized boolean setOwner(AbstractCharacter newOwner) {
+6
View File
@@ -309,6 +309,12 @@ public class WorldServer {
Logger.info("Initializing Errant Guild");
Guild.getErrantGuild();
Logger.info("Loading Server Collision Meshes.");
//DbManager.BuildingQueries.LOAD_PROP_MESHES();
DbManager.BuildingQueries.LOAD_MESH_DATA();
DbManager.BuildingQueries.LOAD_MESH_TRIANGLE_DATA();
//DbManager.BuildingQueries.LOAD_MESH_BOUNDING_BOXES();
Logger.info("Loading zone template data");
DbManager.ZoneQueries.LOAD_ALL_ZONE_TEMPLATES();