pathing between roads and structures
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
5c82c0fc93
commit
518c249b9e
@ -2076,6 +2076,7 @@ Reorganizing macro classes
|
||||
Start work on macro pathfinding storage
|
||||
Town constructs nav graph of road nodes
|
||||
Render pathing nodes (still needs some work)
|
||||
Pathing construction between town buildings and road nodes
|
||||
|
||||
|
||||
|
||||
|
||||
@ -295,7 +295,17 @@ public class TownLayout {
|
||||
//build road and structures between curr and next node
|
||||
if(closedSet.contains(newHash)){
|
||||
if(nearPoint.distance(townCenter) < TOWN_CENTER_RADIUS && currPoint.distance(townCenter) < TOWN_CENTER_RADIUS){
|
||||
TownLayout.generateStructuresAlongRoad(realm, town, nearPoint, currPoint, Road.DEFAULT_RADIUS, allowedStructures);
|
||||
MacroPathNode roadPoint1 = positionNodeMap.get(openHash);
|
||||
MacroPathNode roadPoint2 = positionNodeMap.get(newHash);
|
||||
if(roadPoint1 == null || roadPoint2 == null){
|
||||
throw new Error("Failed to resolve road points! " + roadPoint1 + " " + roadPoint2);
|
||||
}
|
||||
TownLayout.generateStructuresAlongRoad(
|
||||
realm, town,
|
||||
roadPoint1, roadPoint2,
|
||||
nearPoint, currPoint, Road.DEFAULT_RADIUS,
|
||||
allowedStructures
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -379,8 +389,14 @@ public class TownLayout {
|
||||
* @param road The road
|
||||
* @param allowedStructures The list of allowed structure types
|
||||
*/
|
||||
private static void generateStructuresAlongRoad(Realm realm, Town town, Vector3d startPoint, Vector3d endPoint, double radius, List<StructureData> allowedStructures){
|
||||
private static void generateStructuresAlongRoad(
|
||||
Realm realm, Town town,
|
||||
MacroPathNode roadPoint1, MacroPathNode roadPoint2,
|
||||
Vector3d startPoint, Vector3d endPoint, double radius,
|
||||
List<StructureData> allowedStructures
|
||||
){
|
||||
MacroData macroData = realm.getMacroData();
|
||||
MacroPathCache pathCache = macroData.getPathCache();
|
||||
|
||||
//get values to scan along
|
||||
int len = (int)startPoint.distance(endPoint);
|
||||
@ -449,6 +465,10 @@ public class TownLayout {
|
||||
if(!macroData.intersectsStruct(aabb)){
|
||||
VirtualStructure struct = VirtualStructure.createStructure(macroData, structureData, currPos, rotation1);
|
||||
town.addStructure(struct);
|
||||
//create pathing node for structure and link it to nearest town centers
|
||||
MacroPathNode structNode = MacroPathNode.create(pathCache, struct, new Vector3d(currPos));
|
||||
structNode.addNeighbor(roadPoint1);
|
||||
structNode.addNeighbor(roadPoint2);
|
||||
//TODO: once have successfully placed this structure type, pick a new one to place
|
||||
}
|
||||
}
|
||||
@ -477,6 +497,10 @@ public class TownLayout {
|
||||
if(!macroData.intersectsStruct(aabb)){
|
||||
VirtualStructure struct = VirtualStructure.createStructure(macroData, structureData, currPos, rotation2);
|
||||
town.addStructure(struct);
|
||||
//create pathing node for structure and link it to nearest town centers
|
||||
MacroPathNode structNode = MacroPathNode.create(pathCache, struct, new Vector3d(currPos));
|
||||
structNode.addNeighbor(roadPoint1);
|
||||
structNode.addNeighbor(roadPoint2);
|
||||
//TODO: once have successfully placed this structure type, pick a new one to place
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,4 +50,14 @@ public class MacroPathCache {
|
||||
return idNodeMap.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a node with the pathing cache
|
||||
* @param node The node
|
||||
*/
|
||||
public void registerNode(MacroPathNode node){
|
||||
node.setId(nodes.size());
|
||||
nodes.add(node);
|
||||
idNodeMap.put(node.getId(),node);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -102,8 +102,7 @@ public class MacroPathNode {
|
||||
*/
|
||||
public static MacroPathNode create(MacroPathCache cache, Object correspondingObject, Vector3d position){
|
||||
MacroPathNode rVal = new MacroPathNode();
|
||||
rVal.setId(cache.getNodes().size());
|
||||
cache.getNodes().add(rVal);
|
||||
cache.registerNode(rVal);
|
||||
|
||||
//set data on the node
|
||||
rVal.position = position;
|
||||
@ -132,8 +131,7 @@ public class MacroPathNode {
|
||||
*/
|
||||
public static MacroPathNode createRoadNode(MacroPathCache cache, Vector3d position){
|
||||
MacroPathNode rVal = new MacroPathNode();
|
||||
rVal.setId(cache.getNodes().size());
|
||||
cache.getNodes().add(rVal);
|
||||
cache.registerNode(rVal);
|
||||
|
||||
//set data on the node
|
||||
rVal.position = position;
|
||||
@ -207,8 +205,12 @@ public class MacroPathNode {
|
||||
* @param neighbor The neighbor
|
||||
*/
|
||||
public void addNeighbor(MacroPathNode neighbor){
|
||||
if(neighbor == null){
|
||||
throw new Error("Invalid neighbor! " + neighbor);
|
||||
}
|
||||
if(!this.neighborNodes.contains(neighbor.getId())){
|
||||
this.neighborNodes.add(neighbor.getId());
|
||||
neighbor.addNeighbor(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user