From 5acb2676306436868779a54949e4cbdfa8221e77 Mon Sep 17 00:00:00 2001 From: Yamagi Date: Sun, 8 Sep 2024 16:56:09 +0200 Subject: [PATCH] Add a new playback mode `ogg_shuffle` == `4`, truly random playback. 912b65ff74ffc1467fe303c8b70cc1e85d9e02b4 changed mode `3` from random playback to truly random playback, allowing the same track being played several times in a row. Since some users might prefer the old behavior move truly random playback to a new mode `4`. Add it to the menu and finally document the `ogg_shuffle` cvar. In addition to #1143 --- doc/040_cvarlist.md | 9 +++++++++ src/client/menu/menu.c | 1 + src/client/sound/ogg.c | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/doc/040_cvarlist.md b/doc/040_cvarlist.md index 4200fd76..7d11bb62 100644 --- a/doc/040_cvarlist.md +++ b/doc/040_cvarlist.md @@ -291,6 +291,15 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable` 0. Setting this cvar to `1` disables this behavior, the music keeps playing. +* **ogg_shuffle**: Ogg/Vorbis playback mode. Supported modes are: + `0`: Loop the current track (the default). + `1`: Play the current track once, then stop. + `2`: Play all available tracks in a linear sequence. + `3`: Shuffle through the available tracks, never play the same track + twice in a row. + `4`: Shuffle through the available tracks, may play the same track + multiple times in a row. + * **s_doppler**: If set to `1` doppler effects are enabled. This is only supported by the OpenAL sound backend. diff --git a/src/client/menu/menu.c b/src/client/menu/menu.c index 41f97939..90f8ea2d 100644 --- a/src/client/menu/menu.c +++ b/src/client/menu/menu.c @@ -2371,6 +2371,7 @@ Options_MenuInit(void) "play once", "sequential", "random", + "truly random", 0 }; diff --git a/src/client/sound/ogg.c b/src/client/sound/ogg.c index 74fc6303..782c2731 100644 --- a/src/client/sound/ogg.c +++ b/src/client/sound/ogg.c @@ -530,6 +530,7 @@ OGG_PlayTrack(const char *track, qboolean cdtrack, qboolean immediate) newtrack = (curtrack + 1) % (ogg_maxfileindex + 1) != 0 ? (curtrack + 1) : 2; } break; case 3: // random + case 4: // random with true randomness { int retries = 100; newtrack = 0; @@ -537,6 +538,14 @@ OGG_PlayTrack(const char *track, qboolean cdtrack, qboolean immediate) while (retries-- > 0 && newtrack < 2) { newtrack = randk() % (ogg_maxfileindex + 1); + + if (playback == 3) + { + if (newtrack == curtrack) + { + newtrack = 0; + } + } } } break; }