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

@ -7,7 +7,9 @@ extends RefCounted
## pumpkin bombs (thrown from the off-hand, not with the right click leaving build mode) reaching the replica (drawn there, doing no damage of their own), enemies, loot,
## and shots reaching the replica,
## the co-op fall rule (one down is out until morning, both down is Game Over) and Retry, message
## sizes with a crowd, dropped unreliable messages, and either side leaving.
## sizes with a crowd, dropped unreliable messages, and either side leaving. And the traffic: the
## farm state isn't resent for the clock alone, a partner standing still sends little, enemies go
## by dead reckoning, and voice chat's codec and gate (CoopVoice).
const P := CampaignController.Phase
const DT := 1.0 / 60.0
@ -29,6 +31,7 @@ func run(p_r: GameTestRunner) -> void:
await _setup()
_join()
_requests()
_quiet_wire()
await _partner_moves_and_gathers()
_night()
_partner_shoots()
@ -36,6 +39,7 @@ func run(p_r: GameTestRunner) -> void:
_fall_rule()
_crowd()
_leaving()
_voice()
for l in links:
l.close()
host_farm.queue_free()
@ -137,6 +141,22 @@ func _requests() -> void:
"the partner buys an upgrade at the workbench (the host does it)")
## Standing still by day: the clock runs, nothing else changes.
func _quiet_wire() -> void:
_pump(30) # the requests' news settles
var states := links[0].sent_count("state")
var inputs := links[1].sent_count("input")
var left := host.campaign.state.phase_time_left
_pump(120)
r.check(host.campaign.state.phase_time_left < left - 1.5 and links[0].sent_count("state") == states,
"the day's clock runs on both farms, but the farm state isn't resent for it")
var n := links[1].sent_count("input") - inputs
r.check(n >= 7 and n <= 9, "the partner standing still sends its input %d times in 2 s (every %.2f s, not every frame)"
% [n, CoopSession.INPUT_KEEPALIVE])
r.check(absf(client.campaign.state.phase_time_left - host.campaign.state.phase_time_left) < 0.2,
"and the partner's clock follows the host's (from the snapshots)")
func _partner_moves_and_gathers() -> void:
var tree: GatherNode
for n in host.interactions.nodes:
@ -303,6 +323,19 @@ func _crowd() -> void:
r.info("co-op traffic: host sent %d messages, %.1f KB in %d ticks; partner %d messages" % [links[0].sent_messages,
links[0].sent_bytes / 1024.0, hs.ticks, links[1].sent_messages])
links[0].drop_every = 0
# Dead reckoning: two seconds of the crowd, against every enemy in every snapshot.
var records := hs.foe_records
var bytes := links[0].sent_bytes
var partner_bytes := links[1].sent_bytes
var snaps := links[0].sent_count("snap")
var crowd := host.enemies.alive_count()
_pump(120)
var every := crowd * (links[0].sent_count("snap") - snaps)
r.check(hs.foe_records - records < every / 2, "the host sends %d enemy records in 2 s, not %d (only the ones the partner's guess drifted from)"
% [hs.foe_records - records, every])
r.check(_enemies_match(1.0), "and the partner's crowd still matches the host's")
r.info("crowd of %d: host %.1f KB/s, partner %.1f KB/s (before GD-Sync's wrapping)" % [crowd,
(links[0].sent_bytes - bytes) / 2048.0, (links[1].sent_bytes - partner_bytes) / 2048.0])
func _leaving() -> void:
@ -319,6 +352,60 @@ func _leaving() -> void:
r.check(not host.campaign.state.coop, "a co-op morning played alone goes back to the solo rules")
## Voice chat's sending, without GD-Sync: the gate, the pieces, and the codec.
func _voice() -> void:
var v := CoopVoice.new()
var mix := 48000.0
var hum := _frames(mix, 1.0, func(t: float) -> float: return 0.003 * sin(TAU * 50.0 * t))
r.check(v.feed(hum, mix).is_empty(), "voice: a quiet microphone (room hum) sends nothing")
var click := _frames(mix, 0.03, func(t: float) -> float: return 0.6 if int(t * 4000.0) % 2 == 0 else -0.6)
var sent := v.feed(click, mix)
sent.append_array(v.feed(hum, mix))
r.check(sent.is_empty(), "a click alone doesn't open the gate")
var words := v.feed(_frames(mix, 0.6, func(t: float) -> float: return 0.2 * sin(TAU * 220.0 * t)), mix)
words.append_array(v.feed(hum, mix))
var size := 3 + CoopVoice.CHUNK / 2
var all_sized := true
for piece in words:
all_sized = all_sized and piece.size() == size
r.check(words.size() >= 12 and words.size() <= 22 and all_sized,
"speech opens it: %d pieces of %d bytes (0.6 s of voice, the piece before, and the hold)" % [words.size(), size])
r.check(v.feed(hum, mix).is_empty(), "and the gate shuts again after the hold")
var kbs := size * float(CoopVoice.RATE) / CoopVoice.CHUNK / 1024.0
r.check(kbs < 7.0, "talking costs %.1f KB/s before GD-Sync's wrapping (GD-Sync's raw VoiceChat: about 47)" % kbs)
v.free()
var tone := PackedFloat32Array()
for i in 2 * CoopVoice.CHUNK:
tone.append(0.25 * sin(TAU * 300.0 * i / CoopVoice.RATE) + 0.1 * sin(TAU * 1100.0 * i / CoopVoice.RATE))
var state := [0, 0]
var first := CoopVoice.encode(tone.slice(0, CoopVoice.CHUNK), state)
var second := CoopVoice.encode(tone.slice(CoopVoice.CHUNK), state)
var snr_first := _snr(tone.slice(0, CoopVoice.CHUNK), CoopVoice.decode(first))
var snr_second := _snr(tone.slice(CoopVoice.CHUNK), CoopVoice.decode(second))
r.check(snr_first > 15.0 and snr_second > 25.0,
"ADPCM keeps the sound: %.0f dB signal to noise from a cold start (a few samples to adapt), %.0f dB running" % [snr_first, snr_second])
r.check(CoopVoice.decode(second).size() == CoopVoice.CHUNK, "and a piece decodes on its own (a lost one before it costs nothing more)")
## Stereo microphone frames: seconds of f(t) at mix Hz.
static func _frames(mix: float, seconds: float, f: Callable) -> PackedVector2Array:
var out := PackedVector2Array()
out.resize(roundi(mix * seconds))
for i in out.size():
var s: float = f.call(i / mix)
out[i] = Vector2(s, s)
return out
static func _snr(a: PackedFloat32Array, b: PackedFloat32Array) -> float:
var sig := 0.0
var noise := 0.0
for i in mini(a.size(), b.size()):
sig += a[i] * a[i]
noise += (a[i] - b[i]) * (a[i] - b[i])
return 10.0 * log(sig / maxf(noise, 1e-12)) / log(10.0)
func _types(es: EnemySystem) -> Dictionary:
var out := {}
for d in es.active_count: