Co-op voice/session work, config retune, net budget tool, overhaul plan

Snapshot of in-progress work before the alien overhaul so worker
worktrees branch from current code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-05 13:35:53 -04:00
parent 2e6638b744
commit 39f9d15cfe
15 changed files with 1394 additions and 339 deletions

View file

@ -8,22 +8,29 @@ extends Node
##
## Host -> partner
## welcome (reliable, once) the farm state, the phase, tonight's time, the loot, the names
## refused (reliable) the partner's game speaks another PROTOCOL
## batch (reliable, each tick with news) events in order: phase changes (with the state),
## the end of the campaign, sounds, toasts for the partner, loot and arrival news,
## breaches, fear bursts, gather popups, the workbench; enemies removed
## state (reliable, at most STATE_HZ, when it changed) the farm state
## state (reliable, at most STATE_HZ, when it changed) the farm state (the phase clock
## alone isn't a change: it is in every snapshot)
## loot (reliable, at most LOOT_HZ, when it changed) every item
## snap (unreliable, SNAP_HZ) the phase clock, both scarecrows, the animals
## foes (unreliable, SNAP_HZ, in chunks) every enemy, 16 bytes each
## shots (unreliable, SNAP_HZ) the shots in flight
## snap (unreliable, SNAP_HZ) packed bytes: the phase clock, both scarecrows, the
## animals, the shots in flight, and the enemies that are due (as many as fit)
## foes (unreliable, with a snapshot) the due enemies that didn't fit, 16 bytes each
## Partner -> host
## hello (reliable) its player's name
## input (unreliable, INPUT_HZ) its scarecrow's position and facing, held buttons and press
## counts, aim, build mode, the upgrade menu (RemoteControls)
## hello (reliable) its player's name and PROTOCOL
## input (unreliable, up to INPUT_HZ when it changed, else every INPUT_KEEPALIVE) its
## scarecrow's position and facing, held buttons and press counts, aim, build mode,
## the upgrade menu (RemoteControls, packed bytes)
## req (reliable) start the day, start the night early, retry the night, build,
## dismantle, buy an upgrade
## Unreliable messages stay under CoopLink.UNRELIABLE_LIMIT; nothing depends on any single one
## arriving (enemies missed by a snapshot appear in the next; removals are reliable).
## arriving. Enemies go by dead reckoning: the partner moves each one on at the velocity of its
## last record, and the host sends a new record only when that guess drifts (FOE_DRIFT, or the
## velocity, heading, altitude, state, or a hit), at least every FOE_REFRESH seconds, and a
## record sent for a change (or a new enemy) goes out again in the next snapshots in case one is
## lost. Removals are reliable. Large messages go out compressed (CoopLink).
## Voice chat (GD-Sync only, start_voice): a CoopVoice per player, owned by that player's client.
enum Role { SOLO, HOST, CLIENT }
@ -35,12 +42,29 @@ signal ended(reason: String)
## Partner: the first full state arrived; the game is on.
signal welcomed
const SNAP_EVERY := 3 # physics ticks: 20 Hz
const INPUT_EVERY := 2 # 30 Hz
## The wire format: both machines must speak the same one (hello and welcome carry it).
const PROTOCOL := 2
const SNAP_EVERY := 4 # physics ticks: 15 Hz
const INPUT_EVERY := 3 # 20 Hz, when it changed
## Seconds: the partner's input goes out at least this often, changed or not.
const INPUT_KEEPALIVE := 0.25
const STATE_EVERY := 15 # 4 Hz
const LOOT_EVERY := 6 # 10 Hz
const ENEMY_CHUNK := 56
const MAX_SHOTS := 60
## Bytes of packed data in one snapshot or foes message (the wrapping keeps it under
## CoopLink.UNRELIABLE_LIMIT).
const PACK_LIMIT := 1000
const FOE_RECORD := 16
## An enemy record's velocity, in 1/VEL_SCALE m/s (s8: up to 12.7 m/s).
const VEL_SCALE := 10.0
## Dead reckoning: a new record goes out when the partner's guess is this far off (m), its
## velocity this far (m/s), its heading turned past FOE_TURN (cosine: 20 degrees), its altitude
## FOE_ALT_DRIFT off (m), or FOE_REFRESH seconds after the last one.
const FOE_DRIFT := 0.25
const FOE_VEL_DRIFT := 0.75
const FOE_TURN := 0.94
const FOE_ALT_DRIFT := 0.25
const FOE_REFRESH := 1.0
## Partner: seconds without a word from the host before it counts as gone.
const TIMEOUT := 8.0
@ -56,8 +80,15 @@ var quiet: float = 0.0
var voices: Array[CoopVoice] = []
var microphone := true
## Seconds since the session started (physics time).
var clock: float = 0.0
# Host
var _events: Array = []
## Enemy records sent so far (each 16 bytes).
var foe_records: int = 0
## What the partner last got for each enemy: host handle -> [clock, record, times to send again].
var _foe_sent := {}
var _removed: Array = []
var _state_hash: int = 0
var _loot_hash: int = 0
@ -67,6 +98,8 @@ var _map := {} # host enemy handle -> local handle
var _gone := {} # host handles already removed (a late snapshot mustn't bring them back)
var _targets := {} # local handle -> PackedFloat32Array [x, z, hx, hz, vx, vz, alt]
var _sender := RemoteControls.Sender.new()
var _last_input := PackedByteArray()
var _input_age: float = 0.0
var _snap_tick: int = -1
var _structures_json := ""
var _shed_json := ""
@ -95,7 +128,9 @@ func start_host(p_sim: FarmSim, p_link: CoopLink, p_my_name: String, p_partner_n
my_name = p_my_name
partner_name = p_partner_name
ticks = 0
clock = 0.0
quiet = 0.0
_foe_sent.clear()
link.received.connect(_on_message)
sim.avatars[0].player_name = my_name
var a := sim.add_partner(false, partner_name)
@ -104,12 +139,15 @@ func start_host(p_sim: FarmSim, p_link: CoopLink, p_my_name: String, p_partner_n
_tag_all()
_hook(sim.campaign.phase_changed, func(phase: CampaignController.Phase, previous: CampaignController.Phase) -> void:
_events.append(["phase", int(phase), int(previous), sim.campaign.state.to_dict(), sim.campaign.state.phase_time_left])
if phase == CampaignController.Phase.MORNING and sim.partner != null:
_ensure_coop())
if phase == CampaignController.Phase.MORNING:
_foe_sent.clear() # the partner forgets the night's enemies too
if sim.partner != null:
_ensure_coop())
_hook(sim.campaign.campaign_ended, func(outcome: CampaignController.Outcome) -> void:
_events.append(["ended", int(outcome), sim.campaign.state.to_dict()]))
_hook(sim.enemies.enemy_removed, func(h: int, reason: EnemySystem.Removal, x: float, z: float, _c: int, _t: int) -> void:
_removed.append([h, int(reason), x, z]))
_removed.append([h, int(reason), x, z])
_foe_sent.erase(h))
_hook(sim.waves.arrived, func(h: int, at: Vector2) -> void:
var d := sim.enemies.resolve_handle(h)
_events.append(["arrived", sim.enemies.type[d] if d >= 0 else 0, at]))
@ -146,8 +184,11 @@ func start_client(p_sim: FarmSim, p_link: CoopLink, p_my_name: String) -> void:
role = Role.CLIENT
my_name = p_my_name
ticks = 0
clock = 0.0
quiet = 0.0
_is_welcomed = false
_snap_tick = -1
_last_input = PackedByteArray()
link.received.connect(_on_message)
var c := sim.campaign
c.save_path = "" # only the host saves
@ -236,13 +277,14 @@ func partner_speaking() -> bool:
## GD-Sync calls this on the other machine (GDSyncLink).
func net_receive(kind: String, data: Variant) -> void:
if link != null:
link.received.emit(kind, data)
link.receive(kind, data)
func _physics_process(dt: float) -> void:
if role == Role.SOLO or link == null:
return
ticks += 1
clock += dt
quiet += dt
if role == Role.HOST:
link.poll()
@ -256,9 +298,11 @@ func _physics_process(dt: float) -> void:
_hello_wait -= dt
if _hello_wait <= 0.0:
_hello_wait = 1.0
link.send("hello", {"name": my_name}, true)
elif ticks % INPUT_EVERY == 0:
_send_input()
link.send("hello", {"name": my_name, "v": PROTOCOL}, true)
else:
_input_age += dt
if ticks % INPUT_EVERY == 0:
_send_input()
if link.closed or (role == Role.CLIENT and quiet > TIMEOUT):
stop("The host left the game" if link.closed else "Lost the connection to the host")
@ -270,7 +314,10 @@ func _host_tick() -> void:
_send_snapshot()
if ticks % STATE_EVERY == 0:
var d := sim.campaign.state.to_dict()
var left: float = d["phase_time_left"]
d["phase_time_left"] = 0.0 # ticks down all day and night; every snapshot has it
var h := hash(d)
d["phase_time_left"] = left
if h != _state_hash:
_state_hash = h
link.send("state", d, true)
@ -289,32 +336,98 @@ func _host_tick() -> void:
func _welcome() -> Dictionary:
var c := sim.campaign
return {"state": c.state.to_dict(), "phase": int(c.state.phase), "time": c.state.phase_time_left, "outcome": int(c.outcome),
"night_time": sim.waves.night_time, "loot": sim.loot.replica_record(), "host": my_name}
"night_time": sim.waves.night_time, "loot": sim.loot.replica_record(), "host": my_name, "v": PROTOCOL}
## One snapshot: the clock, the scarecrows, the animals, the shots, and the enemies that are due,
## packed; the due enemies that don't fit follow in foes messages.
func _send_snapshot() -> void:
var avs: Array = []
var b := StreamPeerBuffer.new()
b.put_u32(ticks)
b.put_float(sim.campaign.state.phase_time_left)
b.put_float(sim.waves.night_time)
b.put_u8(sim.avatars.size())
for a in sim.avatars:
avs.append(_avatar_record(a))
link.send("snap", {"t": ticks, "time": sim.campaign.state.phase_time_left, "night": sim.waves.night_time, "av": avs,
"an": sim.animals.replica_record()}, false)
_put_avatar(b, a)
var an := sim.animals.replica_record() # x, z, yaw, speed per animal
b.put_u8(an.size() / 4)
for k in range(0, an.size(), 4):
CoopLink.put_cm(b, an[k])
CoopLink.put_cm(b, an[k + 1])
CoopLink.put_angle(b, an[k + 2])
b.put_u8(clampi(roundi(an[k + 3] * 20.0), 0, 255))
var shots := sim.projectiles.replica_record(MAX_SHOTS) # x, z, direction per shot
b.put_u8(shots.size() / 4)
for k in range(0, shots.size(), 4):
CoopLink.put_cm(b, shots[k])
CoopLink.put_cm(b, shots[k + 1])
b.put_8(clampi(roundi(shots[k + 2] * 127.0), -127, 127))
b.put_8(clampi(roundi(shots[k + 3] * 127.0), -127, 127))
var foes := _due_foes()
var n := foes.size() / FOE_RECORD
var fit := mini(n, (PACK_LIMIT - b.get_size() - 2) / FOE_RECORD)
b.put_u16(fit)
b.put_data(foes.slice(0, fit * FOE_RECORD))
link.send("snap", b.data_array, false)
var per := (PACK_LIMIT - 6) / FOE_RECORD
while fit < n:
var take := mini(n - fit, per)
var c := StreamPeerBuffer.new()
c.put_u32(ticks)
c.put_u16(take)
c.put_data(foes.slice(fit * FOE_RECORD, (fit + take) * FOE_RECORD))
link.send("foes", c.data_array, false)
fit += take
## The records of the enemies the partner needs news of (dead reckoning, see the top), noted as
## sent.
func _due_foes() -> PackedByteArray:
var es := sim.enemies
var chunk := PackedByteArray()
var out := PackedByteArray()
for d in es.active_count:
if es.alive[d] == 0:
continue
chunk.append_array(_enemy_bytes(es, d))
if chunk.size() >= ENEMY_CHUNK * 16:
link.send("foes", chunk, false)
chunk = PackedByteArray()
if not chunk.is_empty():
link.send("foes", chunk, false)
link.send("shots", sim.projectiles.replica_record(MAX_SHOTS), false)
var h := es.handle_of(d)
var last: Array = _foe_sent.get(h, [])
var again := 0
if last.is_empty():
again = 2 # a new enemy: in the next two snapshots too
elif int(last[2]) > 0:
again = int(last[2]) - 1
elif _foe_changed(es, d, last[1], clock - float(last[0])):
again = 1
elif clock - float(last[0]) < FOE_REFRESH:
continue
var rec := _enemy_bytes(es, d)
_foe_sent[h] = [clock, rec, again]
out.append_array(rec)
foe_records += 1
return out
## Whether enemy d is off from the partner's guess: its last record r, moved on for age seconds.
func _foe_changed(es: EnemySystem, d: int, r: PackedByteArray, age: float) -> bool:
if r[4] != es.type[d] or r[5] != es.state[d]:
return true
if es.hurt[d] > maxf(r[6] / 255.0 - age * EnemySystem.HURT_FADE, 0.0) + 0.15:
return true # hit again
if absf(es.alt[d] - r[7] / 40.0) > FOE_ALT_DRIFT:
return true
var vx := r.decode_s8(14) / VEL_SCALE
var vz := r.decode_s8(15) / VEL_SCALE
var off := Vector2(es.pos_x[d] - (r.decode_s16(8) / 100.0 + vx * age), es.pos_z[d] - (r.decode_s16(10) / 100.0 + vz * age))
if off.length_squared() > FOE_DRIFT * FOE_DRIFT:
return true
if Vector2(es.vel_x[d] - vx, es.vel_z[d] - vz).length_squared() > FOE_VEL_DRIFT * FOE_VEL_DRIFT:
return true
var head := Vector2(r.decode_s8(12), r.decode_s8(13))
return head.length_squared() > 0.0 and Vector2(es.head_x[d], es.head_z[d]).dot(head.normalized()) < FOE_TURN
static func _enemy_bytes(es: EnemySystem, d: int) -> PackedByteArray:
var b := PackedByteArray()
b.resize(16)
b.resize(FOE_RECORD)
b.encode_s32(0, es.handle_of(d))
b[4] = es.type[d]
b[5] = es.state[d]
@ -324,20 +437,31 @@ static func _enemy_bytes(es: EnemySystem, d: int) -> PackedByteArray:
b.encode_s16(10, clampi(roundi(es.pos_z[d] * 100.0), -32768, 32767))
b.encode_s8(12, clampi(roundi(es.head_x[d] * 127.0), -127, 127))
b.encode_s8(13, clampi(roundi(es.head_z[d] * 127.0), -127, 127))
b.encode_s8(14, clampi(roundi(es.vel_x[d] * 20.0), -127, 127))
b.encode_s8(15, clampi(roundi(es.vel_z[d] * 20.0), -127, 127))
b.encode_s8(14, clampi(roundi(es.vel_x[d] * VEL_SCALE), -127, 127))
b.encode_s8(15, clampi(roundi(es.vel_z[d] * VEL_SCALE), -127, 127))
return b
func _avatar_record(a: Avatar) -> Dictionary:
## A scarecrow in a snapshot: slot, position, facing, speed, alive and patching, health, its
## timers (invulnerable, fear, bomb recharge, patch, gather, repair), the weapon, the channel
## clip and what it is focused on and gathering (names), and the repair's target and progress.
func _put_avatar(b: StreamPeerBuffer, a: Avatar) -> void:
var it := a.interactions
var k := a.kit
return {"s": a.slot, "p": a.body.global_position, "y": a.body.model.rotation.y, "v": a.body.move_strength(),
"a": k.alive, "hp": k.hp(), "inv": k.invulnerable_left, "fl": k.fear_left,
"w": int(a.combat.weapon), "bl": a.combat.bomb_left,
"pt": k.patch_elapsed if k.patching else -1.0, "ch": String(a.body.channel_clip) if a.body.rooted else "",
"fo": String(it.focus.name) if it.focus != null else "", "ga": String(it.gathering.name) if it.gathering != null else "",
"ge": it.gather_elapsed, "rt": it.repair_target, "rp": it.repairing, "re": it.repair_elapsed}
b.put_u8(a.slot)
CoopLink.put_v3(b, a.body.global_position)
CoopLink.put_angle(b, a.body.model.rotation.y)
b.put_u8(clampi(roundi(a.body.move_strength() * 100.0), 0, 255))
b.put_u8((1 if k.alive else 0) | (2 if k.patching else 0))
b.put_u8(clampi(k.hp(), 0, 255))
for t: float in [k.invulnerable_left, k.fear_left, a.combat.bomb_left, k.patch_elapsed, it.gather_elapsed, it.repair_elapsed]:
CoopLink.put_time(b, t)
b.put_u8(int(a.combat.weapon))
CoopLink.put_text(b, String(a.body.channel_clip) if a.body.rooted else "")
CoopLink.put_text(b, String(it.focus.name) if it.focus != null else "")
CoopLink.put_text(b, String(it.gathering.name) if it.gathering != null else "")
b.put_32(it.repair_target)
b.put_32(it.repairing)
func _on_message(kind: String, data: Variant) -> void:
@ -354,20 +478,28 @@ func _host_message(kind: String, data: Variant) -> void:
return
match kind:
"hello":
partner_name = String((data as Dictionary).get("name", partner_name))
var hello := data as Dictionary
partner_name = String(hello.get("name", partner_name))
if int(hello.get("v", 1)) != PROTOCOL:
link.send("refused", {"v": PROTOCOL}, true)
var who := _display(partner_name, "Your friend")
stop()
if sim.toasts != null:
sim.toasts.push("%s has another version of the game: update both to play together" % who, Color(1.0, 0.6, 0.4))
return
a.player_name = partner_name
_tag_all()
if not _welcome_sent:
_welcome_sent = true
_events.clear()
_removed.clear()
_foe_sent.clear() # the partner starts with no enemies
link.send("welcome", _welcome(), true)
"input":
var rec := data as Dictionary
a.remote.apply(rec)
a.body.net_position = rec.get("p", a.body.net_position)
a.body.net_yaw = float(rec.get("y", a.body.net_yaw))
a.body.net_speed = float(rec.get("v", 0.0))
if data is PackedByteArray and a.remote.apply(data):
a.body.net_position = a.remote.position
a.body.net_yaw = a.remote.yaw
a.body.net_speed = a.remote.speed
"req":
_do_request(data as Array)
@ -429,11 +561,15 @@ func _client_message(kind: String, data: Variant) -> void:
"loot":
sim.loot.apply_replica(data as Dictionary, _local_handle)
"snap":
_apply_snap(data as Dictionary)
if data is PackedByteArray:
_apply_snap(data)
"foes":
_apply_foes(data as PackedByteArray)
"shots":
sim.projectiles.apply_replica(data as PackedFloat32Array)
if data is PackedByteArray and (data as PackedByteArray).size() >= 6:
var c := CoopLink.reader(data)
if c.get_u32() >= _snap_tick: # not from an older snapshot than the last
_apply_foes((data as PackedByteArray).slice(6, 6 + c.get_u16() * FOE_RECORD))
"refused":
stop("The host has another version of the game: update both to play together")
"batch":
var b := data as Dictionary
for r: Array in b.get("removed", []):
@ -443,6 +579,9 @@ func _client_message(kind: String, data: Variant) -> void:
func _welcome_received(w: Dictionary) -> void:
if int(w.get("v", 1)) != PROTOCOL:
stop("The host has another version of the game: update both to play together")
return
var c := sim.campaign
partner_name = String(w.get("host", ""))
sim.avatars[0].player_name = partner_name
@ -545,19 +684,55 @@ func _apply_event(e: Array) -> void:
sim.upgrade_panel.open()
func _apply_snap(snap: Dictionary) -> void:
var t := int(snap.get("t", 0))
func _apply_snap(data: PackedByteArray) -> void:
var b := CoopLink.reader(data)
var t := b.get_u32()
if t <= _snap_tick:
return # an older one, out of order
_snap_tick = t
sim.campaign.state.phase_time_left = float(snap["time"])
sim.waves.night_time = float(snap["night"])
for rec: Dictionary in snap["av"]:
var slot := int(rec["s"])
if slot >= sim.avatars.size():
continue
_apply_avatar(sim.avatars[slot], rec)
sim.animals.apply_replica(snap["an"])
sim.campaign.state.phase_time_left = b.get_float()
sim.waves.night_time = b.get_float()
for i in b.get_u8():
var slot := b.get_u8()
var rec := _read_avatar(b)
if slot < sim.avatars.size():
_apply_avatar(sim.avatars[slot], rec)
var an := PackedFloat32Array()
for i in b.get_u8():
var x := CoopLink.get_cm(b)
var z := CoopLink.get_cm(b)
var yaw := CoopLink.get_angle(b)
an.append_array([x, z, yaw, b.get_u8() / 20.0])
sim.animals.apply_replica(an)
var shots := PackedFloat32Array()
for i in b.get_u8():
var x := CoopLink.get_cm(b)
var z := CoopLink.get_cm(b)
var dx := b.get_8() / 127.0
shots.append_array([x, z, dx, b.get_8() / 127.0])
sim.projectiles.apply_replica(shots)
var n := b.get_u16()
var at := b.get_position()
_apply_foes(data.slice(at, at + n * FOE_RECORD))
## A scarecrow from a snapshot (after its slot; see _put_avatar), by the names _apply_avatar uses.
func _read_avatar(b: StreamPeerBuffer) -> Dictionary:
var rec := {"p": CoopLink.get_v3(b), "y": CoopLink.get_angle(b), "v": b.get_u8() / 100.0}
var flags := b.get_u8()
rec["a"] = (flags & 1) != 0
rec["hp"] = b.get_u8()
for key: String in ["inv", "fl", "bl", "pt", "ge", "re"]:
rec[key] = CoopLink.get_time(b)
if (flags & 2) == 0:
rec["pt"] = -1.0 # not patching
rec["w"] = b.get_u8()
rec["ch"] = CoopLink.get_text(b)
rec["fo"] = CoopLink.get_text(b)
rec["ga"] = CoopLink.get_text(b)
rec["rt"] = b.get_32()
rec["rp"] = b.get_32()
return rec
func _apply_avatar(a: Avatar, rec: Dictionary) -> void:
@ -581,9 +756,9 @@ func _apply_avatar(a: Avatar, rec: Dictionary) -> void:
body.die()
k.invulnerable_left = float(rec["inv"])
k.fear_left = float(rec["fl"])
a.combat.bomb_left = float(rec.get("bl", 0.0))
a.combat.bomb_left = float(rec["bl"])
if not a.is_local:
a.combat.show_weapon(int(rec.get("w", 0)))
a.combat.show_weapon(int(rec["w"]))
var pt := float(rec["pt"])
k.patching = pt >= 0.0
k.patch_elapsed = maxf(pt, 0.0)
@ -616,7 +791,7 @@ func _gather_node(node_name: String) -> Node3D:
func _apply_foes(chunk: PackedByteArray) -> void:
var es := sim.enemies
for o in range(0, chunk.size() - 15, 16):
for o in range(0, chunk.size() - FOE_RECORD + 1, FOE_RECORD):
var host := chunk.decode_s32(o)
if _gone.has(host):
continue
@ -634,7 +809,7 @@ func _apply_foes(chunk: PackedByteArray) -> void:
es.state[d] = chunk[o + 5]
es.hurt[d] = chunk[o + 6] / 255.0
var t := PackedFloat32Array([x, z, chunk.decode_s8(o + 12) / 127.0, chunk.decode_s8(o + 13) / 127.0,
chunk.decode_s8(o + 14) / 20.0, chunk.decode_s8(o + 15) / 20.0, chunk[o + 7] / 40.0])
chunk.decode_s8(o + 14) / VEL_SCALE, chunk.decode_s8(o + 15) / VEL_SCALE, chunk[o + 7] / 40.0])
_targets[h] = t
@ -689,6 +864,7 @@ func _replica_tick(dt: float) -> void:
es.vel_x[d] = t[4]
es.vel_z[d] = t[5]
es.alt[d] = lerpf(es.alt[d], t[6], 0.3)
es.hurt[d] = maxf(es.hurt[d] - dt * EnemySystem.HURT_FADE, 0.0) # as on the host, between records
sim.projectiles.advance_replica(dt)
@ -700,19 +876,16 @@ func _reset_world() -> void:
_targets.clear()
## The input record, when it changed or INPUT_KEEPALIVE after the last one (a lost one is
## replaced soon; standing still sends little).
func _send_input() -> void:
var a := sim.local_avatar
var build_on := sim.build.active
var ui := sim.upgrade_panel != null and sim.upgrade_panel.is_open
var rec := _sender.record(a.combat.aim, a.combat.aim_point, int(a.combat.device), build_on, ui)
if sim.local_frozen:
rec["held"] = 0 # a menu is up
rec["p"] = a.body.global_position
rec["y"] = a.body.model.rotation.y
rec["v"] = a.body.move_strength()
rec["weapon"] = int(a.combat.weapon)
rec["ground"] = a.combat.ground_point
link.send("input", rec, false)
var rec := _sender.record(a.combat, a.body, sim.build.active, ui, sim.local_frozen)
if rec != _last_input or _input_age >= INPUT_KEEPALIVE - 0.001: # (sums of 1/60 fall a hair short)
_last_input = rec
_input_age = 0.0
link.send("input", rec, false)
_close_menu_if_needed()