town generates a structure
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-20 13:48:09 -04:00
parent 46ce42eb29
commit fd74af2e88
6 changed files with 59 additions and 0 deletions

View File

@ -1920,6 +1920,7 @@ Macro data blocks terrain and block generation until it is ready
Content generation blocks for macro data generation
Roads block content generation
Properly layout roads along town points in TownLayout
Town generates a structure -- scaffolding for doing it across roads

View File

@ -2,6 +2,9 @@ package electrosphere.data.struct;
import org.joml.Vector3d;
import electrosphere.data.block.fab.BlockFab;
import electrosphere.util.annotation.Exclude;
/**
* Data about a structure
*/
@ -22,6 +25,12 @@ public class StructureData {
*/
String fabPath;
/**
* The actually loaded fab
*/
@Exclude
BlockFab fab;
/**
* The dimensions of the structure
*/
@ -103,6 +112,22 @@ public class StructureData {
public void setPlacementOffset(Vector3d placementOffset) {
this.placementOffset = placementOffset;
}
/**
* Gets the fab
* @return The fab
*/
public BlockFab getFab(){
return fab;
}
/**
* Sets the fab
* @param fab The fab
*/
public void setFab(BlockFab fab){
this.fab = fab;
}
}

View File

@ -9,6 +9,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import electrosphere.data.block.fab.BlockFab;
import electrosphere.util.FileUtils;
/**
@ -96,6 +97,7 @@ public class StructureDataLoader {
List<StructureData> typeList = StructureDataLoader.recursiveReadStructureLoader(rVal, initialPath);
for(StructureData type : typeList){
rVal.putType(type.getId(), type);
type.setFab(BlockFab.read(FileUtils.getAssetFile(type.getFabPath())));
}
return rVal;
}

View File

@ -21,6 +21,7 @@ import electrosphere.util.FileUtils;
import java.util.Random;
import org.joml.AABBd;
import org.joml.Vector3d;
/**
@ -301,6 +302,23 @@ public class MacroData {
rVal.addAll(this.towns);
return rVal;
}
/**
* Checks if the aabb intersects any existing structs
* @param aabb The aabb
* @return true if it intersects any existing structs, false otheriwse
*/
public boolean intersectsStruct(AABBd aabb){
List<MacroAreaObject> areaObjs = new LinkedList<MacroAreaObject>();
areaObjs.addAll(this.roads);
areaObjs.addAll(this.structures);
for(MacroAreaObject areaObj : areaObjs){
if(areaObj.getAABB().testAABB(aabb)){
return true;
}
}
return false;
}
/**
* Describes the world

View File

@ -60,6 +60,7 @@ public class VirtualStructure implements MacroAreaObject {
public static VirtualStructure createStructure(MacroData macroData, StructureData data, Vector3d position){
VirtualStructure rVal = new VirtualStructure();
rVal.fabPath = data.getFabPath();
rVal.fab = data.getFab();
rVal.type = data.getId();
rVal.position = position;
rVal.aabb = new AABBd(new Vector3d(position), new Vector3d(position).add(data.getDimensions()));

View File

@ -4,6 +4,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import org.joml.AABBd;
import org.joml.Vector3d;
import org.joml.Vector3i;
@ -15,6 +16,7 @@ import electrosphere.server.macro.MacroData;
import electrosphere.server.macro.civilization.Civilization;
import electrosphere.server.macro.civilization.road.Road;
import electrosphere.server.macro.race.Race;
import electrosphere.server.macro.structure.VirtualStructure;
import electrosphere.util.math.VoronoiUtils;
/**
@ -88,6 +90,16 @@ public class TownLayout {
//up-facing road
Road.createRoad(macroData, upNodeLoc, centerNodeLoc);
//generate structures along the road
StructureData structureData = allowedStructures.get(0);
Vector3d pos = new Vector3d(centerNodeLoc).add(10,0,10);
pos.y = realm.getServerWorldData().getServerTerrainManager().getElevation(pos);
AABBd aabb = new AABBd();
aabb.setMin(pos);
aabb.setMax(new Vector3d(pos).add(structureData.getDimensions()));
if(!macroData.intersectsStruct(aabb)){
VirtualStructure.createStructure(macroData, structureData, pos);
}
//right-facing road
Road.createRoad(macroData, rightNodeLoc, centerNodeLoc);