N11: Build ghost, client flood and shot effects in the playable client
- Build ghost: ClientSession shows a BuildGhost in build mode while the client plays, asking Building.check() of its own world and predicted player with the mouse's newest look, so it agrees with the server. - Flooded basins: ClientMirror.follow_flood() spreads the client's flood as the server's tide tick does, from the tide and the pieces it has. WaterView passes a mask of flooded cells (Flood.pours says when it changed) to the sea shader, which leaves dry cells undrawn. - Shots, impacts and swings: a new FX message (NetFx) goes unreliably on the state channel next to each snapshot, with what happened within NET_FX_RADIUS_METRES of what the client watches or involving that player. ClientGame keeps them in `fx` for views and sound. They change no state, so a lost one is a missed flash; sending them reliably would add to the traffic a bad link can least afford (N8). The fuzzer covers the new parser. - Captures: client_build and client_build_refused show the ghost in its allowed and refused tints; client_basin rings shore ground with breakwaters and plays until the tide stands over it, and the server, the client's flood and the drawn sea all keep the basin dry. - Tests: NetFx round trips, limits and malformed input; a landed player's shots and impacts reach a client, each matching a server event; the client keeps a ringed basin dry through the first rise, floods it with no ring, catches up after a long frame; the water mask follows pours. The held item is still not drawn; that needs the models (A4, #44). Closes #78 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
extends TestCase
|
||||
|
||||
## Issue N11: a network client follows the flood from the tide and the pieces it has,
|
||||
## and the sea isn't drawn over ground the flood hasn't reached.
|
||||
|
||||
const SIDE: int = 513
|
||||
const SPACING: float = 2.0
|
||||
## A 200 m square of land 1 m high in open sea, as in test_tide.
|
||||
const LAND_MIN: float = 400.0
|
||||
const LAND_MAX: float = 600.0
|
||||
## Breakwaters on the edges of cells 120 to 122, a 12 m square.
|
||||
const RING_MIN: int = 120
|
||||
const RING_MAX: int = 122
|
||||
const INSIDE: Vector3 = Vector3(486.0, 1.0, 486.0)
|
||||
const OUTSIDE: Vector3 = Vector3(450.0, 1.0, 450.0)
|
||||
|
||||
|
||||
func _world() -> Simulation:
|
||||
var values: PackedFloat32Array = PackedFloat32Array()
|
||||
values.resize(SIDE * SIDE)
|
||||
for gz: int in SIDE:
|
||||
for gx: int in SIDE:
|
||||
var x: float = gx * SPACING
|
||||
var z: float = gz * SPACING
|
||||
var land: bool = x >= LAND_MIN and x <= LAND_MAX and z >= LAND_MIN and z <= LAND_MAX
|
||||
values[gz * SIDE + gx] = 1.0 if land else -Tuning.ISLAND_SEA_DEPTH
|
||||
var ground: SimGround = SimGround.from_heights(values, SIDE, SPACING)
|
||||
var world: Simulation = Simulation.new(3, ground)
|
||||
world.flood = Flood.create(ground)
|
||||
# A tide whose first rise takes the sea to 3 m.
|
||||
var levels: PackedFloat32Array = PackedFloat32Array()
|
||||
for index: int in Tide.phase_count():
|
||||
levels.append(3.0 + index)
|
||||
world.tide = Tide.new(0, levels)
|
||||
return world
|
||||
|
||||
|
||||
func _ring(world: Simulation) -> void:
|
||||
var stone: int = Materials.code_of("stone")
|
||||
for along: int in range(RING_MIN, RING_MAX + 1):
|
||||
for slot: Vector4i in [
|
||||
Vector4i(RING_MIN, 0, along, StructureSet.SLOT_WALL_X),
|
||||
Vector4i(RING_MAX + 1, 0, along, StructureSet.SLOT_WALL_X),
|
||||
Vector4i(along, 0, RING_MIN, StructureSet.SLOT_WALL_Z),
|
||||
Vector4i(along, 0, RING_MAX + 1, StructureSet.SLOT_WALL_Z),
|
||||
]:
|
||||
world.structures.add(StructureSet.BREAKWATER, stone, slot, 0, 0, 0, world.ground)
|
||||
|
||||
|
||||
## Moves the client's world to `tick` the way ClientMirror.sync() does.
|
||||
func _show_at(mirror: ClientMirror, world: Simulation, tick: int) -> void:
|
||||
world.tick = tick
|
||||
world.sea_level = world.tide.level_at(tick)
|
||||
mirror.follow_flood(world)
|
||||
|
||||
|
||||
func test_the_client_keeps_a_ringed_basin_dry_as_the_tide_rises() -> void:
|
||||
var world: Simulation = _world()
|
||||
_ring(world)
|
||||
var mirror: ClientMirror = ClientMirror.new()
|
||||
_show_at(mirror, world, 0)
|
||||
assert_false(world.flood.is_flooded(OUTSIDE.x, OUTSIDE.z), "dry land at the start")
|
||||
var risen: int = world.tide.sudden_death_offset()
|
||||
# Frame by frame through the first rise, a few ticks a frame.
|
||||
var first_rise_end: int = roundi((float(Tuning.TIDE_PHASES[0]["hold"]) + float(Tuning.TIDE_PHASES[0]["rise"])) * Tuning.TICK_RATE_HZ)
|
||||
for tick: int in range(0, first_rise_end + 120, 3):
|
||||
_show_at(mirror, world, tick)
|
||||
assert_true(world.sea_level >= 3.0)
|
||||
assert_true(world.flood.is_flooded(OUTSIDE.x, OUTSIDE.z), "the land outside the ring floods")
|
||||
assert_eq(world.water_level_at(OUTSIDE), world.sea_level, "and fills to the sea")
|
||||
assert_false(world.flood.is_flooded(INSIDE.x, INSIDE.z), "inside the ring stays dry")
|
||||
assert_true(risen > first_rise_end)
|
||||
|
||||
var view: WaterView = WaterView.new()
|
||||
view.follow(world)
|
||||
assert_true(view.shows_water_at(OUTSIDE.x, OUTSIDE.z), "the sea is drawn outside")
|
||||
assert_false(view.shows_water_at(INSIDE.x, INSIDE.z), "but not over the basin")
|
||||
assert_true(view.shows_water_at(-50.0, 300.0), "and everywhere off the grid")
|
||||
view.free()
|
||||
|
||||
|
||||
func test_a_late_frame_catches_up_and_a_missing_ring_floods_the_basin() -> void:
|
||||
var world: Simulation = _world()
|
||||
var mirror: ClientMirror = ClientMirror.new()
|
||||
_show_at(mirror, world, 0)
|
||||
# One frame long after the rise: the client catches up all at once.
|
||||
_show_at(mirror, world, roundi(240.0 * Tuning.TICK_RATE_HZ))
|
||||
assert_true(world.flood.is_flooded(INSIDE.x, INSIDE.z), "with no ring the basin floods")
|
||||
assert_eq(world.water_level_at(INSIDE), world.sea_level, "and has filled to the sea")
|
||||
|
||||
|
||||
func test_the_mask_changes_only_when_the_flood_pours() -> void:
|
||||
var world: Simulation = _world()
|
||||
var view: WaterView = WaterView.new()
|
||||
view.follow(world)
|
||||
var material: ShaderMaterial = view.surface().mesh.surface_get_material(0)
|
||||
assert_true(bool(material.get_shader_parameter("use_flood_mask")))
|
||||
var mask: Texture2D = material.get_shader_parameter("flood_mask")
|
||||
assert_eq(mask.get_width(), world.flood.side)
|
||||
var pours: int = world.flood.pours
|
||||
world.set_sea_level(3.0)
|
||||
assert_true(world.flood.pours > pours, "the sea rising over the land pours")
|
||||
view.follow(world)
|
||||
assert_true(view.shows_water_at(INSIDE.x, INSIDE.z))
|
||||
view.set_flood(null)
|
||||
assert_false(bool(material.get_shader_parameter("use_flood_mask")), "no flood: the sea everywhere")
|
||||
view.free()
|
||||
@@ -0,0 +1 @@
|
||||
uid://blh4oh3o15t4i
|
||||
Reference in New Issue
Block a user