From 531781dd54a142749925bc61c5abac9c13a8b312 Mon Sep 17 00:00:00 2001 From: austin Date: Sun, 18 May 2025 16:00:42 -0400 Subject: [PATCH] road macro data --- docs/src/progress/renderertodo.md | 1 + .../electrosphere/server/macro/MacroData.java | 23 +++ .../civilization/CivilizationGenerator.java | 7 + .../server/macro/civilization/road/Road.java | 161 ++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 src/main/java/electrosphere/server/macro/civilization/road/Road.java diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 7799d442..571fa641 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1877,6 +1877,7 @@ AIs build structures based on their character's race Scaffolding jobs assigned by town to characters Fix character position not saving on creating a player's character for the first time Server utility to move entities scans to see if it needs to create macro data if moving a player's entity +Road macro data generation diff --git a/src/main/java/electrosphere/server/macro/MacroData.java b/src/main/java/electrosphere/server/macro/MacroData.java index 8a649bf5..462ab110 100644 --- a/src/main/java/electrosphere/server/macro/MacroData.java +++ b/src/main/java/electrosphere/server/macro/MacroData.java @@ -10,6 +10,7 @@ import electrosphere.server.macro.character.Character; import electrosphere.server.macro.character.data.CharacterDataStrings; import electrosphere.server.macro.civilization.Civilization; import electrosphere.server.macro.civilization.CivilizationGenerator; +import electrosphere.server.macro.civilization.road.Road; import electrosphere.server.macro.race.Race; import electrosphere.server.macro.race.RaceMap; import electrosphere.server.macro.spatial.MacroAreaObject; @@ -51,6 +52,11 @@ public class MacroData { */ List structures = new LinkedList(); + /** + * List of roads + */ + List roads = new LinkedList(); + /** * Generates a world * @param seed The seed for the world @@ -240,6 +246,23 @@ public class MacroData { return null; } + /** + * Adds a road + * @param road The road + */ + public void addRoad(Road road){ + road.setId(this.roads.size()); + this.roads.add(road); + } + + /** + * Gets the roads in the macro data + * @return The list of roads + */ + public List getRoads(){ + return this.roads; + } + /** * Gets the list of structures * @return The list of structures diff --git a/src/main/java/electrosphere/server/macro/civilization/CivilizationGenerator.java b/src/main/java/electrosphere/server/macro/civilization/CivilizationGenerator.java index fdf01273..43e8c73c 100644 --- a/src/main/java/electrosphere/server/macro/civilization/CivilizationGenerator.java +++ b/src/main/java/electrosphere/server/macro/civilization/CivilizationGenerator.java @@ -5,9 +5,11 @@ import org.joml.Vector3d; import electrosphere.data.Config; import electrosphere.server.datacell.ServerWorldData; import electrosphere.server.macro.MacroData; +import electrosphere.server.macro.civilization.road.Road; import electrosphere.server.macro.race.Race; import electrosphere.server.macro.town.Town; import electrosphere.server.physics.terrain.manager.ServerTerrainChunk; +import electrosphere.util.ds.Spline3d; /** * Generates civilizations @@ -34,6 +36,11 @@ public class CivilizationGenerator { newCiv.addRace(race); Town startingTown = macroData.addTown(spawnPoint, INITIAL_TOWN_RADIUS, newCiv.getId()); newCiv.addTown(startingTown); + Road.createRoad(macroData, Spline3d.createCatmullRom(new Vector3d[]{ + new Vector3d(spawnPoint).add(-10,0,0), + new Vector3d(spawnPoint), + new Vector3d(spawnPoint).add( 10,0,0), + })); } } diff --git a/src/main/java/electrosphere/server/macro/civilization/road/Road.java b/src/main/java/electrosphere/server/macro/civilization/road/Road.java new file mode 100644 index 00000000..5c068378 --- /dev/null +++ b/src/main/java/electrosphere/server/macro/civilization/road/Road.java @@ -0,0 +1,161 @@ +package electrosphere.server.macro.civilization.road; + +import org.joml.AABBd; +import org.joml.Vector3d; + +import electrosphere.server.macro.MacroData; +import electrosphere.util.ds.Spline3d; + +/** + * A road + */ +public class Road { + + /** + * The default radius + */ + public static final double DEFAULT_RADIUS = 3; + + /** + * The default material + */ + public static final String defaultMaterial = "dirt"; + + /** + * The id of the road + */ + int id; + + /** + * The spline that the road is aligned along + */ + Spline3d spline; + + /** + * The radius of the road + */ + double radius = Road.DEFAULT_RADIUS; + + /** + * The aabb of the road + */ + AABBd aabb; + + /** + * The material that the road is made out of + */ + String roadMaterial = Road.defaultMaterial; + + /** + * Private contructor + */ + private Road(){ } + + /** + * Creates a road + * @param macroData The macro data + * @param spline The spline + * @param material The material for the road + * @return The road + */ + public static Road createRoad(MacroData macroData, Spline3d spline){ + Road road = new Road(); + road.setSpline(spline); + macroData.addRoad(road); + return road; + } + + /** + * Gets the id of the road + * @return The id + */ + public int getId() { + return id; + } + + /** + * Sets the id of the road + * @param id The id + */ + public void setId(int id) { + this.id = id; + } + + /** + * Gets the spline that the road is aligned along + * @return The spline + */ + public Spline3d getSpline() { + return spline; + } + + /** + * Sets the spline that the road is aligned along + * @param spline The spline + */ + public void setSpline(Spline3d spline) { + this.spline = spline; + this.computeAABB(); + } + + /** + * Gets the radius of the road + * @return The radius + */ + public double getRadius() { + return radius; + } + + /** + * Sets the radius of the road + * @param radius The radius + */ + public void setRadius(double radius) { + this.radius = radius; + } + + /** + * Gets the road material + * @return The material + */ + public String getRoadMaterial() { + return roadMaterial; + } + + /** + * Sets the road material + * @param roadMaterial The material + */ + public void setRoadMaterial(String roadMaterial) { + this.roadMaterial = roadMaterial; + } + + /** + * Computes the aabb of the road + */ + private void computeAABB(){ + this.aabb = new AABBd(); + for(Vector3d point : this.spline.getPoints()){ + if(this.aabb.minX > point.x){ + this.aabb.minX = point.x; + } + if(this.aabb.minY > point.y){ + this.aabb.minY = point.y; + } + if(this.aabb.minZ > point.z){ + this.aabb.minZ = point.z; + } + if(this.aabb.maxX < point.x){ + this.aabb.maxX = point.x; + } + if(this.aabb.maxY < point.y){ + this.aabb.maxY = point.y; + } + if(this.aabb.maxZ < point.z){ + this.aabb.maxZ = point.z; + } + } + } + + +}