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