diff --git a/CLAUDE.md b/CLAUDE.md index e983e1e..58a1bf6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -43,6 +43,7 @@ continuity. | `make chart-captures` | Renders the chart and minimap of seed 2 with the first tide forecast, and again once it has risen (`captures/chart_*.png`, about 2 min). Needs Docker. Look at them. | | `make poi-captures` | Renders each kind of point of interest (`captures/poi_*.png`, about 3 min). Needs Docker. Look at them. | | `make build-captures` | Renders the fort and the wall test card: a row per material, a column per state (half built, intact, worn, battered), and a battered ramp (`captures/build_*.png`), and the barge and sea chests (`captures/vessels.png`), about 2 min. Needs Docker. Look at them. | +| `tools/capture.sh canopy captures/canopy.png` | H11: the shoulder camera on a player against a pine, with canopies in the way hidden (`canopy_before` puts them back). | | `make style-captures` | Renders a hamlet and a dock with and without the woodcut print pass (`captures/style_*.png`). Needs Docker. | | `make soak` | The 24-client network soak (N8): a real server and 24 headless `SoakPlayer` clients in three processes, each behind a `UdpRelay` adding 60 ms, +/-20 ms jitter and 2% loss each way, for two whole matches in real time (about 30 min, under `nice`). Fails on a world-hash mismatch, errors, unreadable packets, a client that didn't play every match, memory growth between matches, or a p99 tick over budget. `SOAK_MATCHES`, `SOAK_CLIENTS`, `SOAK_PROCS`, `SOAK_LATENCY`, `SOAK_JITTER`, `SOAK_LOSS` scale it. Results in `build/soak/report.txt`. | | `make soak-selfcheck` | About a minute: tampers with one client's world and checks the soak's comparison catches it and only it. | diff --git a/src/client/match_view.gd b/src/client/match_view.gd index 2e3f910..c11c804 100644 --- a/src/client/match_view.gd +++ b/src/client/match_view.gd @@ -105,6 +105,10 @@ func follow(entity_id: int, pitch: float = NAN, look_yaw: float = NAN) -> bool: feet = figure.position camera.transform = rig.solve(feet, yaw, look_pitch, player.crouching, sim.ground) camera.fov = rig.fov() + # Pines between the lens and the player are hidden (H11). + var height: float = Movement.body_height(player) + var lines: Array[Vector3] = [feet + Vector3(0.0, height * 0.6, 0.0), feet + Vector3(0.0, height, 0.0)] + props.clear_view(sim.ground, camera.transform.origin, lines) _focus() return true @@ -138,6 +142,8 @@ func frame(entity_id: int, distance: float = 6.0, height: float = 2.6, beyond: V func look_from(eye: Vector3, target: Vector3) -> void: camera.transform = Transform3D(Basis.IDENTITY, eye).looking_at(target, Vector3.UP) camera.fov = CameraRig.FOV + var none: Array[Vector3] = [] + props.clear_view(sim.ground, eye, none) _focus() diff --git a/src/client/props/prop_view.gd b/src/client/props/prop_view.gd index ddadd70..6bd1c0a 100644 --- a/src/client/props/prop_view.gd +++ b/src/client/props/prop_view.gd @@ -7,6 +7,11 @@ ## and coloured per vertex in the weathered palette from docs/ORIGINALITY.md. Each ## instance gets a slight colour shift so a stand of pines isn't one flat green. ## +## A pine's canopy is drawn but doesn't block (only its trunk does), so the shoulder +## camera can end up behind or inside one. `clear_view()` hides every pine whose drawn +## shape crosses the line from the camera to the followed player's chest or head, and +## brings it back once the line is clear (H11). +## ## Destruction comes from the simulation: `sync()` reads new entries in ## PropSet.destroyed and collapses those instances to nothing. Collision never comes from ## here; SimGround holds the props' boxes on the server and in client prediction alike. @@ -46,6 +51,11 @@ var _nodes: Array[MultiMeshInstance3D] = [] var _hidden: PackedByteArray = PackedByteArray() ## How many entries of PropSet.destroyed have been applied. var _cursor: int = 0 +## Pines hidden by clear_view(), and the pine mesh's bounds in unit space. +var _screened: PackedInt32Array = PackedInt32Array() +var _pine_bounds: AABB = AABB() +## How far a canopy may spread past its trunk's box, in metres, for the search. +const CANOPY_REACH: float = 4.0 ## Builds every instance for `props`. Call once, before or after adding to the tree. @@ -59,6 +69,8 @@ func setup(props: PropSet) -> void: var meshes: Array[ArrayMesh] = [] for kind: String in PropSet.KINDS: meshes.append(build_mesh(kind)) + _pine_bounds = meshes[PropSet.KINDS.find("pine")].get_aabb() + _screened = PackedInt32Array() # (chunk key, kind code) -> prop IDs, in prop order so the layout is deterministic. var groups: Dictionary = {} var keys: Array[Vector3i] = [] @@ -126,7 +138,47 @@ func _process(_delta: float) -> void: func is_drawn(prop: int) -> bool: - return _hidden[prop] == 0 + return _hidden[prop] == 0 and not _screened.has(prop) + + +## Hides the pines whose drawn shape crosses a line from `eye` to any of `targets`, or +## holds `eye`, and shows again those that no longer do. Candidates come from the +## trunks in `ground` around the lines. With no targets, shows them all again. +func clear_view(ground: SimGround, eye: Vector3, targets: Array[Vector3]) -> void: + var wanted: PackedInt32Array = PackedInt32Array() + if not targets.is_empty(): + var low: Vector2 = Vector2(eye.x, eye.z) + var high: Vector2 = low + for target: Vector3 in targets: + low = Vector2(minf(low.x, target.x), minf(low.y, target.z)) + high = Vector2(maxf(high.x, target.x), maxf(high.y, target.z)) + for solid_id: int in ground.solids_near(low.x - CANOPY_REACH, low.y - CANOPY_REACH, high.x + CANOPY_REACH, high.y + CANOPY_REACH): + var prop: int = _props.prop_of_solid(solid_id) + if prop < 0 or _hidden[prop] != 0 or _props.kind_name(prop) != "pine" or wanted.has(prop): + continue + var shape: AABB = canopy_bounds(prop) + var blocks: bool = shape.has_point(eye) + for target: Vector3 in targets: + blocks = blocks or shape.intersects_segment(eye, target) + if blocks: + wanted.append(prop) + for prop: int in _screened: + if not wanted.has(prop) and _hidden[prop] == 0: + _nodes[_node_of[prop]].multimesh.set_instance_transform(_index_of[prop], instance_transform(_props, prop)) + for prop: int in wanted: + if not _screened.has(prop): + _nodes[_node_of[prop]].multimesh.set_instance_transform(_index_of[prop], Transform3D(Basis.from_scale(Vector3.ZERO), Vector3.ZERO)) + _screened = wanted + + +## Pines clear_view() is hiding now. +func screened() -> PackedInt32Array: + return _screened + + +## The world-space box around a pine as drawn, canopy and all. +func canopy_bounds(prop: int) -> AABB: + return instance_transform(_props, prop) * _pine_bounds func node_count() -> int: diff --git a/test/capture/canopy.tscn b/test/capture/canopy.tscn new file mode 100644 index 0000000..6ffef4d --- /dev/null +++ b/test/capture/canopy.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=3] + +[ext_resource type="Script" path="res://test/capture/canopy_scene.gd" id="1"] + +[node name="CaptureCanopy" type="Node3D"] +script = ExtResource("1") +screen = true diff --git a/test/capture/canopy_before.tscn b/test/capture/canopy_before.tscn new file mode 100644 index 0000000..79ac295 --- /dev/null +++ b/test/capture/canopy_before.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=3] + +[ext_resource type="Script" path="res://test/capture/canopy_scene.gd" id="1"] + +[node name="CaptureCanopy" type="Node3D"] +script = ExtResource("1") +screen = false diff --git a/test/capture/canopy_scene.gd b/test/capture/canopy_scene.gd new file mode 100644 index 0000000..adaa76b --- /dev/null +++ b/test/capture/canopy_scene.gd @@ -0,0 +1,46 @@ +## Capture scenario for H11: a player standing against a pine in a crowded stand, seen +## from the shoulder camera at a yaw that puts canopies between the lens and the player. +## With `screen` off, the hidden pines are put back, showing what the fix prevents. +extends Node3D + +@export var screen: bool = true +@export var match_seed: int = 2 + + +func _ready() -> void: + var sim: Simulation = Simulation.new(match_seed) + var best: int = -1 + var crowd: int = -1 + for prop: int in sim.props.count(): + if sim.props.kind_name(prop) != "pine" or prop % 7 != 0: + continue + var around: int = sim.props.near(sim.props.boxes[prop].get_center(), 6.0).size() + if around > crowd: + crowd = around + best = prop + var trunk: AABB = sim.props.boxes[best] + var player: SimEntity = sim.entities.find(sim.add_player()) + player.drop_state = Drop.NONE + player.on_ground = true + player.health = 100 + var x: float = trunk.end.x + Tuning.PLAYER_RADIUS + 0.05 + player.position = Vector3(x, sim.ground.terrain_height(x, trunk.get_center().z), trunk.get_center().z) + var view: MatchView = MatchView.new() + view.setup(sim, player.id) + add_child(view) + view.sync() + # The yaw that hides the most pines: the worst view without the fix. + var worst: float = 0.0 + var most: int = -1 + for step: int in 16: + var yaw: float = TAU * step / 16.0 + view.follow(player.id, deg_to_rad(-6.0), yaw) + if view.props.screened().size() > most: + most = view.props.screened().size() + worst = yaw + view.follow(player.id, deg_to_rad(-6.0), worst) + print("canopy_scene: pine %d, %d pines around, %d hidden at yaw %.2f, screen %s" % [best, crowd, most, worst, screen]) + if not screen: + var none: Array[Vector3] = [] + view.props.clear_view(sim.ground, view.camera.transform.origin, none) + view.settle() diff --git a/test/capture/canopy_scene.gd.uid b/test/capture/canopy_scene.gd.uid new file mode 100644 index 0000000..36b79d7 --- /dev/null +++ b/test/capture/canopy_scene.gd.uid @@ -0,0 +1 @@ +uid://c5188opmonsli diff --git a/test/client/test_match_view.gd b/test/client/test_match_view.gd index 1c921c3..fbcee3d 100644 --- a/test/client/test_match_view.gd +++ b/test/client/test_match_view.gd @@ -80,3 +80,55 @@ func test_the_camera_follows_a_player_and_frames_one() -> void: view.overview() assert_true(view.camera.position.y > 200.0) view.free() + + +## H11: a pine's canopy never hides the followed player from the shoulder camera. +func test_pines_between_the_shoulder_camera_and_the_player_are_hidden() -> void: + var loop: ServerLoop = _match() + var sim: Simulation = loop.sim + var view: MatchView = MatchView.new() + view.setup(sim, 1) + while not sim.drop.finished: + loop.run_tick() + # The pine with the most pines around it, and a player standing against its trunk. + var best: int = -1 + var crowd: int = -1 + for prop: int in sim.props.count(): + if sim.props.kind_name(prop) != "pine" or prop % 7 != 0: + continue + var around: int = sim.props.near(sim.props.boxes[prop].get_center(), 6.0).size() + if around > crowd: + crowd = around + best = prop + assert_true(best >= 0) + var trunk: AABB = sim.props.boxes[best] + var player: SimEntity = sim.entities.find(1) + player.drop_state = Drop.NONE + player.position = Vector3(trunk.end.x + Tuning.PLAYER_RADIUS + 0.05, sim.ground.terrain_height(trunk.end.x + 0.4, trunk.get_center().z), trunk.get_center().z) + view.sync() + var hid_any: bool = false + var hidden_at_some_yaw: Dictionary = {} + for step: int in 16: + var yaw: float = TAU * step / 16.0 + assert_true(view.follow(1, 0.0, yaw)) + var eye: Vector3 = view.camera.transform.origin + var height: float = Movement.body_height(player) + var chest: Vector3 = player.position + Vector3(0.0, height * 0.6, 0.0) + var head: Vector3 = player.position + Vector3(0.0, height, 0.0) + for prop: int in sim.props.near(player.position, 20.0): + if sim.props.kind_name(prop) != "pine": + continue + var shape: AABB = view.props.canopy_bounds(prop) + var blocks: bool = shape.has_point(eye) or shape.intersects_segment(eye, chest) or shape.intersects_segment(eye, head) + assert_eq(view.props.is_drawn(prop), not blocks, "yaw %d: pine %d %s" % [step, prop, "blocks the view" if blocks else "is hidden for nothing"]) + if blocks: + hidden_at_some_yaw[prop] = true + hid_any = hid_any or not view.props.screened().is_empty() + assert_true(hid_any, "standing against a pine, some yaw looks through a canopy") + # Looking from anywhere else brings them all back. (Headless Godot keeps no MultiMesh + # instance transforms, so the restored transform itself is checked by capture.) + view.overview() + assert_eq(view.props.screened().size(), 0) + for prop: int in hidden_at_some_yaw: + assert_true(view.props.is_drawn(prop)) + view.free()