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

@ -1,14 +1,18 @@
class_name RemoteControls
extends RefCounted
## What a scarecrow played on another machine wants this tick, as the host sees it (co-op,
## CoopSession). The partner's game sends its input every frame: which actions are held, a
## running press count per action (so a press is never lost with a dropped packet: the host
## counts the new ones), its aim (and the ground point a pumpkin bomb would land on), the weapon
## in hand, and whether it is building or has the upgrade menu open. The
## kit classes (Scarecrow, Interactions, ScarecrowCombat) read this instead of the local Input
## when their remote is set.
## CoopSession). The partner's game sends its input record (Sender.record, RECORD_SIZE bytes)
## whenever it changes, and again at least every few frames: which actions are held, a running
## press count per action (so a press is never lost with a dropped packet: the host counts the
## new ones), its aim (and the ground point a pumpkin bomb would land on), the weapon in hand,
## whether it is building or has the upgrade menu open, and where its scarecrow is. The kit
## classes (Scarecrow, Interactions, ScarecrowCombat) read this instead of the local Input when
## their remote is set.
const ACTIONS: Array[StringName] = [&"fire", &"fear", &"patch", &"interact", &"offhand"]
## Held bits, a 16-bit count per action, the aim (2 x s16), the aim and ground points and the
## scarecrow's position (3 x s16 cm each), device, weapon, flags, facing (s16), speed.
const RECORD_SIZE := 1 + 2 * 5 + 4 + 6 + 6 + 3 + 6 + 2 + 1
var aim := Vector2(0.0, -1.0)
var aim_point := Vector3.ZERO
@ -19,6 +23,10 @@ var device: int = 0
var weapon: int = -1
var build_active := false
var ui_open := false
## The partner's scarecrow, as its machine moved it (CoopSession puts this on the host's copy).
var position := Vector3.ZERO
var yaw: float = 0.0
var speed: float = 0.0
var _held := 0
var _presses := RemoteControls.counts()
@ -46,21 +54,29 @@ func take(action: StringName) -> bool:
return true
## The partner's input record (CoopSession): {"held": bits, "presses": counts, "aim": Vector2,
## "aim_point": Vector3, "ground": Vector3, "device", "weapon", "build", "ui"}.
func apply(rec: Dictionary) -> void:
_held = int(rec.get("held", 0))
var p: Variant = rec.get("presses", [])
var counts: Array = Array(p) if p is PackedInt32Array else (p if p is Array else [])
for i in mini(ACTIONS.size(), counts.size()):
_presses[i] = maxi(_presses[i], int(counts[i]))
aim = rec.get("aim", aim)
aim_point = rec.get("aim_point", aim_point)
ground_point = rec.get("ground", ground_point)
device = int(rec.get("device", device))
weapon = int(rec.get("weapon", weapon))
build_active = bool(rec.get("build", false))
ui_open = bool(rec.get("ui", false))
## The partner's input record (Sender.record). False if it isn't one.
func apply(rec: PackedByteArray) -> bool:
if rec.size() != RECORD_SIZE:
return false
var b := CoopLink.reader(rec)
_held = b.get_u8()
for i in ACTIONS.size():
var step := (b.get_u16() - _presses[i]) & 0xFFFF # the counts go round at 65536
if step < 0x8000:
_presses[i] += step
var ax := b.get_16() / 10000.0
aim = Vector2(ax, b.get_16() / 10000.0)
aim_point = CoopLink.get_v3(b)
ground_point = CoopLink.get_v3(b)
device = b.get_u8()
weapon = b.get_8()
var flags := b.get_u8()
build_active = (flags & 1) != 0
ui_open = (flags & 2) != 0
position = CoopLink.get_v3(b)
yaw = CoopLink.get_angle(b)
speed = b.get_u8() / 100.0
return true
## Forget held actions (the partner left, or a new morning).
@ -81,7 +97,9 @@ class Sender:
presses[i] += 1
_was[i] = 1
func record(aim: Vector2, aim_point: Vector3, device: int, build: bool, ui: bool) -> Dictionary:
## The input record (RemoteControls.apply): the actions held now (none while frozen: a menu
## is up), every press so far, and the scarecrow.
func record(combat: ScarecrowCombat, body: PlayerCharacter, build: bool, ui: bool, frozen: bool) -> PackedByteArray:
var bits := 0
for i in RemoteControls.ACTIONS.size():
var down := Input.is_action_pressed(RemoteControls.ACTIONS[i])
@ -90,5 +108,18 @@ class Sender:
if _was[i] == 0: # pressed without an event (simulated input)
presses[i] += 1
_was[i] = 1 if down else 0
return {"held": bits, "presses": presses.duplicate(), "aim": aim, "aim_point": aim_point, "device": device,
"build": build, "ui": ui}
var b := StreamPeerBuffer.new()
b.put_u8(0 if frozen else bits)
for i in RemoteControls.ACTIONS.size():
b.put_u16(presses[i] & 0xFFFF)
b.put_16(clampi(roundi(combat.aim.x * 10000.0), -32767, 32767))
b.put_16(clampi(roundi(combat.aim.y * 10000.0), -32767, 32767))
CoopLink.put_v3(b, combat.aim_point)
CoopLink.put_v3(b, combat.ground_point)
b.put_u8(int(combat.device))
b.put_8(int(combat.weapon))
b.put_u8((1 if build else 0) | (2 if ui else 0))
CoopLink.put_v3(b, body.global_position)
CoopLink.put_angle(b, body.model.rotation.y)
b.put_u8(clampi(roundi(body.move_strength() * 100.0), 0, 255))
return b.data_array