mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 07:12:16 +00:00
- music.cpp include cleanup
- use a TMap to store music volume settings instead of using a homegrown linked list.
This commit is contained in:
parent
f0534afde6
commit
00bbc48e70
5 changed files with 26 additions and 77 deletions
|
@ -52,7 +52,6 @@
|
||||||
#include "i_sound.h"
|
#include "i_sound.h"
|
||||||
#include "i_soundfont.h"
|
#include "i_soundfont.h"
|
||||||
#include "s_music.h"
|
#include "s_music.h"
|
||||||
#include "doomstat.h"
|
|
||||||
#include "filereadermusicinterface.h"
|
#include "filereadermusicinterface.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,7 +162,7 @@ static void mus_sfclose(void* handle)
|
||||||
reinterpret_cast<FSoundFontReader*>(handle)->close();
|
reinterpret_cast<FSoundFontReader*>(handle)->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef ZMUSIC_LITE
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// Pass some basic working data to the music backend
|
// Pass some basic working data to the music backend
|
||||||
|
@ -210,7 +209,7 @@ static void SetupDMXGUS()
|
||||||
ZMusic_SetDmxGus(data.GetMem(), (uint32_t)data.GetSize());
|
ZMusic_SetDmxGus(data.GetMem(), (uint32_t)data.GetSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -239,9 +238,11 @@ void I_InitMusic(void)
|
||||||
callbacks.SF_Close = mus_sfclose;
|
callbacks.SF_Close = mus_sfclose;
|
||||||
|
|
||||||
ZMusic_SetCallbacks(&callbacks);
|
ZMusic_SetCallbacks(&callbacks);
|
||||||
|
#ifndef ZMUSIC_LITE
|
||||||
SetupGenMidi();
|
SetupGenMidi();
|
||||||
SetupDMXGUS();
|
SetupDMXGUS();
|
||||||
SetupWgOpn();
|
SetupWgOpn();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
#ifndef __I_MUSIC_H__
|
#ifndef __I_MUSIC_H__
|
||||||
#define __I_MUSIC_H__
|
#define __I_MUSIC_H__
|
||||||
|
|
||||||
|
#include "c_cvars.h"
|
||||||
|
|
||||||
class FileReader;
|
class FileReader;
|
||||||
struct FOptionValues;
|
struct FOptionValues;
|
||||||
|
|
||||||
|
@ -50,4 +52,8 @@ void I_SetMusicVolume (double volume);
|
||||||
|
|
||||||
extern int nomusic;
|
extern int nomusic;
|
||||||
|
|
||||||
|
EXTERN_CVAR(Bool, mus_enabled)
|
||||||
|
EXTERN_CVAR(Float, snd_musicvolume)
|
||||||
|
|
||||||
|
|
||||||
#endif //__I_MUSIC_H__
|
#endif //__I_MUSIC_H__
|
||||||
|
|
|
@ -37,42 +37,19 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#ifdef _WIN32
|
|
||||||
#include <io.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "i_system.h"
|
|
||||||
#include "i_sound.h"
|
#include "i_sound.h"
|
||||||
#include "i_music.h"
|
#include "i_music.h"
|
||||||
|
#include "printf.h"
|
||||||
#include "s_sound.h"
|
|
||||||
#include "s_sndseq.h"
|
|
||||||
#include "s_playlist.h"
|
#include "s_playlist.h"
|
||||||
#include "c_dispatch.h"
|
#include "c_dispatch.h"
|
||||||
#include "m_random.h"
|
|
||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
#include "p_local.h"
|
|
||||||
#include "doomstat.h"
|
|
||||||
#include "cmdlib.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 "s_music.h"
|
||||||
#include "filereadermusicinterface.h"
|
#include "filereadermusicinterface.h"
|
||||||
#include <zmusic.h>
|
#include <zmusic.h>
|
||||||
|
|
||||||
// MACROS ------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
||||||
|
|
||||||
extern float S_GetMusicVolume (const char *music);
|
extern float S_GetMusicVolume (const char *music);
|
||||||
|
@ -86,6 +63,7 @@ MusPlayingInfo mus_playing; // music currently being played
|
||||||
static FPlayList PlayList;
|
static FPlayList PlayList;
|
||||||
float relative_volume = 1.f;
|
float relative_volume = 1.f;
|
||||||
float saved_relative_volume = 1.0f; // this could be used to implement an ACS FadeMusic function
|
float saved_relative_volume = 1.0f; // this could be used to implement an ACS FadeMusic function
|
||||||
|
MusicVolumeMap MusicVolumes;
|
||||||
|
|
||||||
static FileReader DefaultOpenMusic(const char* fn)
|
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);
|
S_StopMusic(true);
|
||||||
|
|
||||||
// Just record it if volume is 0 or music was disabled
|
// 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.loop = looping;
|
||||||
mus_playing.name = musicname;
|
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)
|
if (mus_playing.handle != 0)
|
||||||
{ // play it
|
{ // 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());
|
Printf("Unable to start %s: %s\n", mus_playing.name.GetChars(), ZMusic_GetLastError());
|
||||||
return false;
|
return false;
|
||||||
|
@ -424,7 +404,6 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// S_RestartMusic
|
// S_RestartMusic
|
||||||
|
@ -433,12 +412,17 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
|
||||||
|
|
||||||
void S_RestartMusic ()
|
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;
|
FString song = mus_playing.LastSong;
|
||||||
mus_playing.LastSong = "";
|
mus_playing.LastSong = "";
|
||||||
S_ChangeMusic (song, mus_playing.baseorder, mus_playing.loop, true);
|
S_ChangeMusic (song, mus_playing.baseorder, mus_playing.loop, true);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
S_StopMusic(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
|
@ -31,8 +31,6 @@ void S_ResetMusic ();
|
||||||
bool S_StartMusic (const char *music_name);
|
bool S_StartMusic (const char *music_name);
|
||||||
|
|
||||||
// Start music using <music_name>, and set whether looping
|
// 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);
|
bool S_ChangeMusic (const char *music_name, int order=0, bool looping=true, bool force=false);
|
||||||
|
|
||||||
void S_RestartMusic ();
|
void S_RestartMusic ();
|
||||||
|
|
|
@ -147,14 +147,6 @@ struct FBloodSFX
|
||||||
char RawName[9]; // name of RAW resource
|
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.
|
// This is used to recreate the skin sounds after reloading SNDINFO due to a changed local one.
|
||||||
struct FSavedPlayerSoundInfo
|
struct FSavedPlayerSoundInfo
|
||||||
{
|
{
|
||||||
|
@ -230,7 +222,6 @@ static const char *SICommandStrings[] =
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static FMusicVolume *MusicVolumes_;
|
|
||||||
static TArray<FSavedPlayerSoundInfo> SavedPlayerSounds;
|
static TArray<FSavedPlayerSoundInfo> SavedPlayerSounds;
|
||||||
|
|
||||||
static int NumPlayerReserves;
|
static int NumPlayerReserves;
|
||||||
|
@ -247,28 +238,6 @@ static uint8_t CurrentPitchMask;
|
||||||
|
|
||||||
// CODE --------------------------------------------------------------------
|
// 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
|
// S_CheckIntegrity
|
||||||
|
@ -744,12 +713,7 @@ void S_ClearSoundData()
|
||||||
soundEngine->Clear();
|
soundEngine->Clear();
|
||||||
|
|
||||||
Ambients.Clear();
|
Ambients.Clear();
|
||||||
while (MusicVolumes_ != NULL)
|
MusicVolumes.Clear();
|
||||||
{
|
|
||||||
FMusicVolume *me = MusicVolumes_;
|
|
||||||
MusicVolumes_ = me->Next;
|
|
||||||
M_Free(me);
|
|
||||||
}
|
|
||||||
|
|
||||||
NumPlayerReserves = 0;
|
NumPlayerReserves = 0;
|
||||||
PlayerClassesIsSorted = false;
|
PlayerClassesIsSorted = false;
|
||||||
|
@ -1179,13 +1143,9 @@ static void S_AddSNDINFO (int lump)
|
||||||
|
|
||||||
case SI_MusicVolume: {
|
case SI_MusicVolume: {
|
||||||
sc.MustGetString();
|
sc.MustGetString();
|
||||||
FString musname (sc.String);
|
FName musname (sc.String);
|
||||||
sc.MustGetFloat();
|
sc.MustGetFloat();
|
||||||
FMusicVolume *mv = (FMusicVolume *)M_Malloc (sizeof(*mv) + musname.Len());
|
MusicVolumes[musname] = (float)sc.Float;
|
||||||
mv->Volume = (float)sc.Float;
|
|
||||||
strcpy (mv->MusicName, musname);
|
|
||||||
mv->Next = MusicVolumes_;
|
|
||||||
MusicVolumes_ = mv;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue