Files
transcience/src/view/sfx.gd
T
claudeandClaude Opus 5 872922e9e2
ci / verify (push) Successful in 48s
Fix boss jitter; add a settings screen for controls and volume
The jitter had two causes, and the larger one is embarrassing: boss_state()
handed back the newest snapshot raw while players and enemies both went
through the interpolator. The boss therefore stepped at the 20Hz snapshot rate
instead of the frame rate. Invisible for as long as every boss stood still,
and the first one that moved looked broken. It is interpolated now -- but not
across an instance change, where the previous snapshot describes a different
fight in a different room and lerping to it would fling the new boss across
the map for a frame.

The smaller cause was server-side: a CHASE boss corrects by the SIGN of its
distance error, so at the standoff the sign flipped every tick and the boss
vibrated a couple of pixels at 60Hz. It has a dead band now.

The settings screen covers rebindable controls and volume, reachable from both
the main menu and the in-game menu. Bindings are stored as physical keycodes
-- following key position, the choice setup_input_map.gd already made -- and
labelled back through the active layout so an AZERTY player reads the letter on
the key their fingers are on. A rebind replaces every event on the action
rather than the first, because an action that kept its alternates would still
answer to the key you just moved away from. A key already in use is refused and
the clash is named. Reset restores what the PROJECT shipped, captured once
before anything overrides it -- captured later it would restore the last
session's choice, which is the thing being undone.

Effects play on an SFX bus created at runtime, so both sliders are real mixer
settings rather than a number multiplied into every play() call.

Worth recording: the test suite AND the smoke test both passed while a client
logged twelve engine errors on every startup. ConfigFile.get_value(s, k, null)
does not mean "no default" -- it means the key is absent and no default was
given, and the engine logs an error per action. Nothing caught it because the
smoke refutations matched SCRIPT ERROR and friends, and a plain ERROR: is none
of those. It surfaced from running the client and reading the output. smoke.sh
now asserts no plain engine errors either, excluding by name the one line Godot
prints on every clean exit, and reintroducing the bug makes it fail.

One mutation caught nothing and should not have: the early return in
linear_to_db_clamped was dead code, since the clamp beneath it already prevents
negative infinity. Removed rather than left looking tested.

check.sh clean, 439 tests, SMOKE PASS (23 assertions), all four diagnostics
green, and a real client boots with zero engine errors.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 10:56:44 +02:00

52 lines
1.6 KiB
GDScript

extends Node
## Sound effects, played from the events the client already receives.
##
## Strictly a view concern: sound is triggered by server events arriving, never
## by anything the client decides for itself, so what you hear matches what
## actually happened. Nothing under src/sim/ knows this exists.
## Voices in the pool. Bullet-hell fire rates mean sounds overlap constantly;
## one player would cut its own tail off on every shot.
const VOICES := 16
## Identical sounds landing within this many frames are collapsed into one, so
## a boss ring hitting eight bullets at once is a bang rather than a wall of
## clipping.
const DEDUPE_FRAMES := 2
var _voices: Array[AudioStreamPlayer] = []
var _next: int = 0
var _last_played: Dictionary = {}
var _frame: int = 0
func _ready() -> void:
# Settings.apply_audio() creates the bus; make sure it exists before the
# players are pointed at it, or they silently fall back to Master and the
# effects slider does nothing.
Settings.apply_audio()
for i in VOICES:
var p := AudioStreamPlayer.new()
p.bus = Settings.SFX_BUS
add_child(p)
_voices.append(p)
func _process(_delta: float) -> void:
_frame += 1
func play(stream: AudioStream, volume_db: float = 0.0) -> void:
if stream == null:
return
var last: int = _last_played.get(stream, -999)
if _frame - last < DEDUPE_FRAMES:
return
_last_played[stream] = _frame
# Round-robin rather than "find a free voice": with this many voices the
# oldest is always the best one to steal, and it needs no search.
var v := _voices[_next]
_next = (_next + 1) % _voices.size()
v.stream = stream
v.volume_db = volume_db
v.play()