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
+8
View File
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/terrain_scene.gd" id="1"]
[node name="CapturePoi" type="Node3D"]
script = ExtResource("1")
poi_kind = "dock"
poi_view = Vector3(16, 8, 4)
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/terrain_scene.gd" id="1"]
[node name="CapturePoi" type="Node3D"]
script = ExtResource("1")
poi_kind = "hamlet"
+8
View File
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/terrain_scene.gd" id="1"]
[node name="CapturePoi" type="Node3D"]
script = ExtResource("1")
poi_kind = "lighthouse"
poi_view = Vector3(10, 9, 30)
+8
View File
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/terrain_scene.gd" id="1"]
[node name="CapturePoi" type="Node3D"]
script = ExtResource("1")
poi_kind = "quarry"
poi_view = Vector3(10, 12, 30)
+8
View File
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/terrain_scene.gd" id="1"]
[node name="CapturePoi" type="Node3D"]
script = ExtResource("1")
poi_kind = "salt_works"
poi_view = Vector3(10, 12, 30)
+8
View File
@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/terrain_scene.gd" id="1"]
[node name="CapturePoi" type="Node3D"]
script = ExtResource("1")
poi_kind = "shrine"
poi_view = Vector3(10, 12, 30)
+17 -1
View File
@@ -15,6 +15,10 @@ const CRACK_COLOUR: Color = Color(1.0, 0.0, 1.0)
@export var fov: float = 70.0
## Off only in terrain_cracks_control, which must show cracks.
@export var skirts: bool = true
## When set, draw the island's points of interest and frame the first one of this kind:
## the camera stands `poi_view` (x right, y up, z out of the front) from its origin.
@export var poi_kind: String = ""
@export var poi_view: Vector3 = Vector3(6.0, 7.0, 22.0)
func _ready() -> void:
@@ -58,8 +62,20 @@ func _ready() -> void:
camera.fov = fov
camera.far = 2000.0
camera.position = Vector3(eye.x, island.ground.terrain_height(eye.x, eye.y) + lift, eye.y)
var look_at_point: Vector3 = target
if not poi_kind.is_empty():
var placed: PoiSet = PoiSet.generate(island)
var view: PoiView = PoiView.new()
view.setup(placed)
add_child(view)
for poi: Poi in placed.pois:
if poi.kind == poi_kind:
camera.position = poi.to_world(poi_view)
camera.position.y = maxf(camera.position.y, island.ground.terrain_height(camera.position.x, camera.position.z) + 2.0)
look_at_point = poi.origin + Vector3.UP * 2.5
break
add_child(camera)
camera.look_at(target)
camera.look_at(look_at_point)
camera.make_current()
var terrain: TerrainView = TerrainView.new()
+27
View File
@@ -273,3 +273,30 @@ func _rough_simulation() -> Simulation:
for _index: int in 4:
sim.add_player()
return sim
func test_climbs_stairs_with_treads_narrower_than_the_body() -> void:
# Treads of 0.45 m are narrower than the 0.8 m body, so the next riser is under the
# body's front edge before its centre is lifted onto the current step. (Treads
# narrower than the 0.4 m radius can't be climbed: the second riser is reached
# before the centre is on the first.)
var ground: SimGround = SimGround.flat()
for index: int in 12:
ground.add_solid(AABB(Vector3(10.0 + index * 0.45, 0.0, 8.0), Vector3(0.45, 0.35 * (index + 1), 4.0)))
# A landing at the top, so the player stays up there.
ground.add_solid(AABB(Vector3(15.4, 0.0, 8.0), Vector3(20.0, 0.35 * 12, 4.0)))
var player: SimEntity = _player(Vector3(8.0, 0.0, 10.0))
_run(player, ground, 90, Vector2(0.0, 1.0), EAST)
assert_near(player.position.y, 0.35 * 12, 0.01, "should stand on the top step")
assert_true(player.position.x > 15.0, "should have walked up the flight")
func test_a_step_does_not_let_the_body_through_a_wall_behind_it() -> void:
# A climbable 0.4 m step with a 1.5 m wall right behind it: stepping up must not
# carry the body into the wall.
var ground: SimGround = SimGround.flat()
ground.add_solid(AABB(Vector3(10.0, 0.0, 8.0), Vector3(0.5, 0.4, 4.0)))
ground.add_solid(AABB(Vector3(10.5, 0.0, 8.0), Vector3(1.0, 1.5, 4.0)))
var player: SimEntity = _player(Vector3(8.0, 0.0, 10.0))
_run(player, ground, 90, Vector2(0.0, 1.0), EAST)
assert_true(player.position.x < 10.5 - Tuning.PLAYER_RADIUS + 0.01, "walked into the wall to x %.2f" % player.position.x)
+120
View File
@@ -0,0 +1,120 @@
extends TestCase
## Seeds for the placement checks, and the fewer, slower traversal walks.
const PLACEMENT_SEEDS: int = 30
const TRAVERSAL_SEEDS: Array[int] = [1, 2, 3, 4]
## A route segment must be walked within this many seconds.
const SEGMENT_SECONDS: float = 12.0
const ARRIVE_METRES: float = 0.45
func test_every_island_gets_every_kind_well_spaced() -> void:
var kinds: int = Tuning.POI_KINDS.size()
assert_true(kinds >= 6, "issue W4 asks for at least 6 kinds")
for seed_value: int in range(1, PLACEMENT_SEEDS + 1):
var island: Island = Island.generate(seed_value)
var placed: PoiSet = PoiSet.generate(island)
var label: String = "seed %d" % seed_value
var total: int = placed.pois.size()
assert_true(total >= Tuning.POI_MIN_TOTAL and total <= Tuning.POI_MAX_TOTAL, "%s placed %d" % [label, total])
for kind: String in Tuning.POI_KINDS:
var count: int = placed.count_of(kind)
assert_true(count >= Tuning.POI_KINDS[kind]["min"] and count <= Tuning.POI_KINDS[kind]["max"],
"%s: %d %s" % [label, count, kind])
for a: int in total:
var here: Vector3 = placed.pois[a].origin
assert_true(here.y > 0.0, "%s: %s sited in the sea" % [label, placed.pois[a].kind])
for b: int in range(a + 1, total):
var gap: float = Vector2(here.x, here.z).distance_to(Vector2(placed.pois[b].origin.x, placed.pois[b].origin.z))
assert_true(gap >= Tuning.POI_SPACING_METRES - 0.001, "%s: two sites %.0f m apart" % [label, gap])
_check_sites(placed, label)
func test_same_seed_places_the_same_points_of_interest() -> void:
var first: PoiSet = PoiSet.generate(Island.generate(9))
var second: PoiSet = PoiSet.generate(Island.generate(9))
assert_eq(first.pois.size(), second.pois.size())
for index: int in first.pois.size():
assert_eq(first.pois[index].origin, second.pois[index].origin)
assert_eq(first.pois[index].solids, second.pois[index].solids)
func test_loot_markers_are_exposed_and_stand_on_floors() -> void:
var sim: Simulation = Simulation.new(6)
var markers: Array[Dictionary] = sim.pois.loot_markers()
assert_true(markers.size() >= sim.pois.pois.size(), "every POI should offer loot, got %d markers" % markers.size())
var kinds: Dictionary = {}
for marker: Dictionary in markers:
var at: Vector3 = marker["position"]
kinds[marker["kind"]] = true
var support: float = sim.ground.support_height(at.x, at.z, at.y + 0.5)
assert_near(support, at.y, 0.6, "%s marker at %s floats or is buried" % [marker["kind"], at])
assert_false(sim.ground.body_blocked(at + Vector3.UP * 0.05, 0.3, 1.0, 0.0), "%s marker at %s is inside a solid" % [marker["kind"], at])
assert_eq(kinds.size(), Tuning.POI_KINDS.size(), "every kind has loot")
func test_interiors_are_walkable() -> void:
# The automated traversal: a player walks every route of every POI, from open ground
# outside, through the door and up any stairs, to the loot inside, using the real
# Movement code against the real solids.
var walked: int = 0
for seed_value: int in TRAVERSAL_SEEDS:
var sim: Simulation = Simulation.new(seed_value)
for poi: Poi in sim.pois.pois:
for route: Array in poi.routes:
var failure: String = _walk(sim.ground, route)
assert_eq(failure, "", "seed %d %s at %s" % [seed_value, poi.kind, poi.origin])
walked += 1
assert_true(walked >= 40, "walked only %d routes" % walked)
func test_players_do_not_spawn_inside_buildings() -> void:
var sim: Simulation = Simulation.new(3)
for _index: int in Tuning.SOLO_PLAYERS:
var player: SimEntity = sim.entities.find(sim.add_player())
assert_false(sim.ground.body_blocked(player.position, Tuning.PLAYER_RADIUS, Tuning.PLAYER_HEIGHT, 0.0),
"spawned inside a solid at %s" % player.position)
func _check_sites(placed: PoiSet, label: String) -> void:
for poi: Poi in placed.pois:
var height: float = poi.origin.y
match poi.kind:
"shrine":
assert_true(height >= Tuning.ISLAND_FOREST_TOP * 0.8, "%s: shrine at %.1f m" % [label, height])
"dock":
assert_true(height < 6.0, "%s: dock at %.1f m" % [label, height])
"salt_works":
assert_true(height < Tuning.ISLAND_MARSH_TOP * 3.2, "%s: salt works at %.1f m" % [label, height])
"quarry":
assert_true(height >= Tuning.ISLAND_FOREST_TOP - 6.0, "%s: quarry at %.1f m" % [label, height])
## Walks a player along `route`. Returns "" on success or what went wrong.
func _walk(ground: SimGround, route: Array) -> String:
var player: SimEntity = SimEntity.new(1, SimEntity.ARCHETYPE_PLAYER)
var start: Vector3 = route[0]
player.position = Vector3(start.x, ground.support_height(start.x, start.z, start.y + 1.0), start.z)
player.health = Tuning.PLAYER_MAX_HEALTH
player.on_ground = true
if ground.body_blocked(player.position, Tuning.PLAYER_RADIUS, Tuning.PLAYER_HEIGHT, Tuning.STEP_HEIGHT):
return "route starts inside a solid at %s" % player.position
var tick: int = 0
for index: int in range(1, route.size()):
var target: Vector3 = route[index]
var limit: int = tick + roundi(SEGMENT_SECONDS * Tuning.TICK_RATE_HZ)
while true:
var towards: Vector2 = Vector2(target.x - player.position.x, target.z - player.position.z)
if towards.length() < ARRIVE_METRES:
break
if tick >= limit:
return "stuck at %s heading for waypoint %d %s" % [player.position, index, target]
var speed: float = clampf(towards.length() / (Tuning.WALK_SPEED / Tuning.TICK_RATE_HZ), 0.2, 1.0)
var command: PlayerCommand = PlayerCommand.from_input(tick, Vector2(0.0, speed), atan2(towards.x, towards.y), 0.0)
Movement.step(player, command, ground)
tick += 1
if absf(player.position.y - target.y) > 1.0:
return "reached waypoint %d at height %.2f, expected %.2f" % [index, player.position.y, target.y]
if player.health < Tuning.PLAYER_MAX_HEALTH:
return "took damage on the way"
return ""
+1
View File
@@ -0,0 +1 @@
uid://be2rbacqxhrdk
+29
View File
@@ -83,3 +83,32 @@ func test_body_blocked_respects_step_and_height() -> void:
assert_false(ground.body_blocked(Vector3(2.5, 0.0, 1.0), 0.4, 1.8, 0.0))
assert_false(ground.body_blocked(Vector3(11.0, 0.0, 1.0), 0.4, 1.8, 0.0), "fits under")
assert_true(ground.body_blocked(Vector3(11.0, 0.0, 1.0), 0.4, 2.5, 0.0))
func test_index_finds_solids_across_cells() -> void:
var ground: SimGround = SimGround.flat()
# Spans several index cells, including negative ones.
ground.add_solid(AABB(Vector3(-5.0, 0.0, -5.0), Vector3(30.0, 2.0, 3.0)))
assert_eq(ground.support_height(20.0, -4.0, 5.0), 2.0)
assert_eq(ground.support_height(-4.0, -4.0, 5.0), 2.0)
assert_eq(ground.support_height(20.0, 4.0, 5.0), 0.0)
assert_true(ground.body_blocked(Vector3(12.0, 0.0, -1.7), 0.4, 1.8, 0.0), "radius reaches into the next cell")
# The box's far side from the ray's start is at z = -2, 22 m along a 40 m ray.
assert_near(ground.raycast(Vector3(15.0, 1.0, 20.0), Vector3(15.0, 1.0, -20.0)), 22.0 / 40.0, 0.0001)
func test_index_gives_the_same_answers_as_a_full_scan() -> void:
var ground: SimGround = SimGround.flat()
var random: RandomNumberGenerator = RandomNumberGenerator.new()
random.seed = 5
for _index: int in 200:
var at: Vector3 = Vector3(random.randf_range(0.0, 100.0), random.randf_range(0.0, 4.0), random.randf_range(0.0, 100.0))
ground.add_solid(AABB(at, Vector3(random.randf_range(0.2, 12.0), random.randf_range(0.2, 3.0), random.randf_range(0.2, 12.0))))
for _index: int in 500:
var x: float = random.randf_range(0.0, 100.0)
var z: float = random.randf_range(0.0, 100.0)
var expected: float = 0.0
for box: AABB in ground.solids:
if box.end.y <= 6.0 and x > box.position.x and x < box.end.x and z > box.position.z and z < box.end.z:
expected = maxf(expected, box.end.y)
assert_eq(ground.support_height(x, z, 6.0), expected)