Files
tidewall/test/capture/terrain_scene.gd
T
claudeandClaude Opus 5.5 be987b6f82 W6: Water and swimming
The simulation has a global sea level (Simulation.sea_level, changed with
set_sea_level and read every tick, so the tide can move it mid-match).
Walkers wade more slowly in water over WADE_DEPTH; in water SWIM_DEPTH deep
they swim: floating head-out, sprint-swimming, diving with crouch, kicking
out with jump, and standing again in the shallows. Falling into deep water
does no fall damage. Water tracks breath, stamina and drowning in whole
ticks: swimming spends stamina, an exhausted swimmer slips under, and with
no breath left the tide phase's drown damage lands once a second. All of
it, plus the sea level, is in the state hash.

WaterView draws the sea surface at the simulation's level with a
procedural shader: depth-tinted colour, foam at the waterline, ripples.

Closes #13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 12:24:50 -05:00

134 lines
5.5 KiB
GDScript

## Capture scenario for the streamed island terrain. The camera stands `lift` metres above
## the ground at `eye` (x, z) and looks at `target`. With `crack_check` the sky is a flat
## magenta that appears nowhere in the terrain, so any crack between chunks shows up as
## magenta pixels for tools/crack_check.gd to count.
extends Node3D
const CRACK_COLOUR: Color = Color(1.0, 0.0, 1.0)
@export var island_seed: int = 2
@export var eye: Vector2 = Vector2(700.0, 760.0)
@export var lift: float = 12.0
@export var target: Vector3 = Vector3(520.0, 35.0, 470.0)
@export var show_lod: bool = false
@export var crack_check: bool = false
@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)
## Draw the sea at `sea_level`. Never in crack checks, where it would hide seams.
@export var show_water: bool = true
@export var sea_level: float = Tuning.SEA_LEVEL_START
## Draw the island's props too.
@export var show_props: bool = false
## When set, frame the first prop of this kind whose surroundings hold at least
## `prop_crowd` others within 25 m: the camera stands `prop_view` from it (x east, y up,
## z south) and looks at it.
@export var prop_kind: String = ""
@export var prop_crowd: int = 0
@export var prop_view: Vector3 = Vector3(10.0, 4.0, 14.0)
## Destroy every `knock_out`th prop near the framed one, to show felled props vanish.
@export var knock_out: int = 0
func _ready() -> void:
var island: Island = Island.generate(island_seed)
var environment: Environment = Environment.new()
if crack_check:
environment.background_mode = Environment.BG_COLOR
environment.background_color = CRACK_COLOUR
environment.ambient_light_source = Environment.AMBIENT_SOURCE_COLOR
environment.ambient_light_color = Color(0.5, 0.5, 0.5)
environment.tonemap_mode = Environment.TONE_MAPPER_LINEAR
else:
var sky_material: ProceduralSkyMaterial = ProceduralSkyMaterial.new()
sky_material.sky_top_color = Color(0.32, 0.5, 0.68)
sky_material.sky_horizon_color = Color(0.82, 0.78, 0.68)
sky_material.ground_bottom_color = Color(0.18, 0.2, 0.2)
sky_material.ground_horizon_color = Color(0.82, 0.78, 0.68)
var sky: Sky = Sky.new()
sky.sky_material = sky_material
environment.background_mode = Environment.BG_SKY
environment.sky = sky
environment.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
environment.ambient_light_energy = 0.45
environment.tonemap_mode = Environment.TONE_MAPPER_FILMIC
environment.fog_enabled = true
environment.fog_light_color = Color(0.78, 0.78, 0.74)
environment.fog_density = 0.0005
environment.fog_aerial_perspective = 0.4
var world: WorldEnvironment = WorldEnvironment.new()
world.environment = environment
add_child(world)
var sun: DirectionalLight3D = DirectionalLight3D.new()
sun.rotation_degrees = Vector3(-35.0, -130.0, 0.0)
sun.light_energy = 0.95
sun.shadow_enabled = not crack_check
sun.directional_shadow_max_distance = 600.0
add_child(sun)
var camera: Camera3D = Camera3D.new()
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
if show_props or not prop_kind.is_empty():
var sim_props: PropSet = PropSet.generate(island, PoiSet.generate(island))
var prop_view_node: PropView = PropView.new()
prop_view_node.setup(sim_props)
add_child(prop_view_node)
if not prop_kind.is_empty():
for prop: int in sim_props.count():
if sim_props.kind_name(prop) != prop_kind:
continue
var at: Vector3 = sim_props.boxes[prop].get_center()
var crowd: PackedInt32Array = sim_props.near(at, 25.0)
if crowd.size() <= prop_crowd:
continue
var base: Vector3 = Vector3(at.x, island.ground.terrain_height(at.x, at.z), at.z)
# Back away along the view offset until no canopy is in the camera's face.
var offset: Vector3 = prop_view
for _try: int in 12:
camera.position = base + offset
camera.position.y = maxf(camera.position.y, island.ground.terrain_height(camera.position.x, camera.position.z) + 1.6)
if sim_props.near(Vector3(camera.position.x, island.ground.terrain_height(camera.position.x, camera.position.z), camera.position.z), 6.0).is_empty():
break
offset *= 1.15
look_at_point = base + Vector3.UP * minf(sim_props.boxes[prop].size.y * 0.5, 3.0)
if knock_out > 0:
for index: int in crowd.size():
if index % knock_out == 1:
sim_props.damage(crowd[index], 100000)
prop_view_node.sync()
break
if show_water and not crack_check:
var water: WaterView = WaterView.new()
water.set_level(sea_level)
add_child(water)
add_child(camera)
camera.look_at(look_at_point)
camera.make_current()
var terrain: TerrainView = TerrainView.new()
terrain.setup(island)
terrain.focus = camera.position
terrain.show_lod = show_lod
terrain.skirts = skirts
add_child(terrain)
terrain.build_all_now()