- fixed most issues with newly added music files

This commit is contained in:
Christoph Oelckers 2019-11-11 01:01:18 +01:00
parent ae06d19008
commit f6a9bb770d
9 changed files with 78 additions and 71 deletions

View file

@ -64,6 +64,7 @@ enum
//CVAR_IGNORE = 16384,// do not send cvar across the network/inaccesible from ACS (dummy mod cvar)
//CVAR_CHEAT = 32768,// can be set only when sv_cheats is enabled
//CVAR_UNSAFECONTEXT = 65536,// cvar value came from unsafe context
CVAR_VIRTUAL = 0x20000, //do not invoke the callback recursively so it can
CVAR_FRONTEND_BLOOD = 0x10000000, // To mark frontend specific CVARs, so that the other ones can disable them.
CVAR_FRONTEND_EDUKE = 0x20000000,
CVAR_FRONTEND_DUKELIKE = 0x30000000,
@ -107,7 +108,15 @@ public:
FBaseCVar (const char *name, uint32_t flags, void (*callback)(FBaseCVar &), const char *descr);
virtual ~FBaseCVar ();
inline void Callback () { if (m_Callback) m_Callback (*this); }
inline void Callback ()
{
if (m_Callback && !inCallback)
{
inCallback = !!(Flags & CVAR_VIRTUAL); // Virtual CVARs never invoke the callback recursively, giving it a chance to manipulate the value without side effects.
m_Callback(*this);
inCallback = false;
}
}
inline const char *GetName () const { return VarName.GetChars(); }
inline uint32_t GetFlags () const { return Flags; }

View file

@ -21,6 +21,7 @@
#include "c_console.h"
#include "c_dispatch.h"
#include "i_specialpaths.h"
#include "z_music.h"
#ifndef NETCODE_DISABLE
#include "enet.h"
#endif
@ -234,7 +235,7 @@ int GameMain()
{
// Set up the console before anything else so that it can receive text.
C_InitConsole(1024, 768, true);
FStringf logpath("logfile %sdemolition.log", M_GetDocumentsPath());
FStringf logpath("logfile %sdemolition.log", M_GetDocumentsPath().GetChars());
C_DoCommand(logpath);
#ifndef NETCODE_DISABLE
@ -368,7 +369,6 @@ int CONFIG_Init()
currentGame.Truncate(currentGame.IndexOf("."));
CheckFrontend(g_gameType);
int index = 0;
InitFileSystem(usedgroups);
CONTROL_ClearAssignments();
@ -388,6 +388,7 @@ int CONFIG_Init()
}
V_InitFonts();
buttonMap.SetGameAliases();
Mus_Init();

View file

