From f5d7caab65b1392cb4042f39a869794eeca5a489 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 3 Dec 2023 10:43:59 -0500 Subject: [PATCH] Rework of db handler --- src/engine/db/handlers/dbBuildingHandler.java | 51 +++---------------- src/engine/gameManager/BuildingManager.java | 3 +- 2 files changed, 9 insertions(+), 45 deletions(-) diff --git a/src/engine/db/handlers/dbBuildingHandler.java b/src/engine/db/handlers/dbBuildingHandler.java index aa9e078d..6f6763dc 100644 --- a/src/engine/db/handlers/dbBuildingHandler.java +++ b/src/engine/db/handlers/dbBuildingHandler.java @@ -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 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 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<>(); - } - } - - //for (int i = 0; i < vertStrings.length; i += 2) - // vertArrayList.add(new Vector2f(Float.parseFloat(vertStrings[i]), Float.parseFloat(vertStrings[1 + 1]))); + Path2D.Float prop_path = BuildingManager.hullToPath2d(HullStrings); - ArrayList> meshList; + ArrayList> 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); } } diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 821e5c8d..143a14a4 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -41,8 +41,7 @@ public enum BuildingManager { BUILDINGMANAGER; - public static HashMap> _render_lookup = new HashMap<>(); - public static HashMap>> _hull_data = new HashMap<>(); + public static HashMap>> _hull_data = new HashMap<>(); public static HashMap> _stuckLocations = new HashMap<>(); public static HashMap> _slotLocations = new HashMap<>();