The soak's drops under loss came from stalls: the server's island (#79) and each client process making islands on its main thread fed ENet second-long round-trip samples, its retransmission timer grew, and two losses of one reliable message in the busy drop that followed reached the 15 s timeout. - ClientGame.build_in_background makes a new match's island on a WorkerThreadPool task and holds the packets that arrive meanwhile, then takes them in order. The networked client and the soak's clients use it; the soak's own one-island-a-frame holding is gone. - NetServer.close(grace_msec) sends the shutdown notice reliably and services the socket while clients acknowledge it. The headless server waits up to 2 s. A notice sent once was lost under 2% loss, and that client timed out instead of hearing the server stop. - Tests: background island holding and ordering, freeing mid-build, a graceful shutdown reaching four clients behind 50% loss (it fails with the old one-shot notice), and the scripted UDP match and client capture wait for the client's island the way a real 20 s lobby would. The soak at 2% loss and +/-20 ms now keeps all 24 clients for both matches, with 0 of 3,758 world hashes differing and every client told of the stop. It still fails on client memory growth between matches in two of three processes (17 and 20 MB), which is not yet explained, so #39 stays open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
111 lines
4.0 KiB
GDScript
111 lines
4.0 KiB
GDScript
## Capture scenario for the network client (issue N10): a headless server listening
|
|
## on loopback UDP in this process, and the real ClientSession connected to it, played
|
|
## 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.
|
|
extends Node3D
|
|
|
|
const DT: float = 1.0 / Tuning.TICK_RATE_HZ
|
|
const HOST: String = "127.0.0.1"
|
|
const LIMIT_ROUNDS: int = 200 * Tuning.TICK_RATE_HZ
|
|
|
|
@export var stage: String = "barge"
|
|
@export var match_seed: int = 2
|
|
@export var bots: int = 23
|
|
|
|
var _loop: ServerLoop
|
|
var _net: NetServer
|
|
var _game: NetGame
|
|
var _session: ClientSession
|
|
|
|
|
|
func _ready() -> void:
|
|
var rules: MatchRules = MatchRules.new()
|
|
rules.max_players = bots + 1
|
|
rules.lobby_ticks = 6
|
|
rules.countdown_ticks = 6
|
|
_loop = ServerLoop.new(match_seed, 0, bots, rules)
|
|
_net = NetServer.new()
|
|
if _net.listen(0, HOST) != OK:
|
|
push_error("client capture: the server couldn't listen on loopback")
|
|
return
|
|
_game = NetGame.new(_loop, _net)
|
|
_session = ClientSession.new()
|
|
_session.input.autoplay = true
|
|
if _session.connect_to(HOST, _net.port(), "Mara") != OK:
|
|
push_error("client capture: the client couldn't open a connection")
|
|
return
|
|
add_child(_session)
|
|
# The picture is of one moment, so the session isn't left running behind it.
|
|
_session.set_process(false)
|
|
var me: SimEntity = _session.game.prediction.player
|
|
var since: int = -1
|
|
for _round: int in LIMIT_ROUNDS:
|
|
_game.poll()
|
|
if _session.game.building_world():
|
|
# The client makes its island in the background. A real lobby is far
|
|
# longer than that takes; this one is 6 ticks, so the server waits.
|
|
_session.pump(DT)
|
|
OS.delay_msec(5)
|
|
continue
|
|
_loop.run_tick()
|
|
_game.after_tick()
|
|
_session.pump(DT)
|
|
var reached: bool = false
|
|
if _session.game.playing():
|
|
match stage:
|
|
"barge":
|
|
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":
|
|
reached = me.drop_state == Drop.NONE
|
|
if reached and since < 0:
|
|
since = 0
|
|
elif since >= 0:
|
|
since += 1
|
|
if since >= (2 * Tuning.TICK_RATE_HZ if stage != "barge" else 1):
|
|
break
|
|
if since < 0:
|
|
push_error("client capture: never reached stage '%s'" % stage)
|
|
return
|
|
_session.view.settle()
|
|
var others: int = 0
|
|
var camera: Camera3D = _session.view.camera
|
|
for entity: SimEntity in _session.game.world.entities.entities():
|
|
if entity.archetype != SimEntity.ARCHETYPE_PLAYER or entity.id == _session.mirror.own_id or entity.eliminated:
|
|
continue
|
|
var figure: Node3D = _session.view.entities.figure_of(entity.id)
|
|
var to: Vector3 = (figure.position if figure != null else entity.position) + Vector3(0.0, 1.0, 0.0) - camera.position
|
|
if to.length() < 150.0 and to.normalized().dot(-camera.basis.z) > 0.8:
|
|
others += 1
|
|
var flow: Match = _loop.match_flow
|
|
_caption("NETWORK CLIENT · %s · %s · seed %d\njoined %s over UDP as \"%s\" · %d players drawn, %d others ahead of the camera\nsimulation tick %d on the server, %d predicted here · %d snapshots, %d world messages, %d corrections" % [
|
|
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,
|
|
])
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
if _session != null:
|
|
_session.leave()
|
|
if _net != null:
|
|
_net.close()
|
|
|
|
|
|
func _caption(text: String) -> void:
|
|
var settings: LabelSettings = LabelSettings.new()
|
|
settings.font_size = 20
|
|
settings.font_color = Color(0.96, 0.94, 0.88)
|
|
settings.outline_size = 6
|
|
settings.outline_color = Color(0.08, 0.09, 0.1)
|
|
var label: Label = Label.new()
|
|
label.label_settings = settings
|
|
label.text = text
|
|
label.position = Vector2(18.0, 14.0)
|
|
var layer: CanvasLayer = CanvasLayer.new()
|
|
layer.add_child(label)
|
|
add_child(layer)
|