@ -40,10 +40,11 @@
#include <zlib.h>
#include "m_argv.h"
#include "filesystrem.h"
#include "filesystem.h"
#include "c_dispatch.h"
#include "templates.h"
#include "stats.h"
#include "cmdlib.h"
#include "c_cvars.h"
#include "c_console.h"
#include "v_text.h"
@ -58,6 +59,7 @@
void I_InitSoundFonts();
void S_SetStreamVolume(float);
EXTERN_CVAR (Int, snd_samplerate)
EXTERN_CVAR (Int, snd_mididevice)
@ -118,12 +120,8 @@ CUSTOM_CVARD(Int, mus_volume, 255, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "controls mus
{
// Set general music volume.
ChangeMusicSetting(ZMusic::snd_musicvolume, nullptr, self / 255.f);
/* todo: Alter the active music stream's volume
if (GSnd != nullptr)
{
GSnd->SetMusicVolume(clamp<float>(self * relative_volume, 0, 1));
}
*/
S_SetStreamVolume(clamp<float>(self * relative_volume, 0, 1));
// For music not implemented through the digital sound system,
// let them know about the change.
if (mus_playing.handle != nullptr)
@ -216,13 +214,13 @@ static void SetupGenMidi()
{
// The OPL renderer should not care about where this comes from.
// Note: No I_Error here - this needs to be consistent with the rest of the music code.
auto lump = fileSystem.FindFile("demolition/genmidi.txt");
auto lump = fileSystem.FindFile("demolition/genmidi.dat");
if (lump < 0)
{
Printf("No GENMIDI lump found. OPL playback not available.");
return;
}
auto data = Wads.OpenLumpReader(lump);
auto data = fileSystem.OpenFileReader(lump);
auto genmidi = data.Read();
if (genmidi.Size() < 8 + 175 * 36 || memcmp(genmidi.Data(), "#OPL_II#", 8)) return;
@ -235,7 +233,7 @@ static void SetupGenMidi()
//
//==========================================================================
void I_InitMusic (void)
void Mus_Init(void)
{
I_InitSoundFonts();
@ -333,7 +331,7 @@ static MIDISource *GetMIDISource(const char *fn)
return nullptr;
}
auto wlump = fileSystem.OpenFile(lump);
auto wlump = fileSystem.OpenFileReader(lump);
uint32_t id[32 / 4];

View file

@ -313,7 +313,7 @@ FLumpPatchSetReader::FLumpPatchSetReader(const char *filename)
FileReader FLumpPatchSetReader::OpenMainConfigFile()
{
return Wads.ReopenLumpReader(mLumpIndex);
return fileSystem.ReopenFileReader(mLumpIndex);
}
FileReader FLumpPatchSetReader::OpenFile(const char *name)
@ -323,7 +323,7 @@ FileReader FLumpPatchSetReader::OpenFile(const char *name)
path = mBasePath + name;
auto index = fileSystem.FindFile(path);
if (index < 0) return FileReader();
return Wads.ReopenLumpReader(index);
return fileSystem.ReopenFileReader(index);
}
//==========================================================================

View file

@ -58,18 +58,40 @@
#include "zstring.h"
#include "name.h"
#include "s_music.h"
#include "i_music.h"
#include "printf.h"
#include "files.h"
#include "filesystem.h"
#include "cmdlib.h"
#include "gamecvars.h"
#include "c_dispatch.h"
#include "gamecontrol.h"
#include "filereadermusicinterface.h"
MusPlayingInfo mus_playing;
MusicAliasMap MusicAliases;
MidiDeviceMap MidiDevices;
MusicVolumeMap MusicVolumes;
bool MusicPaused;
void S_CreateStream()
{
}
void S_PauseStream(bool pause)
{
}
void S_StopStream()
{
}
void S_SetStreamVolume(float vol)
{
}
//==========================================================================
//
// starts playing this song
@ -88,7 +110,7 @@ static void S_StartMusicPlaying(MusInfo* song, bool loop, float rel_vol, int sub
ZMusic_Start(song, subsong, loop);
// Notify the sound system of the changed relative volume
snd_musicvolume.Callback();
mus_volume.Callback();
}
@ -143,47 +165,11 @@ void S_UpdateMusic ()
// playlist when the current song finishes.
if (!ZMusic_IsPlaying(mus_playing.handle))
{
if (PlayList.GetNumSongs())
{
PlayList.Advance();
S_ActivatePlayList(false);
}
else
{
S_StopMusic(true);
}
S_StopMusic(true);
}
}
}
//==========================================================================
//
// S_Start
//
// Per level startup code. Kills playing sounds at start of level
// and starts new music.
//==========================================================================
void S_StartMusic ()
{
// stop the old music if it has been paused.
// This ensures that the new music is started from the beginning
// if it's the same as the last one and it has been paused.
if (MusicPaused) S_StopMusic(true);
// start new music for the level
MusicPaused = false;
// Don't start the music if loading a savegame, because the music is stored there.
// Don't start the music if revisiting a level in a hub for the same reason.
if (!primaryLevel->IsReentering())
{
primaryLevel->SetMusic();
}
}
//==========================================================================
//
// S_ChangeCDMusic
@ -197,11 +183,11 @@ bool S_ChangeCDMusic (int track, unsigned int id, bool looping)
if (id != 0)
{
mysnprintf (temp, countof(temp), ",CD,%d,%x", track, id);
snprintf (temp, countof(temp), ",CD,%d,%x", track, id);
}
else
{
mysnprintf (temp, countof(temp), ",CD,%d", track);
snprintf (temp, countof(temp), ",CD,%d", track);
}
return S_ChangeMusic (temp, 0, looping);
}
@ -296,7 +282,6 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
else
{
int lumpnum = -1;
int length = 0;
MusInfo* handle = nullptr;
MidiDeviceSetting* devp = MidiDevices.CheckKey(musicname);
@ -311,8 +296,13 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
{
if ((lumpnum = fileSystem.FindFile(musicname)) == -1)
{
Printf("Music \"%s\" not found\n", musicname);
return false;
// Always look in the 'music' subfolder as well.
FStringf aliasMusicname("music/%s", musicname);
if ((lumpnum = fileSystem.FindFile(aliasMusicname)) == -1)
{
Printf("Music \"%s\" not found\n", musicname);
return false;
}
}
if (handle == nullptr)
{
@ -373,7 +363,8 @@ bool S_ChangeMusic(const char* musicname, int order, bool looping, bool force)
{ // play it
try
{
S_StartMusicPlaying(mus_playing.handle, looping, S_GetMusicVolume(musicname), order);
auto vol = MusicVolumes.CheckKey(musicname);
S_StartMusicPlaying(mus_playing.handle, looping, vol? *vol : 1.f, order);
S_CreateStream();
mus_playing.baseorder = order;
}
@ -456,7 +447,7 @@ void S_StopMusic (bool force)
try
{
// [RH] Don't stop if a playlist is active.
if ((force || PlayList.GetNumSongs() == 0) && !mus_playing.name.IsEmpty())
if (!mus_playing.name.IsEmpty())
{
if (mus_playing.handle != nullptr)
{
@ -483,8 +474,6 @@ void S_StopMusic (bool force)
}
}
}
//==========================================================================
//
// CCMD changemus
@ -493,11 +482,10 @@ void S_StopMusic (bool force)
CCMD (changemus)
{
if (!nomusic)
if (MusicEnabled())
{
if (argv.argc() > 1)
{
PlayList.Clear();
S_ChangeMusic (argv[1], argv.argc() > 2 ? atoi (argv[2]) : 0);
}
else
@ -527,19 +515,23 @@ CCMD (changemus)
CCMD (stopmus)
{
PlayList.Clear();
S_StopMusic (false);
mus_playing.LastSong = ""; // forget the last played song so that it won't get restarted if some volume changes occur
}
void Mus_Play(const char *fn, bool loop)
{
S_ChangeMusic(fn, 0, loop, true);
}
void Mus_SetVolume(float vol)
void Mus_Stop()
{
S_StopMusic(true);
}
void Mus_SetPaused(bool on)
{
if (on) S_PauseMusic();
else S_ResumeMusic();
}

View file

@ -33,7 +33,6 @@
#define DEF_MIDIDEV -5
EXTERN_CVAR(Int, snd_mididevice)
static uint32_t nummididevices;
#define NUM_DEF_DEVICES 7
@ -56,7 +55,10 @@ void I_InitMusicWin32 ()
#include "v_text.h"
#include "zmusic/zmusic.h"
#include "s_music.h"
#include "c_cvars.h"
#include "printf.h"
EXTERN_CVAR(Int, snd_mididevice)
CUSTOM_CVAR (Int, snd_mididevice, DEF_MIDIDEV, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL)

View file

@ -30,6 +30,7 @@
#include "zstring.h"
#include "tarray.h"
#include "name.h"
//
@ -71,9 +72,11 @@ struct MidiDeviceSetting
typedef TMap<FName, FName> MusicAliasMap;
typedef TMap<FName, MidiDeviceSetting> MidiDeviceMap;
typedef TMap<FName, float> MusicVolumeMap;
extern MusicAliasMap MusicAliases;
extern MidiDeviceMap MidiDevices;
extern MusicVolumeMap MusicVolumes;
class MusInfo;
struct MusPlayingInfo

View file

@ -2,7 +2,7 @@
// Totally minimalistic interface - should be all the game modules need.
void Mus_Init();
void Mus_Play(const char *fn, bool loop);
void Mus_Stop();
void Mus_SetVolume(float vol);
void Mus_SetPaused(bool on);

View file

@ -1,4 +1,5 @@
#define WIN32_LEAN_AND_MEAN
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <windows.h> // Ugh... This needs to go away but since some of the headers pull it in the compilation is creepingly slow without this.
@ -6,6 +7,7 @@
#undef min
#undef max
#endif
#endif
#include <stddef.h>
#include <stdlib.h>
@ -39,4 +41,4 @@
// These two headers get included nearly everywhere so it doesn't matter if changing them forces a few more recompiles.
// The overall savings from PCHing them are more significant.
//#include "tarray.h"
//#include "zstring.h"
//#include "zstring.h"