database mesh data loaded into hashmaps
This commit is contained in:
@@ -15,11 +15,13 @@ import engine.Enum.ProtectionState;
|
||||
import engine.Enum.TaxType;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.DbManager;
|
||||
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.Rectangle2D;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@@ -27,6 +29,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 +852,96 @@ public class dbBuildingHandler extends dbHandlerBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
BuildingManager.prop_meshes.get(rs.getInt("propId")).add(rs.getInt("meshID"));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_MESH_DATA() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_mesh_triangles`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
BuildingManager.mesh_triangle_points = new HashMap<>();
|
||||
BuildingManager.mesh_heights = 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);
|
||||
}
|
||||
if(BuildingManager.mesh_heights.containsKey(rs.getInt("meshID")) == false){
|
||||
BuildingManager.mesh_heights.put(rs.getInt("meshID"),rs.getFloat("maxY"));
|
||||
}
|
||||
}
|
||||
|
||||
} 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_triangles`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
BuildingManager.mesh_bounding_boxes = new HashMap<>();
|
||||
while (rs.next()) {
|
||||
if(BuildingManager.mesh_bounding_boxes.containsKey(rs.getInt("meshId")) == false){
|
||||
float centerX = Float.parseFloat(rs.getString("start").split(";")[0]);
|
||||
float centerZ = Float.parseFloat(rs.getString("start").split(";")[1]);
|
||||
float endX = Float.parseFloat(rs.getString("end").split(";")[0]);
|
||||
float endZ = Float.parseFloat(rs.getString("end").split(";")[1]);
|
||||
float refX = Float.parseFloat(rs.getString("ref").split(";")[0]);
|
||||
float refZ = Float.parseFloat(rs.getString("ref").split(";")[1]);
|
||||
Rectangle2D boundRect = new Rectangle2D.Float();
|
||||
boundRect.setRect(centerX,centerZ,Math.abs(endX-refX),Math.abs(endZ-refZ));
|
||||
BuildingManager.mesh_bounding_boxes.put(rs.getInt("meshId"),boundRect);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user