W4: Points of interest

PoiSet.generate(island) places 10 to 16 points of interest per island from
the seed's "poi" stream: hilltop shrines, lighthouses, docks, salt works,
quarries and fishing hamlets, at least 85 m apart. Each kind has a siting
rule (height band, flatness, coast or summit) that loosens step by step
until its minimum is placed. Piers are sited so their deck clears the
ground all the way out to water 1.5 m deep.

Poi assembles each from modular parts in a local frame turned in quarter
turns, so every solid stays an axis-aligned box: walls with a door and
lintel, plinths, steps down to the ground, roofs, a stair to a loft. Each
POI carries loot spawn markers, exposed through PoiSet.loot_markers(),
and walking routes from open ground into its interiors.

- Simulation adds every POI solid to its ground and never spawns players
  inside one.
- SimGround indexes solids in 8 m cells, so collision queries only test
  nearby boxes. Smoke p95 tick is 0.47 ms with about 300 solids.
- Movement tests the body where it will stand after stepping up, so
  stairs with treads narrower than the body can be climbed. The
  traversal test found the lighthouse stair impassable without it.
- PoiView draws parts as one MultiMesh per look, in the seafaring
  palette. Capture scenarios poi_<kind> frame each kind.
- Summit stone is darker so it no longer reads as snow.

Tests: 30 seeds get every kind within its limits, 10 to 16 in total,
spaced and sited; placement is deterministic; loot markers stand on
floors and are not inside solids; a player walks every route of every
POI on 4 seeds through doors, up steps and the lighthouse stair; stairs
with 0.45 m treads are climbed and a step doesn't carry the body into a
wall; the solid index matches a full scan on 500 queries.

Closes #11

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 14:47:10 -05:00
co-authored by Claude Opus 5.5
parent 8b74485168
commit 5021d13686
23 changed files with 949 additions and 13 deletions
+49 -8
View File
@@ -10,6 +10,9 @@ extends RefCounted
## Ray-marching step for terrain, in metres. Small enough for camera-length rays.
const RAY_STEP: float = 0.05
const RAY_REFINE_STEPS: int = 10
## Side of the squares the solid index buckets by, in metres.
const INDEX_CELL: float = 8.0
const _NO_SOLIDS: PackedInt32Array = []
const _MARGIN_OFFSETS: Array[Vector2] = [
Vector2(1.0, 0.0), Vector2(-1.0, 0.0), Vector2(0.0, 1.0), Vector2(0.0, -1.0),
Vector2(0.7071, 0.7071), Vector2(0.7071, -0.7071), Vector2(-0.7071, 0.7071), Vector2(-0.7071, -0.7071),
@@ -20,8 +23,13 @@ const _MARGIN_OFFSETS: Array[Vector2] = [
var heights: PackedFloat32Array = PackedFloat32Array()
var samples: int = 0
var cell: float = 1.0
## Every solid, in the order added. Add them with add_solid(), which indexes them.
var solids: Array[AABB] = []
## Solids indexed by the INDEX_CELL squares their footprints overlap, so queries only
## test nearby boxes. Vector2i -> PackedInt32Array of indices into `solids`.
var _index: Dictionary = {}
## A flat world at `height`.
static func flat(height: float = 0.0) -> SimGround:
@@ -43,7 +51,37 @@ static func from_heights(values: PackedFloat32Array, side: int, spacing: float)
func add_solid(box: AABB) -> void:
solids.append(box.abs())
var normalised: AABB = box.abs()
var id: int = solids.size()
solids.append(normalised)
var low: Vector2i = _cell_of(normalised.position.x, normalised.position.z)
var high: Vector2i = _cell_of(normalised.end.x, normalised.end.z)
for cz: int in range(low.y, high.y + 1):
for cx: int in range(low.x, high.x + 1):
var key: Vector2i = Vector2i(cx, cz)
var bucket: PackedInt32Array = _index.get(key, PackedInt32Array())
bucket.append(id)
_index[key] = bucket
## Indices of solids whose footprint may overlap the rectangle. May repeat an index when
## the rectangle spans several cells, which every query tolerates.
func solids_near(min_x: float, min_z: float, max_x: float, max_z: float) -> PackedInt32Array:
if _index.is_empty():
return _NO_SOLIDS
var low: Vector2i = _cell_of(min_x, min_z)
var high: Vector2i = _cell_of(max_x, max_z)
if low == high:
return _index.get(low, _NO_SOLIDS)
var found: PackedInt32Array = PackedInt32Array()
for cz: int in range(low.y, high.y + 1):
for cx: int in range(low.x, high.x + 1):
found.append_array(_index.get(Vector2i(cx, cz), _NO_SOLIDS))
return found
func _cell_of(x: float, z: float) -> Vector2i:
return Vector2i(floori(x / INDEX_CELL), floori(z / INDEX_CELL))
## Terrain height at (x, z), bilinearly interpolated.
@@ -80,7 +118,8 @@ func walkable_terrain(x: float, z: float) -> bool:
## top of a solid. Solid tops are always walkable.
func support_height(x: float, z: float, max_y: float) -> float:
var best: float = terrain_height(x, z)
for box: AABB in solids:
for id: int in solids_near(x, z, x, z):
var box: AABB = solids[id]
var top: float = box.end.y
if top > best and top <= max_y and _inside_footprint(box, x, z, 0.0):
best = top
@@ -90,7 +129,8 @@ func support_height(x: float, z: float, max_y: float) -> float:
## True when the best support under (x, z) up to `max_y` is the top of a solid.
func support_is_solid(x: float, z: float, max_y: float) -> bool:
var terrain: float = terrain_height(x, z)
for box: AABB in solids:
for id: int in solids_near(x, z, x, z):
var box: AABB = solids[id]
var top: float = box.end.y
if top > terrain and top <= max_y and _inside_footprint(box, x, z, 0.0):
return true
@@ -100,7 +140,8 @@ func support_is_solid(x: float, z: float, max_y: float) -> bool:
## True if a player body at `feet` overlaps a solid. Solids whose top is within
## `step` of the feet don't count, so they can be stepped onto.
func body_blocked(feet: Vector3, radius: float, height: float, step: float) -> bool:
for box: AABB in solids:
for id: int in solids_near(feet.x - radius, feet.z - radius, feet.x + radius, feet.z + radius):
var box: AABB = solids[id]
if box.end.y <= feet.y + step or box.position.y >= feet.y + height:
continue
if _inside_footprint(box, feet.x, feet.z, radius):
@@ -112,8 +153,8 @@ func body_blocked(feet: Vector3, radius: float, height: float, step: float) -> b
## to the first hit, or 1.0 if nothing is hit. A ray starting inside something returns 0.
func raycast(from: Vector3, to: Vector3) -> float:
var nearest: float = 1.0
for box: AABB in solids:
nearest = minf(nearest, _ray_box(from, to, box))
for id: int in solids_near(minf(from.x, to.x), minf(from.z, to.z), maxf(from.x, to.x), maxf(from.z, to.z)):
nearest = minf(nearest, _ray_box(from, to, solids[id]))
return minf(nearest, _ray_terrain(from, to, nearest))
@@ -128,8 +169,8 @@ func point_inside(point: Vector3, margin: float = 0.0) -> bool:
var probe: Vector2 = offset * margin
if point.y < terrain_height(point.x + probe.x, point.z + probe.y):
return true
for box: AABB in solids:
if box.grow(margin).has_point(point):
for id: int in solids_near(point.x - margin, point.z - margin, point.x + margin, point.z + margin):
if solids[id].grow(margin).has_point(point):
return true
return false