- music.cpp include cleanup

- use a TMap to store music volume settings instead of using a homegrown linked list.
This commit is contained in:
Christoph Oelckers 2020-04-11 18:24:46 +02:00
parent f0534afde6
commit 00bbc48e70
5 changed files with 26 additions and 77 deletions

View file

@ -52,7 +52,6 @@
#include "i_sound.h"
#include "i_soundfont.h"
#include "s_music.h"
#include "doomstat.h"
#include "filereadermusicinterface.h"
@ -163,7 +162,7 @@ static void mus_sfclose(void* handle)
reinterpret_cast<FSoundFontReader*>(handle)->close();
}
#ifndef ZMUSIC_LITE
//==========================================================================
//
// Pass some basic working data to the music backend
@ -210,7 +209,7 @@ static void SetupDMXGUS()
ZMusic_SetDmxGus(data.GetMem(), (uint32_t)data.GetSize());
}
#endif
//==========================================================================
//
@ -239,9 +238,11 @@ void I_InitMusic(void)
callbacks.SF_Close = mus_sfclose;
ZMusic_SetCallbacks(&callbacks);
#ifndef ZMUSIC_LITE
SetupGenMidi();
SetupDMXGUS();
SetupWgOpn();
#endif
}

View file

@ -34,6 +34,8 @@
#ifndef __I_MUSIC_H__
#define __I_MUSIC_H__
#include "c_cvars.h"
class FileReader;
struct FOptionValues;
@ -50,4 +52,8 @@ void I_SetMusicVolume (double volume);
extern int nomusic;
EXTERN_CVAR(Bool, mus_enabled)
EXTERN_CVAR(Float, snd_musicvolume)
#endif //__I_MUSIC_H__

View file

@ -37,42 +37,19 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <io.h>
#endif
#include "i_system.h"
#include "i_sound.h"
#include "i_music.h"
#include "s_sound.h"
#include "s_sndseq.h"
#include "printf.h"
#include "s_playlist.h"
#include "c_dispatch.h"
#include "m_random.h"
#include "filesystem.h"
#include "p_local.h"
#include "doomstat.h"
#include "cmdlib.h"
#include "v_video.h"
#include "v_text.h"
#include "a_sharedglobal.h"
#include "gstrings.h"
#include "gi.h"
#include "po_man.h"
#include "serializer.h"
#include "d_player.h"
#include "g_levellocals.h"
#include "vm.h"
#include "g_game.h"
#include "s_music.h"
#include "filereadermusicinterface.h"
#include <zmusic.h>
// MACROS ------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
extern float S_GetMusicVolume (const char *music);
@ -86,6 +63,7 @@ MusPlayingInfo mus_playing; // music currently being played
static FPlayList PlayList;
float relative_volume = 1.f;
float saved_relative_volume = 1.0f; // this could be used to implement an ACS FadeMusic function
MusicVolumeMap MusicVolumes;
static FileReader DefaultOpenMusic(const char* fn)
{
@ -381,7 +359,7 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
S_StopMusic(true);
// Just record it if volume is 0 or music was disabled
if (snd_musicvolume <= 0)
if (snd_musicvolume <= 0 || !mus_enabled)
{
mus_playing.loop = looping;
mus_playing.name = musicname;
@ -412,7 +390,9 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
if (mus_playing.handle != 0)
{ // play it
if (!S_StartMusicPlaying(mus_playing.handle, looping, S_GetMusicVolume(musicname), order))
auto volp = MusicVolumes.CheckKey(musicname);
float vol = volp ? *volp : 1.f;
if (!S_StartMusicPlaying(mus_playing.handle, looping, vol, order))
{
Printf("Unable to start %s: %s\n", mus_playing.name.GetChars(), ZMusic_GetLastError());
return false;
@ -424,7 +404,6 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
return false;
}
//==========================================================================
//
// S_RestartMusic
@ -433,12 +412,17 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
void S_RestartMusic ()
{
if (!mus_playing.LastSong.IsEmpty())
if (snd_musicvolume <= 0) return;
if (!mus_playing.LastSong.IsEmpty() && mus_enabled)
{
FString song = mus_playing.LastSong;
mus_playing.LastSong = "";
S_ChangeMusic (song, mus_playing.baseorder, mus_playing.loop, true);
}
else
{
S_StopMusic(true);
}
}
//==========================================================================

View file

@ -31,8 +31,6 @@ void S_ResetMusic ();
bool S_StartMusic (const char *music_name);
// Start music using <music_name>, and set whether looping
bool S_SetupMusic(const char* musicname, int order, bool looping, FileReader(*OpenMusic)(const char* filename));
bool S_ChangeMusic (const char *music_name, int order=0, bool looping=true, bool force=false);
void S_RestartMusic ();

View file

@ -147,14 +147,6 @@ struct FBloodSFX
char RawName[9]; // name of RAW resource
};
// music volume multipliers
struct FMusicVolume
{
FMusicVolume *Next;
float Volume;
char MusicName[1];
};
// This is used to recreate the skin sounds after reloading SNDINFO due to a changed local one.
struct FSavedPlayerSoundInfo
{
@ -230,7 +222,6 @@ static const char *SICommandStrings[] =
NULL
};
static FMusicVolume *MusicVolumes_;
static TArray<FSavedPlayerSoundInfo> SavedPlayerSounds;
static int NumPlayerReserves;
@ -247,28 +238,6 @@ static uint8_t CurrentPitchMask;
// CODE --------------------------------------------------------------------
//==========================================================================
//
// S_GetMusicVolume
//
// Gets the relative volume for the given music track
//==========================================================================
float S_GetMusicVolume (const char *music)
{
FMusicVolume *musvol = MusicVolumes_;
while (musvol != NULL)
{
if (!stricmp (music, musvol->MusicName))
{
return musvol->Volume;
}
musvol = musvol->Next;
}
return 1.f;
}
//==========================================================================
//
// S_CheckIntegrity
@ -744,12 +713,7 @@ void S_ClearSoundData()
soundEngine->Clear();
Ambients.Clear();
while (MusicVolumes_ != NULL)
{
FMusicVolume *me = MusicVolumes_;
MusicVolumes_ = me->Next;
M_Free(me);
}
MusicVolumes.Clear();
NumPlayerReserves = 0;
PlayerClassesIsSorted = false;
@ -1179,13 +1143,9 @@ static void S_AddSNDINFO (int lump)
case SI_MusicVolume: {
sc.MustGetString();
FString musname (sc.String);
FName musname (sc.String);
sc.MustGetFloat();
FMusicVolume *mv = (FMusicVolume *)M_Malloc (sizeof(*mv) + musname.Len());
mv->Volume = (float)sc.Float;
strcpy (mv->MusicName, musname);
mv->Next = MusicVolumes_;
MusicVolumes_ = mv;
MusicVolumes[musname] = (float)sc.Float;
}
break;