Add a fix to load the music from save

This commit implements code to get/set sample offset in an OpenAL channel and saves the music filename/offset into the file. This only works by using the experimental sound system, so it partially fixes #327
This commit is contained in:
smallmodel 2024-07-22 20:07:32 +02:00
parent 2198bdec21
commit 757b4849f8
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
9 changed files with 151 additions and 17 deletions

View file

@ -3976,13 +3976,13 @@ void S_ServerLoaded(void)
Com_DPrintf("Loading Previous Sound State.\n"); Com_DPrintf("Loading Previous Sound State.\n");
S_StopAllSounds2(qfalse); S_StopAllSounds2(qfalse);
//S_TriggeredMusic_Stop(); S_TriggeredMusic_Stop();
//s_bSoundPaused = qtrue; s_bSoundPaused = qtrue;
//S_ReLoad( &svs.soundSystem ); S_ReLoad( &svs.soundSystem );
//
//if( svs.tm_filename[ 0 ] ) { if( svs.tm_filename[ 0 ] ) {
// S_TriggeredMusic_SetupHandle( svs.tm_filename, svs.tm_loopcount, svs.tm_offset, 0 ); S_TriggeredMusic_SetupHandle( svs.tm_filename, svs.tm_loopcount, svs.tm_offset, 0 );
//} }
} }
/* /*

View file

@ -503,6 +503,36 @@ void S_TriggeredMusic_SetupHandle(const char* pszName, int iLoopCount, int iOffs
// FIXME: unimplemented // FIXME: unimplemented
} }
/*
==============
S_GetMusicFilename
==============
*/
const char* S_GetMusicFilename() {
// FIXME: unimplemented
return "";
}
/*
==============
S_GetMusicLoopCount
==============
*/
int S_GetMusicLoopCount() {
// FIXME: unimplemented
return 0;
}
/*
==============
S_GetMusicOffset
==============
*/
unsigned int S_GetMusicOffset() {
// FIXME: unimplemented
return 0;
}
/* /*
============== ==============
callbackServer callbackServer

View file

@ -80,6 +80,10 @@ void S_FadeSound(float fTime);
void S_TriggeredMusic_PlayIntroMusic(); void S_TriggeredMusic_PlayIntroMusic();
void S_TriggeredMusic_SetupHandle(const char* pszName, int iLoopCount, int iOffset, qboolean autostart); void S_TriggeredMusic_SetupHandle(const char* pszName, int iLoopCount, int iOffset, qboolean autostart);
const char* S_GetMusicFilename();
int S_GetMusicLoopCount();
unsigned int S_GetMusicOffset();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -787,4 +787,34 @@ void S_ClearSoundBuffer()
// TODO: Remove once AL is fully implemented // TODO: Remove once AL is fully implemented
} }
/*
==============
S_GetMusicFilename
==============
*/
const char* S_GetMusicFilename()
{
return S_Driver_GetMusicFilename();
}
/*
==============
S_GetMusicLoopCount
==============
*/
int S_GetMusicLoopCount()
{
return S_Driver_GetMusicLoopCount();
}
/*
==============
S_GetMusicOffset
==============
*/
unsigned int S_GetMusicOffset()
{
return S_Driver_GetMusicOffset();
}
#endif #endif

View file

