From 9b8be777f112d7f882de02436388681765c76292 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 16 Nov 2023 13:00:49 -0500 Subject: [PATCH] Final schema for convex hull data. --- src/engine/db/handlers/dbBuildingHandler.java | 41 ++++++++++--------- src/engine/gameManager/BuildingManager.java | 2 +- src/engine/server/world/WorldServer.java | 4 +- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/engine/db/handlers/dbBuildingHandler.java b/src/engine/db/handlers/dbBuildingHandler.java index aa9e078d..b3a5cf3e 100644 --- a/src/engine/db/handlers/dbBuildingHandler.java +++ b/src/engine/db/handlers/dbBuildingHandler.java @@ -549,22 +549,22 @@ public class dbBuildingHandler extends dbHandlerBase { return false; } - public void POPULATE_RENDER_LOOKUP() { + public void LOAD_SUBMESH_LOOKUP() { try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_structure_renders`")) { + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_render_submesh`")) { ResultSet rs = preparedStatement.executeQuery(); while (rs.next()) { - int structureID = rs.getInt("structureID"); - int renderID = rs.getInt("renderID"); + int structureID = rs.getInt("propID"); + int renderID = rs.getInt("meshID"); - if (!BuildingManager._render_lookup.containsKey(structureID)) - BuildingManager._render_lookup.put(structureID, new ArrayList<>()); + if (!BuildingManager._prop_subMeshes.containsKey(structureID)) + BuildingManager._prop_subMeshes.put(structureID, new ArrayList<>()); - BuildingManager._render_lookup.get(structureID).add(renderID); + BuildingManager._prop_subMeshes.get(structureID).add(renderID); } } catch (SQLException e) { @@ -572,12 +572,12 @@ public class dbBuildingHandler extends dbHandlerBase { } } - public void LOAD_MESH_HULLS() { + public void LOAD_CONVEX_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(); @@ -585,39 +585,40 @@ public class dbBuildingHandler extends dbHandlerBase { recordsRead++; - int propID = rs.getInt("propID"); - String[] vertStrings = rs.getString("vertices").split(";"); + int meshID = rs.getInt("meshID"); + String[] vertStrings = rs.getString("convexHull").split(";"); ArrayList vertArrayList = new ArrayList<>(); // Filter things that couldn't be wrapped if (vertStrings.length < 3) { - Logger.error("Prop : " + propID + " has less than 3 vertices."); + Logger.error("Mesh : " + meshID + " has less than 3 vertices."); continue; } + ArrayList vectors = new ArrayList<>(); ArrayList 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<>(); + floats.clear(); } - } - - //for (int i = 0; i < vertStrings.length; i += 2) - // vertArrayList.add(new Vector2f(Float.parseFloat(vertStrings[i]), Float.parseFloat(vertStrings[1 + 1]))); + } ArrayList> meshList; - if (BuildingManager._hull_data.get(propID) == null) { + if (BuildingManager._hull_data.get(meshID) == null) { meshList = new ArrayList<>(); meshList.add(vectors); - BuildingManager._hull_data.put(propID, meshList); + BuildingManager._hull_data.put(meshID, meshList); } else { - meshList = BuildingManager._hull_data.get(propID); + meshList = BuildingManager._hull_data.get(meshID); meshList.add(vectors); } } diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 882b1261..b00613db 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -41,7 +41,7 @@ public enum BuildingManager { BUILDINGMANAGER; - public static HashMap> _render_lookup = new HashMap<>(); + public static HashMap> _prop_subMeshes = new HashMap<>(); public static HashMap>> _hull_data = new HashMap<>(); public static HashMap> _stuckLocations = new HashMap<>(); public static HashMap> _slotLocations = new HashMap<>(); diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index acc86e1c..c6c35852 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -404,10 +404,10 @@ public class WorldServer { BuildingLocation.loadBuildingLocations(); Logger.info("Populating structure to render lookup."); - DbManager.BuildingQueries.POPULATE_RENDER_LOOKUP(); + DbManager.BuildingQueries.LOAD_SUBMESH_LOOKUP(); Logger.info("Loading mesh hulls."); - DbManager.BuildingQueries.LOAD_MESH_HULLS(); + DbManager.BuildingQueries.LOAD_CONVEX_HULLS(); // Starting before loading of structures/guilds/characters // so the database connections are available to write