0.2.6-dev: no BGM download while the music is muted or at BGM volume 0; the wanted track is fetched once it is audible again (host bandwidth layer 0.1); golden: unchanged
This commit is contained in:
1 parent
a8ff5e7c1d
commit
69011d2b54
3 files changed
+79
-3
No files matched your search
+21
-2
@@ -13,7 +13,9 @@
|
||||
// never block or warn; everything requested before that is remembered (BGM) or dropped (SFX).
|
||||
// - Channels: master → { bgm, sfx, voice } gains; volumes from settings (0..1) + mute. Tab hidden ⇒ suspend.
|
||||
// - BGM: `intro` then `loop` (1 s crossfade); switching tracks fades out/in (0.8 s). The same loop URL
|
||||
// keeps playing across phases (prep and combat share a track).
|
||||
// keeps playing across phases (prep and combat share a track). While the music is silent — muted, or the BGM volume
|
||||
// at 0 — no track is downloaded (≈ 14 MB a match): the wanted one is remembered, another one playing stops, and the
|
||||
// track the screen wants then starts once the music is audible again (`setVolumes`; host bandwidth, layer 0).
|
||||
// - 开战 BGM: `bgm.combatAlts` are the mode's own battle tracks (塞壬唱片 骑士之日 / 无畏者). The track is fixed per
|
||||
// round, not drawn: 无畏者 through rounds 1–7 and 骑士之日 from round 8 on (`combatTrackFor`, the official
|
||||
// schedule), so every client of a match hears the same one, a fight never switches track halfway through and the
|
||||
@@ -662,6 +664,7 @@ export class AudioManager {
|
||||
*/
|
||||
setVolumes(v) {
|
||||
const n = (x, d) => (Number.isFinite(x) ? Math.max(0, Math.min(1, x)) : d);
|
||||
const wasSilent = this.bgmSilent;
|
||||
this.volumes = {
|
||||
bgm: n(v?.bgm, this.volumes.bgm),
|
||||
sfx: n(v?.sfx, this.volumes.sfx),
|
||||
@@ -670,8 +673,13 @@ export class AudioManager {
|
||||
};
|
||||
this._applyVolumes();
|
||||
if (this.volumes.muted || this.volumes.sfx <= 0) this.stopBondCue();
|
||||
// the music became audible again: download and start the track the screen wants now (none was fetched meanwhile)
|
||||
if (wasSilent && !this.bgmSilent && this.ctx && this.wantBgm) { const k = this.wantBgm; this.wantBgm = null; this.playBgm(k); }
|
||||
}
|
||||
|
||||
/** Is the music silent — muted, or the BGM volume at 0? Then no BGM is downloaded (playBgm). */
|
||||
get bgmSilent() { return this.volumes.muted || this.volumes.bgm <= 0; }
|
||||
|
||||
/**
|
||||
* The voice dub (settings 语音语言): 'jp' plays `audio.voiceJp`, anything else `audio.voice` (中文, the default). The
|
||||
* line on air finishes in its own dub; the next one follows the setting.
|
||||
@@ -766,12 +774,23 @@ export class AudioManager {
|
||||
// ---- BGM ------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Switch BGM (null stops). Same loop URL ⇒ no restart.
|
||||
* Switch BGM (null stops). Same loop URL ⇒ no restart. Before the first gesture, or while the music is silent
|
||||
* (`bgmSilent`), the key is only remembered (`wantBgm`) and nothing is downloaded; a different track that is still
|
||||
* playing stops. `_unlock` / `setVolumes` start the remembered track once it can be heard.
|
||||
* @param {string|null} key see bgmKeyFor
|
||||
*/
|
||||
playBgm(key) {
|
||||
try {
|
||||
if (!this.ctx) { this.wantBgm = key; return; }
|
||||
if (this.bgmSilent) {
|
||||
this.wantBgm = key;
|
||||
const silentTrack = resolveBgm(this.getManifest(), key);
|
||||
if (this.bgm && silentTrack && this.bgm.loopUrl === silentTrack.loop) { this.bgm.key = key; return; }
|
||||
++this.bgmToken; // a start still waiting for its download stays silent too
|
||||
this._fadeOutBgm();
|
||||
return;
|
||||
}
|
||||
this.wantBgm = null;
|
||||
const track = resolveBgm(this.getManifest(), key);
|
||||
if (this.bgm && track && this.bgm.loopUrl === track.loop) { this.bgm.key = key; return; }
|
||||
if (!track && !this.bgm) return;
|
||||
|
||||
Reference in new issue
Block a user