@ -215,6 +215,9 @@ qboolean S_LoadSound(const char *fileName, sfx_t *sfx, int streamed, qboolean fo
#define S_Driver_Respatialize S_Call_SndDriverX(SOUND_DRIVER, Respatialize) #define S_Driver_Respatialize S_Call_SndDriverX(SOUND_DRIVER, Respatialize)
#define S_Driver_SetReverb S_Call_SndDriverX(SOUND_DRIVER, SetReverb) #define S_Driver_SetReverb S_Call_SndDriverX(SOUND_DRIVER, SetReverb)
#define S_Driver_Update S_Call_SndDriverX(SOUND_DRIVER, Update) #define S_Driver_Update S_Call_SndDriverX(SOUND_DRIVER, Update)
#define S_Driver_GetMusicFilename S_Call_SndDriverX(SOUND_DRIVER, GetMusicFilename)
#define S_Driver_GetMusicLoopCount S_Call_SndDriverX(SOUND_DRIVER, GetMusicLoopCount)
#define S_Driver_GetMusicOffset S_Call_SndDriverX(SOUND_DRIVER, GetMusicOffset)
void S_PrintInfo(); void S_PrintInfo();
void S_DumpInfo(); void S_DumpInfo();

View file

@ -958,8 +958,6 @@ void S_UnpauseSound()
return; return;
} }
s_bSoundPaused = true;
for (i = 0; i < MAX_OPENAL_POSITION_CHANNELS; i++) { for (i = 0; i < MAX_OPENAL_POSITION_CHANNELS; i++) {
openal_channel *pChannel = openal.channel[i]; openal_channel *pChannel = openal.channel[i];
if (!pChannel) { if (!pChannel) {
@ -2477,6 +2475,36 @@ void S_OPENAL_Update()
} }
} }
/*
==============
S_OPENAL_GetMusicFilename
==============
*/
const char* S_OPENAL_GetMusicFilename()
{
return openal.tm_filename;
}
/*
==============
S_OPENAL_GetMusicLoopCount
==============
*/
int S_OPENAL_GetMusicLoopCount()
{
return openal.tm_loopcount;
}
/*
==============
S_OPENAL_GetMusicOffset
==============
*/
unsigned int S_OPENAL_GetMusicOffset()
{
return openal.chan_trig_music.sample_offset();
}
/* /*
============== ==============
S_IsSoundPlaying S_IsSoundPlaying
@ -3077,8 +3105,12 @@ openal_channel::sample_offset
*/ */
U32 openal_channel::sample_offset() U32 openal_channel::sample_offset()
{ {
STUB_DESC("sample_offset"); ALint offset = 0;
return 127;
qalGetSourcei(source, AL_SAMPLE_OFFSET, &offset);
alDieIfError();
return offset;
} }
/* /*
@ -3088,8 +3120,12 @@ openal_channel::sample_ms_offset
*/ */
U32 openal_channel::sample_ms_offset() U32 openal_channel::sample_ms_offset()
{ {
STUB_DESC("sample_ms_offset"); float offset = 0;
return 127;
qalGetSourcef(source, AL_SAMPLE_OFFSET, &offset);
alDieIfError();
return offset * 1000.f;
} }
/* /*
@ -3122,7 +3158,8 @@ openal_channel::set_sample_offset
*/ */
void openal_channel::set_sample_offset(U32 offset) void openal_channel::set_sample_offset(U32 offset)
{ {
STUB_DESC("sample_offset"); qalSourcei(source, AL_SAMPLE_OFFSET, offset);
alDieIfError();
} }
/* /*
@ -3132,7 +3169,8 @@ openal_channel::set_sample_ms_offset
*/ */
void openal_channel::set_sample_ms_offset(U32 offset) void openal_channel::set_sample_ms_offset(U32 offset)
{ {
STUB_DESC("sample_ms_offset"); qalSourcef(source, AL_SEC_OFFSET, offset / 1000.f);
alDieIfError();
} }
/* /*
@ -3932,9 +3970,18 @@ void S_TriggeredMusic_SetupHandle(const char *pszName, int iLoopCount, int iOffs
openal.chan_trig_music.set_sample_loop_count(iLoopCount); openal.chan_trig_music.set_sample_loop_count(iLoopCount);
openal.chan_trig_music.set_sample_offset(iOffset); openal.chan_trig_music.set_sample_offset(iOffset);
if (autostart) { // Fixed in OPM
openal.chan_trig_music.play(); // Play the sound then pause it immediately
// So it can be unpaused upon loading from save
openal.chan_trig_music.play();
if (!autostart) {
openal.chan_trig_music.pause();
} }
//if (autostart) {
// openal.chan_trig_music.play();
//}
} }
/* /*

View file

@ -197,6 +197,10 @@ void S_OPENAL_Respatialize(int iEntNum, const vec3_t vHeadPos, const vec3_t vAxi
void S_OPENAL_SetReverb(int iType, float fLevel); void S_OPENAL_SetReverb(int iType, float fLevel);
void S_OPENAL_Update(); void S_OPENAL_Update();
const char* S_OPENAL_GetMusicFilename();
int S_OPENAL_GetMusicLoopCount();
unsigned int S_OPENAL_GetMusicOffset();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -157,6 +157,10 @@ void S_StopMovieAudio();
void S_SetupMovieAudio(const char* pszMovieName); void S_SetupMovieAudio(const char* pszMovieName);
int S_CurrentMoviePosition(); int S_CurrentMoviePosition();
const char* S_GetMusicFilename();
int S_GetMusicLoopCount();
unsigned int S_GetMusicOffset();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -1955,6 +1955,7 @@ qboolean SV_ArchiveServerFile( qboolean loading, qboolean autosave )
time_t aclock; time_t aclock;
Com_DPrintf( "SV_ArchiveServerFile(%s)\n", autosave ? "true" : "false" ); Com_DPrintf( "SV_ArchiveServerFile(%s)\n", autosave ? "true" : "false" );
memset(&save, 0, sizeof(save));
name = Com_GetArchiveFileName( svs.gameName, "ssv" ); name = Com_GetArchiveFileName( svs.gameName, "ssv" );
if( !loading ) if( !loading )
@ -1995,6 +1996,17 @@ qboolean SV_ArchiveServerFile( qboolean loading, qboolean autosave )
strncpy( save.saveName, svs.gameName, sizeof( save.saveName ) ); strncpy( save.saveName, svs.gameName, sizeof( save.saveName ) );
save.mapTime = svs.time - svs.startTime; save.mapTime = svs.time - svs.startTime;
name = S_GetMusicFilename();
if (name) {
Q_strncpyz(save.tm_filename, name, sizeof(save.tm_filename));
save.tm_offset = S_GetMusicOffset();
save.tm_loopcount = S_GetMusicLoopCount();
} else {
save.tm_filename[0] = 0;
save.tm_offset = 0;
save.tm_loopcount = 0;
}
FS_Write( &save, sizeof( savegamestruct_t ), f ); FS_Write( &save, sizeof( savegamestruct_t ), f );
S_Save( f ); S_Save( f );
CM_WritePortalState( f ); CM_WritePortalState( f );