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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user