Files
tidewall/test/client/test_weather.gd
T
claudeandClaude Opus 5.5 4bc2171b01 H15: Re-check the underwater murk whenever the camera moves
MatchView.setup() syncs with the camera at the origin, which is under the sea
once it has risen, and nothing re-checked the murk when the camera was then
placed. Captures of the late match (match_tide, match_final, match_results)
came out as flat teal, and in the game every camera cut showed one frame of
the wrong murk, since ClientSession syncs before moving the camera.

_focus(), which every camera placement calls, now applies the weather again
for the camera's new position. Test: a view under a risen sea, moved with no
sync, follows the camera in and out of the murk.

Closes #84

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:08:54 -05:00

130 lines
5.9 KiB
GDScript

extends TestCase
## A6: the weather and light follow the tide's schedule (replicated state only), and
## the match view shows them: sky, sun, haze, the sea's roughness, rain and the view
## under water.
func test_before_the_tide_it_is_a_clear_afternoon() -> void:
var calm: Weather = Weather.at(null, 500)
assert_eq(calm.storm, 0.0)
assert_eq(calm.day, 0.0)
assert_eq(calm.rain(), 0.0)
assert_eq(calm.sky_top(), Palette.SKY_TOP)
assert_eq(calm.sky_horizon(), Palette.SKY_HAZE)
assert_near(calm.fog_density(), Weather.FOG_CLEAR, 0.000001)
assert_near(calm.sun_elevation(), Weather.SUN_HIGH, 0.001)
func test_the_storm_builds_through_every_phase_to_a_gale_at_sudden_death() -> void:
var tide: Tide = Tide.new(1000)
var last: float = -1.0
var at: int = 1000
var step: int = maxi(tide.sudden_death_offset() / 40, 1)
while at <= 1000 + tide.sudden_death_offset():
var now: Weather = Weather.at(tide, at)
assert_true(now.storm >= last, "never eases: %f after %f" % [now.storm, last])
last = now.storm
at += step
assert_near(Weather.at(tide, 1000 + tide.sudden_death_offset()).storm, 1.0, 0.0001)
assert_near(Weather.at(tide, 1000 + tide.time_limit_offset()).storm, 1.0, 0.0001, "still a gale in sudden death")
assert_eq(Weather.at(tide, 1000).storm, 0.0, "calm at the first tide")
var gale: Weather = Weather.at(tide, 1000 + tide.sudden_death_offset())
assert_eq(gale.rain(), 1.0)
assert_near(gale.wind(), 1.0, 0.0001)
assert_eq(gale.sky_top(), Palette.STORM_SKY)
assert_true(gale.fog_density() > Weather.FOG_CLEAR * 1.5)
assert_true(gale.fog_density() <= 0.0012, "haze is mood, not cover")
var halfway: Weather = Weather.at(tide, 1000 + tide.sudden_death_offset() / 4)
assert_eq(halfway.rain(), 0.0, "no rain early on")
func test_the_light_lowers_and_warms_to_dusk() -> void:
var tide: Tide = Tide.new(0)
var noon: Weather = Weather.at(tide, 0)
var dusk: Weather = Weather.at(tide, tide.time_limit_offset())
assert_near(dusk.day, 1.0, 0.0001)
assert_near(dusk.sun_elevation(), Weather.SUN_LOW, 0.001)
assert_eq(dusk.sun_colour(), Palette.DUSK_SUN)
assert_eq(noon.sun_colour(), Color.WHITE)
assert_true(dusk.sun_energy() < noon.sun_energy() * 0.5, "dusk in a gale is dim")
assert_true(dusk.sun_elevation() > 0.0, "the sun never sets inside a match")
func test_every_client_sees_the_same_weather_from_the_same_tick() -> void:
var one: Weather = Weather.at(Tide.new(300), 9000)
var two: Weather = Weather.at(Tide.new(300), 9000)
assert_eq(one.storm, two.storm)
assert_eq(one.day, two.day)
assert_eq(one.sky_horizon(), two.sky_horizon())
func test_the_match_view_shows_the_weather() -> void:
var sim: Simulation = Simulation.new(3, SimGround.flat(-20.0))
var view: MatchView = MatchView.new()
view.setup(sim, 0)
var sky: ProceduralSkyMaterial = view.weather.environment.sky.sky_material as ProceduralSkyMaterial
assert_eq(sky.sky_top_color, Palette.SKY_TOP)
assert_false(view.weather.rain().emitting, "no rain in the lobby")
sim.tide = Tide.new(-Tide.new(0).sudden_death_offset())
view.sync()
assert_eq(sky.sky_top_color, Palette.STORM_SKY)
assert_near(view.water.sea_state, 1.0, 0.0001)
assert_near(float(view.water.material().get_shader_parameter("sea_state")), 1.0, 0.0001)
assert_true(view.weather.rain().emitting, "rain in the gale")
assert_near(view.sun.rotation_degrees.x, -Weather.at(sim.tide, sim.tick).sun_elevation(), 0.001)
assert_near(view.weather.environment.fog_density, Weather.at(sim.tide, sim.tick).fog_density(), 0.000001)
view.free()
func test_under_water_the_view_closes_in_and_the_rain_stops() -> void:
var sim: Simulation = Simulation.new(3, SimGround.flat(-20.0))
sim.tide = Tide.new(-Tide.new(0).sudden_death_offset())
var view: MatchView = MatchView.new()
view.setup(sim, 0)
view.look_from(Vector3(500.0, sim.sea_level - 2.0, 500.0), Vector3(510.0, sim.sea_level - 2.0, 500.0))
view.sync()
assert_true(view.weather.underwater)
assert_eq(view.weather.environment.fog_light_color, Palette.SEA_MURK)
assert_near(view.weather.environment.fog_density, Weather.FOG_UNDER, 0.000001)
assert_false(view.weather.rain().emitting, "no rain under water")
view.look_from(Vector3(500.0, sim.sea_level + 2.0, 500.0), Vector3(510.0, sim.sea_level, 500.0))
view.sync()
assert_false(view.weather.underwater)
assert_ne(view.weather.environment.fog_light_color, Palette.SEA_MURK)
view.free()
func test_the_sea_takes_its_colours_from_the_palette_and_a_heightmap() -> void:
var view: WaterView = WaterView.new()
var material: ShaderMaterial = view.material()
assert_eq(material.get_shader_parameter("deep_colour"), Palette.SEA_DEEP)
assert_eq(material.get_shader_parameter("storm_colour"), Palette.SEA_STORM)
assert_eq(material.get_shader_parameter("murk_colour"), Palette.SEA_MURK)
var island: Island = Island.generate(2)
view.set_ground(island.ground)
var heights: Texture2D = material.get_shader_parameter("terrain_heights")
assert_not_null(heights)
assert_eq(heights.get_width(), island.ground.samples)
assert_near(float(material.get_shader_parameter("terrain_cell")), island.ground.cell, 0.0001)
view.set_level(5.0)
assert_true(view.is_under(Vector3(1.0, 4.0, 1.0)))
assert_false(view.is_under(Vector3(1.0, 6.0, 1.0)))
view.free()
func test_moving_the_camera_rechecks_the_murk_without_a_sync() -> void:
# H6: setup() syncs with the camera at the origin, under a risen sea. A camera
# placed afterwards, with no sync of its own, must not keep that murk.
var sim: Simulation = Simulation.new(3, SimGround.flat(-20.0))
sim.set_sea_level(30.0)
var view: MatchView = MatchView.new()
view.setup(sim, 0)
assert_true(view.weather.underwater, "the camera starts at the origin, under the sea")
view.overview()
assert_false(view.weather.underwater, "the overview is high over the sea")
assert_ne(view.weather.environment.fog_light_color, Palette.SEA_MURK)
view.look_from(Vector3(500.0, 10.0, 500.0), Vector3(510.0, 10.0, 500.0))
assert_true(view.weather.underwater, "and back under it")
view.free()