mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-02-17 19:11:30 +00:00
Port Sound Test (Stereo) code to new music system
Much of struct soundtest was removed, since the music system handles its functionality now.
This commit is contained in:
parent
39f46a0f20
commit
feada89364
5 changed files with 76 additions and 109 deletions
|
|
@ -61,6 +61,9 @@
|
|||
// Condition Sets
|
||||
#include "m_cond.h"
|
||||
|
||||
// Sound Test
|
||||
#include "music.h"
|
||||
|
||||
// And just some randomness for the exits.
|
||||
#include "m_random.h"
|
||||
|
||||
|
|
@ -6477,22 +6480,22 @@ void M_DrawSoundTest(void)
|
|||
titleoffset += titlewidth;
|
||||
}
|
||||
|
||||
V_DrawRightAlignedString(x + 272-1, 18+32, 0,
|
||||
va("%02u:%02u",
|
||||
G_TicsToMinutes(soundtest.currenttime, true),
|
||||
G_TicsToSeconds(soundtest.currenttime)
|
||||
)
|
||||
);
|
||||
{
|
||||
UINT32 currenttime = min(Music_Elapsed(soundtest.tune), Music_TotalDuration(soundtest.tune));
|
||||
|
||||
V_DrawRightAlignedString(x + 272-1, 18+32, 0,
|
||||
va("%02u:%02u",
|
||||
G_TicsToMinutes(currenttime, true),
|
||||
G_TicsToSeconds(currenttime)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ((soundtest.playing && soundtest.current)
|
||||
&& (soundtest.current->basenoloop[soundtest.currenttrack] == true
|
||||
|| soundtest.autosequence == true))
|
||||
{
|
||||
UINT32 exittime = soundtest.sequencemaxtime;
|
||||
if (soundtest.dosequencefadeout == true)
|
||||
{
|
||||
exittime += SOUNDTEST_FADEOUTSECONDS*TICRATE;
|
||||
}
|
||||
UINT32 exittime = Music_TotalDuration(soundtest.tune);
|
||||
|
||||
V_DrawRightAlignedString(x + 272-1, 18+32+10, 0,
|
||||
va("%02u:%02u",
|
||||
|
|
@ -6546,12 +6549,12 @@ void M_DrawSoundTest(void)
|
|||
// The following are springlocks.
|
||||
else if (currentMenu->menuitems[i].mvar2 == stereospecial_pause) // pause
|
||||
{
|
||||
if (soundtest.paused == true)
|
||||
if (Music_Paused(soundtest.tune) == true)
|
||||
y = currentMenu->y + 6;
|
||||
}
|
||||
else if (currentMenu->menuitems[i].mvar2 == stereospecial_play) // play
|
||||
{
|
||||
if (soundtest.playing == true && soundtest.paused == false)
|
||||
if (soundtest.playing == true && Music_Paused(soundtest.tune) == false)
|
||||
y = currentMenu->y + 6;
|
||||
}
|
||||
else if (currentMenu->menuitems[i].mvar2 == stereospecial_seq) // seq
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
/// \brief Stereo Mode menu
|
||||
|
||||
#include "../../k_menu.h"
|
||||
#include "../../music.h"
|
||||
#include "../../s_sound.h"
|
||||
|
||||
static void M_SoundTestMainControl(INT32 choice)
|
||||
|
|
@ -36,11 +37,11 @@ static void M_SoundTestMainControl(INT32 choice)
|
|||
|
||||
if (currentMenu->menuitems[itemOn].mvar1 == 1) // Play
|
||||
{
|
||||
if (soundtest.paused == true)
|
||||
if (Music_Paused(soundtest.tune) == true)
|
||||
{
|
||||
S_SoundTestTogglePause();
|
||||
}
|
||||
else if (soundtest.playing == false)
|
||||
else if (Music_Paused(soundtest.tune) == false)
|
||||
{
|
||||
S_SoundTestPlay();
|
||||
}
|
||||
|
|
@ -49,7 +50,7 @@ static void M_SoundTestMainControl(INT32 choice)
|
|||
{
|
||||
if (currentMenu->menuitems[itemOn].mvar1 == 2) // Pause
|
||||
{
|
||||
if (soundtest.paused == false)
|
||||
if (Music_Paused(soundtest.tune) == false)
|
||||
{
|
||||
S_SoundTestTogglePause();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,6 +144,26 @@ void Music_Init(void)
|
|||
tune.priority = 100;
|
||||
tune.loop = false;
|
||||
}
|
||||
|
||||
{
|
||||
Tune& tune = g_tunes.insert("stereo");
|
||||
|
||||
tune.priority = 1000;
|
||||
tune.resist = true;
|
||||
tune.keep_open = true;
|
||||
tune.credit = true;
|
||||
}
|
||||
|
||||
{
|
||||
Tune& tune = g_tunes.insert("stereo_fade");
|
||||
|
||||
tune.priority = 1000;
|
||||
tune.fade_out = 5000;
|
||||
tune.fade_out_inclusive = false;
|
||||
tune.resist = true;
|
||||
tune.keep_open = true;
|
||||
tune.credit = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Music_Tick(void)
|
||||
|
|
|
|||
120
src/s_sound.c
120
src/s_sound.c
|
|
@ -1380,7 +1380,7 @@ void S_AttemptToRestoreMusic(void)
|
|||
|
||||
musicdef_t *musicdefstart = NULL;
|
||||
struct cursongcredit cursongcredit; // Currently displayed song credit info
|
||||
struct soundtest soundtest; // Sound Test (sound test)
|
||||
struct soundtest soundtest = {.tune = ""}; // Sound Test (sound test)
|
||||
|
||||
static void S_InsertMusicAtSoundTestSequenceTail(const char *musname, UINT16 map, musicdef_t ***tail)
|
||||
{
|
||||
|
|
@ -1623,66 +1623,63 @@ updatetrackonly:
|
|||
|
||||
void S_SoundTestPlay(void)
|
||||
{
|
||||
UINT32 sequencemaxtime = 0;
|
||||
boolean dosequencefadeout = false;
|
||||
|
||||
if (soundtest.current == NULL)
|
||||
{
|
||||
S_SoundTestStop();
|
||||
return;
|
||||
}
|
||||
|
||||
soundtest.privilegedrequest = true;
|
||||
|
||||
S_StopMusic();
|
||||
|
||||
soundtest.playing = true;
|
||||
|
||||
if (soundtest.paused == true)
|
||||
soundtest.tune = "stereo";
|
||||
|
||||
if (soundtest.current->basenoloop[soundtest.currenttrack] == false)
|
||||
{
|
||||
S_SoundTestTogglePause();
|
||||
// Only fade out if we're the last track for this song.
|
||||
dosequencefadeout = (soundtest.currenttrack == soundtest.current->numtracks-1);
|
||||
|
||||
if (dosequencefadeout)
|
||||
{
|
||||
soundtest.tune = "stereo_fade";
|
||||
}
|
||||
}
|
||||
|
||||
S_ChangeMusicInternal(soundtest.current->name[soundtest.currenttrack],
|
||||
!soundtest.current->basenoloop[soundtest.currenttrack]);
|
||||
Music_Remap(soundtest.tune, soundtest.current->name[soundtest.currenttrack]);
|
||||
Music_Loop(soundtest.tune, !soundtest.current->basenoloop[soundtest.currenttrack]);
|
||||
Music_Play(soundtest.tune);
|
||||
|
||||
soundtest.currenttime = 0;
|
||||
soundtest.sequencemaxtime = S_GetMusicLength();
|
||||
// Assuming this song is now actually playing
|
||||
sequencemaxtime = I_GetSongLength();
|
||||
|
||||
if (soundtest.sequencemaxtime == 0)
|
||||
if (sequencemaxtime == 0)
|
||||
{
|
||||
S_SoundTestStop(); // This sets soundtest.privilegedrequest to false
|
||||
S_SoundTestStop();
|
||||
return;
|
||||
}
|
||||
|
||||
S_ShowMusicCredit();
|
||||
|
||||
// ensure default is always set
|
||||
soundtest.sequencefadeout = 0;
|
||||
soundtest.dosequencefadeout = false;
|
||||
|
||||
// Does song have default loop?
|
||||
if (soundtest.current->basenoloop[soundtest.currenttrack] == false)
|
||||
{
|
||||
if (soundtest.sequencemaxtime < 3*60*1000)
|
||||
if (sequencemaxtime < 3*60*1000)
|
||||
{
|
||||
// I'd personally like songs in sequence to last between 3 and 6 minutes.
|
||||
const UINT32 loopduration = (soundtest.sequencemaxtime - S_GetMusicLoopPoint());
|
||||
const UINT32 loopduration = (sequencemaxtime - I_GetSongLoopPoint());
|
||||
|
||||
if (!loopduration)
|
||||
;
|
||||
else do
|
||||
{
|
||||
soundtest.sequencemaxtime += loopduration;
|
||||
} while (soundtest.sequencemaxtime < 4*1000);
|
||||
sequencemaxtime += loopduration;
|
||||
} while (sequencemaxtime < 4*1000);
|
||||
// If the track is EXTREMELY short, keep adding until about 4s!
|
||||
}
|
||||
|
||||
// Only fade out if we're the last track for this song.
|
||||
soundtest.dosequencefadeout = (soundtest.currenttrack == soundtest.current->numtracks-1);
|
||||
}
|
||||
|
||||
// ms to TICRATE conversion
|
||||
soundtest.sequencemaxtime = (TICRATE*soundtest.sequencemaxtime)/1000;
|
||||
|
||||
soundtest.privilegedrequest = false;
|
||||
Music_DelayEnd(soundtest.tune, (TICRATE*sequencemaxtime)/1000);
|
||||
}
|
||||
|
||||
void S_SoundTestStop(void)
|
||||
|
|
@ -1692,23 +1689,13 @@ void S_SoundTestStop(void)
|
|||
return;
|
||||
}
|
||||
|
||||
soundtest.privilegedrequest = true;
|
||||
soundtest.tune = "";
|
||||
|
||||
soundtest.playing = false;
|
||||
soundtest.paused = false;
|
||||
soundtest.autosequence = false;
|
||||
|
||||
S_StopMusic();
|
||||
S_StopMusicCredit();
|
||||
|
||||
soundtest.currenttime = 0;
|
||||
soundtest.sequencemaxtime = 0;
|
||||
soundtest.sequencefadeout = 0;
|
||||
soundtest.dosequencefadeout = false;
|
||||
|
||||
S_AttemptToRestoreMusic();
|
||||
|
||||
soundtest.privilegedrequest = false;
|
||||
Music_Stop("stereo");
|
||||
Music_Stop("stereo_fade");
|
||||
}
|
||||
|
||||
void S_SoundTestTogglePause(void)
|
||||
|
|
@ -1718,25 +1705,18 @@ void S_SoundTestTogglePause(void)
|
|||
return;
|
||||
}
|
||||
|
||||
if (soundtest.paused == true)
|
||||
if (Music_Paused(soundtest.tune))
|
||||
{
|
||||
soundtest.paused = false;
|
||||
S_ResumeAudio();
|
||||
Music_UnPause(soundtest.tune);
|
||||
}
|
||||
else
|
||||
{
|
||||
soundtest.paused = true;
|
||||
S_PauseAudio();
|
||||
Music_Pause(soundtest.tune);
|
||||
}
|
||||
}
|
||||
|
||||
void S_TickSoundTest(void)
|
||||
{
|
||||
static UINT32 storetime = 0;
|
||||
UINT32 lasttime = storetime;
|
||||
|
||||
storetime = I_GetTime();
|
||||
|
||||
if (soundtest.playing == false || soundtest.current == NULL)
|
||||
{
|
||||
// Nothing worth discussing.
|
||||
|
|
@ -1749,47 +1729,15 @@ void S_TickSoundTest(void)
|
|||
goto handlenextsong;
|
||||
}
|
||||
|
||||
if (I_SongPaused() == false)
|
||||
{
|
||||
// Increment the funny little timer.
|
||||
soundtest.currenttime += (storetime - lasttime);
|
||||
}
|
||||
|
||||
if (soundtest.sequencefadeout != 0)
|
||||
{
|
||||
// Are we done fading out?
|
||||
if (soundtest.currenttime > soundtest.sequencefadeout)
|
||||
{
|
||||
goto handlenextsong;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (soundtest.autosequence == false)
|
||||
{
|
||||
// There's nothing else for us here.
|
||||
return;
|
||||
}
|
||||
|
||||
if (soundtest.currenttime >= soundtest.sequencemaxtime)
|
||||
if (Music_DurationLeft(soundtest.tune) == 0)
|
||||
{
|
||||
if (soundtest.dosequencefadeout == false)
|
||||
{
|
||||
// Handle the immediate progression.
|
||||
goto handlenextsong;
|
||||
}
|
||||
|
||||
if (soundtest.sequencemaxtime > 0)
|
||||
{
|
||||
// Handle the fade.
|
||||
soundtest.privilegedrequest = true;
|
||||
S_FadeMusic(0, SOUNDTEST_FADEOUTSECONDS*1000);
|
||||
soundtest.privilegedrequest = false;
|
||||
}
|
||||
|
||||
// Set the conclusion.
|
||||
soundtest.sequencefadeout = soundtest.currenttime + SOUNDTEST_FADEOUTSECONDS*TICRATE;
|
||||
goto handlenextsong;
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -199,23 +199,19 @@ extern struct cursongcredit
|
|||
|
||||
extern struct soundtest
|
||||
{
|
||||
const char *tune; // Tune used for music system
|
||||
|
||||
boolean playing; // Music is playing?
|
||||
boolean paused; // System paused?
|
||||
boolean justopened; // Menu visual assist
|
||||
boolean privilegedrequest; // Overrides S_PlaysimMusicDisabled w/o changing every function signature
|
||||
|
||||
INT32 menutick; // Menu visual timer
|
||||
|
||||
musicdef_t *current; // Current selected music definition
|
||||
SINT8 currenttrack; // Current selected music track for definition
|
||||
UINT32 currenttime; // Current music playing time
|
||||
|
||||
soundtestsequence_t sequence; // Sequence head
|
||||
|
||||
boolean autosequence; // In auto sequence mode?
|
||||
boolean dosequencefadeout; // Fade out when reaching the end?
|
||||
UINT32 sequencemaxtime; // Maximum playing time for current music
|
||||
UINT32 sequencefadeout; // auto sequence fadeout
|
||||
} soundtest;
|
||||
|
||||
void S_PopulateSoundTestSequence(void);
|
||||
|
|
@ -224,7 +220,6 @@ void S_SoundTestPlay(void);
|
|||
void S_SoundTestStop(void);
|
||||
void S_SoundTestTogglePause(void);
|
||||
void S_TickSoundTest(void);
|
||||
#define SOUNDTEST_FADEOUTSECONDS 5
|
||||
|
||||
extern musicdef_t *musicdefstart;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue