feat: per-voice audio, outlines for what is not an actor, and a coast
Three things a game could not say, each of which had been worked around. Audio.play_at(id, gain:, pitch:, pan:) fires a one-shot with its own gain, pitch and stereo position. Audio.volume and Audio.pitch are global - they are the options screen - so a game placing a sound in the world was fighting them, and distance attenuation was simply not expressible. The backend already took volume and rate per call; this adds setPan: alongside them and stops routing through the master state. ludic.render3d gains outline_model(model, mat, width, r, g, b): a rim around something that is not an Actor. The outline pass walked the actor list and stopped, so instanced scatter - a forest - could not be highlighted at all. It is a queue flushed by the same pass, which is what gets the depth test right when the caller does not control pass order. And terrain_coast(cx, cz, margin, fall), the other way to make an island: the sea around the survey's own edge rather than cut out of the middle of it. terrain_island measures a radius from a centre, which drowns two thirds of a real survey to make an island of the rest; this measures inward from the boundary, so everything the data covers stays land and the coast is where the data runs out. Both modes gained a strand - the last few metres of height either side of the water line compressed, which stretches a cliff plunge out into beach and shallows. 132 regression tests and the self-host fixpoints pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
39ad8e85d9
commit
3c27606747
15 changed files with 30113 additions and 29690 deletions
|
|
@ -13,7 +13,7 @@
|
|||
; they vanish from a headless build):
|
||||
; snd_load(path) -> player snd_play(p, loops, rate, vol)
|
||||
; snd_stop(p) snd_playing(p) -> bool
|
||||
; snd_set_volume(p, vol) snd_set_rate(p, rate)
|
||||
; snd_set_volume(p, vol) snd_set_rate(p, rate) snd_set_pan(p, pan)
|
||||
; loops: 0 = once, -1 = forever. rate / vol are 16.16 fixed (value/65536).
|
||||
; ============================================================================
|
||||
|
||||
|
|
@ -37,6 +37,7 @@ declare ptr @objc_msgSend(ptr, ptr, ...)
|
|||
@.a_play = private unnamed_addr constant [5 x i8] c"play\00"
|
||||
@.a_stop = private unnamed_addr constant [5 x i8] c"stop\00"
|
||||
@.a_isply = private unnamed_addr constant [10 x i8] c"isPlaying\00"
|
||||
@.a_span = private unnamed_addr constant [8 x i8] c"setPan:\00"
|
||||
|
||||
; Load a sound file into an AVAudioPlayer; returns the player (or null).
|
||||
define ptr @snd_load(ptr %path) {
|
||||
|
|
@ -137,6 +138,22 @@ out:
|
|||
ret void
|
||||
}
|
||||
|
||||
; Stereo position, -1.0 (hard left) .. 1.0 (hard right). AVAudioPlayer's own pan, so it
|
||||
; costs nothing and needs no mixer: a one-shot can be placed before it is fired.
|
||||
define void @snd_set_pan(ptr %p, i32 %pan) {
|
||||
entry:
|
||||
%nil = icmp eq ptr %p, null
|
||||
br i1 %nil, label %out, label %go
|
||||
go:
|
||||
%pf = sitofp i32 %pan to float
|
||||
%v = fdiv float %pf, 6.5536e+04
|
||||
%sel_p = call ptr @sel_registerName(ptr @.a_span)
|
||||
%rp = call ptr (ptr, ptr, float) @objc_msgSend(ptr %p, ptr %sel_p, float %v)
|
||||
br label %out
|
||||
out:
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @snd_set_rate(ptr %p, i32 %rate) {
|
||||
entry:
|
||||
%nil = icmp eq ptr %p, null
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const AUDIO_CAP: int = 64 # max simultaneously-loaded sounds
|
|||
|
||||
var snd_ready: bool = false
|
||||
var snd_tab: pointers = null # handle (1-based) -> AVAudioPlayer pointer
|
||||
var snd_master: fixed = 1.0 # master volume, applied to every play
|
||||
var snd_master: fixed = 1.0 # master volume, applied to every play (and to audio_play_at's gain)
|
||||
var snd_rate: fixed = 1.0 # playback rate / pitch (1.0 = normal)
|
||||
var snd_music: int = 0 # the handle currently playing as music (0 = none)
|
||||
# the sound bank: sounds registered by name (Audio.define), played by name (Audio.play(name:))
|
||||
|
|
@ -92,9 +92,42 @@ function audio_play(id: int) -> void {
|
|||
if not is_windowed() { return }
|
||||
let p = audio_get(id)
|
||||
if p == null { return }
|
||||
snd_set_pan(p, 0.0)
|
||||
snd_play(p, 0, snd_rate, snd_master)
|
||||
}
|
||||
|
||||
# Fire a one-shot with its OWN gain, pitch and stereo position, leaving the master
|
||||
# settings alone.
|
||||
#
|
||||
# Audio.volume and Audio.pitch are global: they exist to let a player turn the game down,
|
||||
# and a game that used them to place a sound in the world would be fighting its own
|
||||
# options screen. This is the per-voice version, and it is what distance attenuation is
|
||||
# made of - a 3D game works out how far away and which side a sound is, and says so here.
|
||||
#
|
||||
# gain 0.0 .. 1.0, multiplied by the master volume, so the options screen still wins
|
||||
# pitch 1.0 is as recorded; 0.5 an octave down, 2.0 an octave up
|
||||
# pan -1.0 hard left .. 0.0 centred .. 1.0 hard right
|
||||
#
|
||||
# The one honest limitation: a sound is one player, so firing the same handle again
|
||||
# restarts it rather than layering a second copy. Load a handle per variant when several
|
||||
# need to overlap - which is what a game does anyway to stop a repeated sound machine-gunning.
|
||||
function audio_play_at(id: int, gain: fixed, pitch: fixed, pan: fixed) -> void {
|
||||
if not is_windowed() { return }
|
||||
let p = audio_get(id)
|
||||
if p == null { return }
|
||||
var g = gain
|
||||
if g < 0.0 { g = 0.0 }
|
||||
if g > 1.0 { g = 1.0 }
|
||||
var pn = pan
|
||||
if pn < -1.0 { pn = -1.0 }
|
||||
if pn > 1.0 { pn = 1.0 }
|
||||
var pt = pitch
|
||||
if pt < 0.25 { pt = 0.25 } # AVAudioPlayer's own rate range
|
||||
if pt > 4.0 { pt = 4.0 }
|
||||
snd_set_pan(p, pn)
|
||||
snd_play(p, 0, pt, g * snd_master)
|
||||
}
|
||||
|
||||
# Play a sound as looping background music on the single music channel; any
|
||||
# previous music is stopped first.
|
||||
function audio_play_music(id: int) -> void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue