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:
2026-11-13 02:24:16 -05:00
co-authored by Claude Opus 5.5
parent 2973abf144
commit 57faefb81a
22 changed files with 810 additions and 9 deletions
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/client_scene.gd" id="1"]
[node name="CaptureClient" type="Node3D"]
script = ExtResource("1")
stage = "basin"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/client_scene.gd" id="1"]
[node name="CaptureClient" type="Node3D"]
script = ExtResource("1")
stage = "build"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/client_scene.gd" id="1"]
[node name="CaptureClient" type="Node3D"]
script = ExtResource("1")
stage = "build_refused"
+137 -3
View File
@@ -3,7 +3,12 @@
## by its autoplay script. The picture is the client's own: its copy of the world, its
## predicted player, everyone else as the server's snapshots have them.
##
## Stages: barge (a few seconds into the drop), glide, landed.
## Stages: barge (a few seconds into the drop), glide, landed, and basin: once landed,
## the server rings a patch of low ground near the shore with breakwaters and play goes
## on until the tide has risen past it, so the sea stands outside the ring and the
## ground inside, below the sea, stays dry on the client too (issue N11). build and
## build_refused: once landed, the client goes into build mode for a driftwood wall,
## with plenty of materials or none, so the ghost shows in its allowed or refused tint.
extends Node3D
const DT: float = 1.0 / Tuning.TICK_RATE_HZ
@@ -59,7 +64,7 @@ func _ready() -> void:
reached = me.drop_state == Drop.ABOARD and _session.game.prediction.next_tick > 3 * Tuning.TICK_RATE_HZ
"glide":
reached = me.drop_state == Drop.GLIDING
"landed":
"landed", "basin", "build", "build_refused":
reached = me.drop_state == Drop.NONE
if reached and since < 0:
since = 0
@@ -70,6 +75,15 @@ func _ready() -> void:
if since < 0:
push_error("client capture: never reached stage '%s'" % stage)
return
var basin_text: String = ""
if stage == "basin":
basin_text = _basin()
if basin_text.is_empty():
return
elif stage.begins_with("build"):
basin_text = _build_mode(stage == "build")
if basin_text.is_empty():
return
_session.view.settle()
var others: int = 0
var camera: Camera3D = _session.view.camera
@@ -85,7 +99,127 @@ func _ready() -> void:
stage.to_upper(), flow.phase_name(), match_seed, HOST, _net.name_of(_session.link.handle),
_session.view.entities.figure_count(), others, _loop.sim.tick, _session.game.prediction.next_tick,
_session.game.receiver.applied, _session.game.replica.applied, _session.game.prediction.mispredictions,
])
] + basin_text)
## Stops the autoplay where the player stands and goes into build mode for a driftwood
## wall, after the server has given the player plenty of materials or taken them all.
## Returns a caption line, or "" after reporting an error.
func _build_mode(afford: bool) -> String:
var flow: Match = _loop.match_flow
var mine: SimEntity = _loop.sim.entities.find(int(flow.entity_of.get(_session.link.handle, 0)))
if mine == null or mine.eliminated:
push_error("client capture: the player isn't in the match to build")
return ""
mine.materials = PackedInt32Array([200, 200, 200] if afford else [0, 0, 0])
var me: SimEntity = _session.game.prediction.player
_session.input.autoplay = false
_session.input.build_mode = true
_session.input.build_kind = StructureSet.WALL
_session.input.material = Materials.DRIFTWOOD
_session.input.yaw = float(me.yaw) / PlayerCommand.YAW_STEPS * TAU
_session.input.pitch = -0.3
for _round: int in 45:
_game.poll()
_loop.run_tick()
_game.after_tick()
_session.pump(DT)
var ghost: BuildGhost = _session.ghost
if ghost == null or not ghost.visible:
push_error("client capture: no build ghost is showing")
return ""
if ghost.valid != afford:
push_error("client capture: the ghost says %s, expected %s" % [Building.Result.keys()[ghost.result], "OK" if afford else "refused"])
return ""
return "\nBUILD MODE · driftwood wall · ghost %s (%s) · driftwood carried %d" % [
"allowed" if ghost.valid else "refused", Building.Result.keys()[ghost.result], _session.game.prediction.player.materials[Materials.DRIFTWOOD],
]
## Rings low ground with breakwaters on the server, plays on until the tide stands over
## it, and frames the ring. Returns a caption line, or "" after reporting an error.
func _basin() -> String:
var sim: Simulation = _loop.sim
var flood: Flood = sim.flood
var level: float = sim.tide.levels[0]
var ring: Vector2i = _find_basin(flood, level, _session.game.prediction.player.position)
if ring.x < 0:
push_error("client capture: no low ground to ring below the first tide level %.1f m" % level)
return ""
# Two breakwaters a side on every edge of the 3 x 3 cells, based at the edge's floor.
var stone: int = Materials.code_of("stone")
var piece_levels: int = roundi(Tuning.GRID_CELL_METRES / Tuning.BUILD_LEVEL_METRES)
for along: int in range(3):
for wall: Vector4i in [
Vector4i(ring.x, 0, ring.y + along, StructureSet.SLOT_WALL_X),
Vector4i(ring.x + 3, 0, ring.y + along, StructureSet.SLOT_WALL_X),
Vector4i(ring.x + along, 0, ring.y, StructureSet.SLOT_WALL_Z),
Vector4i(ring.x + along, 0, ring.y + 3, StructureSet.SLOT_WALL_Z),
]:
var a: int = wall.z * flood.side + wall.x
var b: int = a - 1 if wall.w == StructureSet.SLOT_WALL_X else a - flood.side
var base: int = floori(maxf(flood.floors[a], flood.floors[b]) / Tuning.BUILD_LEVEL_METRES)
for stack: int in 2:
sim.structures.add(StructureSet.BREAKWATER, stone, Vector4i(wall.x, base + stack * piece_levels, wall.z, wall.w), 0, 0, sim.tick, sim.ground)
var inside: Vector3 = Vector3((ring.x + 1.5) * flood.cell, 0.0, (ring.y + 1.5) * flood.cell)
var outside: Vector3 = Vector3((ring.x - 1.5) * flood.cell, 0.0, (ring.y + 1.5) * flood.cell)
var floor_inside: float = flood.floors[flood.cell_of(inside.x, inside.z)]
var client_flood: Flood = null
for _round: int in 400 * Tuning.TICK_RATE_HZ:
_game.poll()
_loop.run_tick()
_game.after_tick()
_session.pump(DT)
client_flood = _session.game.world.flood
if sim.sea_level > floor_inside + 1.0 and _session.game.world.sea_level > floor_inside + 1.0 and client_flood.is_flooded(outside.x, outside.z):
break
if not (sim.sea_level > floor_inside + 1.0):
push_error("client capture: the tide never rose over the ringed ground")
return ""
_session.pump(DT)
var ground: float = sim.ground.terrain_height(inside.x, inside.z)
_session.view.look_from(inside + Vector3(-19.0, ground + 15.0, -17.0), Vector3(inside.x, ground, inside.z))
return "\nBASIN · ring at (%.0f, %.0f), floor inside %.1f m, sea %.1f m\ninside dry: server %s, client %s, drawn %s · outside flooded on the client: %s" % [
inside.x, inside.z, floor_inside, _session.game.world.sea_level,
not flood.is_flooded(inside.x, inside.z), not client_flood.is_flooded(inside.x, inside.z),
not _session.view.water.shows_water_at(inside.x, inside.z), client_flood.is_flooded(outside.x, outside.z),
]
## The corner cell of a 3 x 3 patch of dry ground whose floor lies between 0.6 m and
## 1.5 m under `level` everywhere in it and in the ring of cells around it, closest to
## `near`, or (-1, -1).
func _find_basin(flood: Flood, level: float, near: Vector3) -> Vector2i:
var best: Vector2i = Vector2i(-1, -1)
var best_distance: float = INF
for cz: int in range(2, flood.side - 6):
for cx: int in range(2, flood.side - 6):
var fits: bool = true
for dz: int in range(-1, 4):
for dx: int in range(-1, 4):
var index: int = (cz + dz) * flood.side + cx + dx
var cell_floor: float = flood.floors[index]
if flood.flooded[index] != 0 or cell_floor < 0.6 or cell_floor > level - 1.5:
fits = false
break
if not fits:
break
if not fits:
continue
# Open sea must reach the patch's surroundings: a flooded cell near it.
var shore: bool = false
for dz: int in range(-3, 6):
for dx: int in range(-3, 6):
var index: int = (cz + dz) * flood.side + cx + dx
if index >= 0 and index < flood.flooded.size() and flood.flooded[index] != 0:
shore = true
if not shore:
continue
var distance: float = Vector2((cx + 1.5) * flood.cell - near.x, (cz + 1.5) * flood.cell - near.z).length()
if distance < best_distance:
best_distance = distance
best = Vector2i(cx, cz)
return best
func _exit_tree() -> void:
+107
View File
@@ -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()
+1
View File
@@ -0,0 +1 @@
uid://blh4oh3o15t4i
+7 -1
View File
@@ -51,6 +51,11 @@ func collect_seeds() -> void:
seeds.append(bytes)
if tick % 10 == 0:
seeds.append(game.snapshot_for(1))
seeds.append(NetFx.encode([
{"kind": NetFx.SHOT, "tick": 90, "player": 3, "item": 2, "position": Vector3(100.0, 12.0, 200.0), "yaw": 1.0, "pitch": -0.2},
{"kind": NetFx.IMPACT, "tick": 91, "player": 3, "item": 2, "position": Vector3(110.0, 11.0, 210.0), "hit": Weapons.HIT_PLAYER, "target": 7},
{"kind": NetFx.HARVEST, "tick": 92, "player": 4, "item": -1, "position": Vector3(50.0, 9.0, 60.0), "prop": 12, "piece": 0},
] as Array[Dictionary]))
var command: PlayerCommand = PlayerCommand.from_input(12, Vector2(0.3, 1.0), 1.0, 0.2, PlayerCommand.BUTTON_FIRE, 2, 1)
seeds.append(NetSnapshot.encode_input(40, [command, command] as Array[PlayerCommand]))
seeds.append(NetProtocol.encode_hello("Fuzzer"))
@@ -100,7 +105,7 @@ func feed(bytes: PackedByteArray) -> void:
var results: Array = [
NetProtocol.decode_hello(bytes), NetProtocol.decode_welcome(bytes), NetProtocol.decode_reject(bytes),
NetSnapshot.decode_input(bytes), NetSnapshot.decode_snapshot(bytes), NetSnapshot.decode_match(bytes),
NetWorld.decode_world(bytes), NetWorld.decode_own(bytes),
NetWorld.decode_world(bytes), NetWorld.decode_own(bytes), NetFx.decode(bytes),
NetDiscovery.decode_query(bytes), NetDiscovery.decode_info(bytes), NetDiscovery.decode_register(bytes),
NetDiscovery.decode_challenge(bytes), NetDiscovery.decode_list(bytes),
]
@@ -152,5 +157,6 @@ func _mutate(bytes: PackedByteArray) -> void:
var types: Array[int] = [
NetProtocol.MSG_HELLO, NetProtocol.MSG_WELCOME, NetProtocol.MSG_REJECT, NetSnapshot.MSG_MATCH,
NetWorld.MSG_WORLD, NetWorld.MSG_OWN, NetSnapshot.MSG_SNAPSHOT, NetSnapshot.MSG_INPUT,
NetFx.MSG_FX,
]
bytes[0] = types[rng.randi_range(0, types.size() - 1)]
+66
View File
@@ -0,0 +1,66 @@
extends TestCase
## Issue N11: shots, impacts and swings on the wire (NetFx).
func _records() -> Array[Dictionary]:
return [
{"kind": NetFx.SHOT, "tick": 400, "player": 3, "item": 2, "position": Vector3(100.25, 12.5, 200.0), "yaw": 1.2345, "pitch": -0.25},
{"kind": NetFx.IMPACT, "tick": 401, "player": 3, "item": 2, "position": Vector3(130.0, 11.0, 220.0), "hit": Weapons.HIT_PLAYER, "target": 700},
{"kind": NetFx.HARVEST, "tick": 402, "player": 4, "item": -1, "position": Vector3(50.0, 9.0, 60.0), "prop": 12, "piece": 0},
{"kind": NetFx.HARVEST, "tick": 402, "player": 5, "item": -1, "position": Vector3(51.0, 9.0, 61.0), "prop": -1, "piece": 33},
]
func test_records_survive_the_trip() -> void:
var bytes: PackedByteArray = NetFx.encode(_records())
var message: Dictionary = NetFx.decode(bytes)
assert_false(message.is_empty())
assert_eq(message["tick"], 402)
var events: Array = message["events"]
assert_eq(events.size(), 4)
for index: int in 4:
var sent: Dictionary = _records()[index]
var got: Dictionary = events[index]
for key: String in sent:
if key == "position":
assert_true((got[key] as Vector3).distance_to(sent[key]) <= 0.06, "%s within 6 cm" % key)
elif key == "yaw" or key == "pitch":
assert_near(float(got[key]), float(sent[key]), 0.0001)
else:
assert_eq(got[key], sent[key], "event %d %s" % [index, key])
assert_true(NetFx.aim(events[0]).is_normalized())
func test_an_event_from_the_simulation_becomes_a_record() -> void:
var direction: Vector3 = Vector3(0.3, -0.2, 0.9).normalized()
var shot: Dictionary = NetFx.from_event({"type": "shot", "player": 9, "item": 4, "from": Vector3(1.0, 2.0, 3.0), "direction": direction}, 77)
assert_eq(shot["kind"], NetFx.SHOT)
assert_true(NetFx.aim(shot).distance_to(direction) < 0.0001, "the aim comes back")
var swing: Dictionary = NetFx.from_event({"type": "harvest", "player": 9, "prop": 5, "material": 0, "amount": 3}, 77, {9: Vector3(4.0, 5.0, 6.0)})
assert_eq(swing["position"], Vector3(4.0, 5.0, 6.0))
assert_true(NetFx.from_event({"type": "pickup", "player": 9}, 77).is_empty(), "only FX events")
func test_too_many_keep_the_newest_and_the_byte_limit() -> void:
var many: Array[Dictionary] = []
for index: int in 300:
many.append({"kind": NetFx.SHOT, "tick": 1000 + index / 10, "player": index, "item": 1, "position": Vector3(index, 1.0, 2.0), "yaw": 0.0, "pitch": 0.0})
var bytes: PackedByteArray = NetFx.encode(many)
assert_true(bytes.size() <= Tuning.NET_SNAPSHOT_MAX_BYTES, "%d bytes" % bytes.size())
var events: Array = NetFx.decode(bytes)["events"]
assert_true(events.size() > 40)
assert_eq(int(events[events.size() - 1]["player"]), 299, "the newest is kept")
assert_eq(NetFx.encode([] as Array[Dictionary]).size(), 0)
func test_malformed_messages_are_refused() -> void:
var bytes: PackedByteArray = NetFx.encode(_records())
for cut: int in bytes.size():
assert_true(NetFx.decode(bytes.slice(0, cut)).is_empty(), "cut at %d" % cut)
var longer: PackedByteArray = bytes.duplicate()
longer.append(0)
assert_true(NetFx.decode(longer).is_empty(), "trailing bytes")
var bad_kind: PackedByteArray = bytes.duplicate()
bad_kind[NetFx.HEADER_BYTES] = 9
assert_true(NetFx.decode(bad_kind).is_empty(), "unknown kind")
+1
View File
@@ -0,0 +1 @@
uid://dyrisqacc7jfk
+86
View File
@@ -205,3 +205,89 @@ func test_a_client_freed_while_its_island_is_made_waits_for_it() -> void:
assert_true(client.building_world())
client = null
assert_true(true, "freeing it with a task running raises no error")
## N11: shots, impacts and swings near what the client watches reach it as FX
## records, each one an event the server's simulation really had. The client's own
## player, once landed, is given a hitscan weapon and fires at the ground.
func test_shots_and_hits_reach_the_client() -> void:
var client: ClientGame = ClientGame.new()
assert_true(loop.match_flow.join(7))
game.adopt(7)
client.receive(NetProtocol.CHANNEL_CONTROL, game.match_notice())
client.receive(NetProtocol.CHANNEL_CONTROL, game.world_notice())
var weapon: ItemDef = null
for def: ItemDef in ItemCatalog.all():
if def.kind == ItemDef.WEAPON and def.projectile_speed <= 0.0 and def.ammo_code >= 0 and def.damage > 0:
weapon = def
break
assert_not_null(weapon, "a hitscan weapon to fire")
var happened: Dictionary = {}
var shots: int = 0
var impacts: int = 0
var armed: bool = false
for round_index: int in 4000:
var flow: Match = loop.match_flow
var mine: SimEntity = loop.sim.entities.find(int(flow.entity_of.get(7, 0))) if flow.in_match() else null
if mine != null and mine.drop_state == Drop.NONE and not mine.eliminated:
if not armed:
armed = true
# Wherever it came down, stand it on dry ground well above the sea.
mine.position = _dry_spot(loop.sim)
mine.velocity = Vector3.ZERO
mine.swimming = false
mine.on_ground = true
Inventory.give(mine, weapon.code, 1)
Inventory.give(mine, weapon.ammo_code, 60)
# Press and release, so any weapon fires again.
var buttons: int = PlayerCommand.BUTTON_FIRE if round_index % 8 == 0 else 0
loop.submit(7, PlayerCommand.from_input(loop.sim.tick, Vector2.ZERO, 0.0, -0.7, buttons, 1))
loop.run_tick()
game.after_tick()
if loop.match_flow.in_match():
for event: Dictionary in loop.sim.events:
var record: Dictionary = NetFx.from_event(event, loop.sim.tick)
if not record.is_empty():
# A scattering weapon lands several pellets on one tick.
var key: String = "%d %d %d" % [record["tick"], record["kind"], record["player"]]
if not happened.has(key):
happened[key] = []
(happened[key] as Array).append(record["position"])
for event: Dictionary in loop.match_flow.events:
if event["type"] == "phase":
client.receive(NetProtocol.CHANNEL_CONTROL, game.match_notice())
if not game.world_changes.is_empty():
client.receive(NetProtocol.CHANNEL_CONTROL, game.world_changes)
if game.snapshot_due():
client.receive(NetProtocol.CHANNEL_STATE, game.snapshot_for(7))
var fx: PackedByteArray = game.fx_for(7)
if not fx.is_empty():
client.receive(NetProtocol.CHANNEL_STATE, fx)
for record: Dictionary in client.fx:
var key: String = "%d %d %d" % [record["tick"], record["kind"], record["player"]]
assert_true(happened.has(key), "FX %s happened on the server" % key)
if happened.has(key) and record["kind"] != NetFx.HARVEST:
var near: bool = false
for position: Vector3 in happened[key]:
near = near or (record["position"] as Vector3).distance_to(position) < 0.1
assert_true(near, "FX %s at the same place" % key)
shots += 1 if record["kind"] == NetFx.SHOT else 0
impacts += 1 if record["kind"] == NetFx.IMPACT else 0
client.fx.clear()
if shots >= 3 and impacts >= 3:
break
assert_true(armed, "the player landed and was armed")
assert_true(shots >= 3, "shots arrived: %d" % shots)
assert_true(impacts >= 3, "and where they landed: %d" % impacts)
assert_eq(client.bad_packets, 0)
assert_true(game.fx_for(7).is_empty(), "nothing is sent twice")
func _dry_spot(sim: Simulation) -> Vector3:
for z: int in range(64, 960, 16):
for x: int in range(64, 960, 16):
var y: float = sim.ground.terrain_height(x, z)
var feet: Vector3 = Vector3(x, y, z)
if y > 15.0 and not sim.ground.body_blocked(feet, 2.0, Tuning.PLAYER_HEIGHT, 0.0):
return feet
return Vector3(512.0, sim.ground.terrain_height(512.0, 512.0), 512.0)