A6: Sea, sky and weather
Weather.at(tide, tick) derives the weather from the tide's schedule alone, so every client sees the same sky with nothing new on the wire: the storm builds from calm at the first tide to a gale at sudden death, and the light runs from mid-afternoon to dusk at the time limit. WeatherView applies it each sync to the sky, sun, fog, ambient light, the sea's roughness and rain around the camera (CPUParticles3D, for both renderers). Under water the view closes into SEA_MURK, the rain stops and the surface is a rippled ceiling seen from below. The sea shader darkens open water and adds chop and whitecaps with the storm, and keeps a breathing foam band at the waterline with a fainter line beyond. In the Compatibility renderer, whose depth texture the shader can't read (the sea came out all foam), water depth comes from a texture of the terrain's heights instead. Sea colours move into Palette; the rain and wind beds follow the weather. Tests: test_weather (7). make check passes (611 tests). Captures: make sea-captures (every tide phase, calm beach, the last land in the gale, under water, and three in the Compatibility renderer). Closes #46 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user