- add a system interface for CheckCheatmode and moved some sound code to the backend.

This commit is contained in:
Christoph Oelckers 2022-10-02 15:14:11 +02:00
parent 75afc69306
commit 8aaab153fa
25 changed files with 187 additions and 164 deletions

View file

@ -44,8 +44,11 @@
#include "m_random.h" #include "m_random.h"
#include "printf.h" #include "printf.h"
#include "c_cvars.h" #include "c_cvars.h"
#include "gamestate.h"
CVARD(Bool, snd_enabled, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "enables/disables sound effects") CVARD(Bool, snd_enabled, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "enables/disables sound effects")
CVAR(Bool, i_soundinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, i_pauseinbackground, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
int SoundEnabled() int SoundEnabled()
{ {
@ -1710,3 +1713,160 @@ void S_SoundReset()
S_RestartMusic(); S_RestartMusic();
} }
//==========================================================================
//
// CCMD cachesound <sound name>
//
//==========================================================================
#include "s_music.h"
#include "vm.h"
#include "c_dispatch.h"
#include "stats.h"
#include "i_net.h"
#include "i_interface.h"
CCMD(cachesound)
{
if (argv.argc() < 2)
{
Printf("Usage: cachesound <sound> ...\n");
return;
}
for (int i = 1; i < argv.argc(); ++i)
{
FSoundID sfxnum = argv[i];
if (sfxnum != FSoundID(0))
{
soundEngine->CacheSound(sfxnum);
}
}
}
CCMD(listsoundchannels)
{
Printf("%s", soundEngine->ListSoundChannels().GetChars());
}
// intentionally moved here to keep the s_music include out of the rest of the file.
//==========================================================================
//
// S_PauseSound
//
// Stop music and sound effects, during game PAUSE.
//==========================================================================
void S_PauseSound(bool notmusic, bool notsfx)
{
if (!notmusic)
{
S_PauseMusic();
}
if (!notsfx)
{
soundEngine->SetPaused(true);
GSnd->SetSfxPaused(true, 0);
}
}
DEFINE_ACTION_FUNCTION(DObject, S_PauseSound)
{
PARAM_PROLOGUE;
PARAM_BOOL(notmusic);
PARAM_BOOL(notsfx);
S_PauseSound(notmusic, notsfx);
return 0;
}
//==========================================================================
//
// S_ResumeSound
//
// Resume music and sound effects, after game PAUSE.
//==========================================================================
void S_ResumeSound(bool notsfx)
{
S_ResumeMusic();
if (!notsfx)
{
soundEngine->SetPaused(false);
GSnd->SetSfxPaused(false, 0);
}
}
DEFINE_ACTION_FUNCTION(DObject, S_ResumeSound)
{
PARAM_PROLOGUE;
PARAM_BOOL(notsfx);
S_ResumeSound(notsfx);
return 0;
}
//==========================================================================
//
// S_SetSoundPaused
//
// Called with state non-zero when the app is active, zero when it isn't.
//
//==========================================================================
void S_SetSoundPaused(int state)
{
if (!netgame && (i_pauseinbackground))
{
pauseext = !state;
}
if ((state || i_soundinbackground) && !pauseext)
{
if (paused == 0)
{
S_ResumeSound(true);
if (GSnd != nullptr)
{
GSnd->SetInactive(SoundRenderer::INACTIVE_Active);
}
}
}
else
{
if (paused == 0)
{
S_PauseSound(false, true);
if (GSnd != nullptr)
{
GSnd->SetInactive(gamestate == GS_LEVEL || gamestate == GS_TITLELEVEL ?
SoundRenderer::INACTIVE_Complete :
SoundRenderer::INACTIVE_Mute);
}
}
}
}
CCMD(snd_status)
{
GSnd->PrintStatus();
}
CCMD(snd_reset)
{
S_SoundReset();
}
CCMD(snd_listdrivers)
{
GSnd->PrintDriversList();
}
ADD_STAT(sound)
{
return GSnd->GatherStats();
}

View file

@ -306,6 +306,7 @@ public:
void MarkUsed(int num); void MarkUsed(int num);
void CacheMarkedSounds(); void CacheMarkedSounds();
TArray<FSoundChan*> AllActiveChannels(); TArray<FSoundChan*> AllActiveChannels();
virtual void SetSoundPaused(int state) {}
void MarkAllUnused() void MarkAllUnused()
{ {

View file

@ -43,6 +43,7 @@
#include "engineerrors.h" #include "engineerrors.h"
#include "printf.h" #include "printf.h"
#include "palutil.h" #include "palutil.h"
#include "i_interface.h"
struct FLatchedValue struct FLatchedValue
@ -1462,7 +1463,7 @@ EXTERN_CVAR(Bool, sv_cheats);
void FBaseCVar::CmdSet (const char *newval) void FBaseCVar::CmdSet (const char *newval)
{ {
if ((GetFlags() & CVAR_CHEAT) && CheckCheatmode ()) if ((GetFlags() & CVAR_CHEAT) && sysCallbacks.CheckCheatmode && sysCallbacks.CheckCheatmode(true, false))
return; return;
MarkUnsafe(); MarkUnsafe();

View file

@ -59,8 +59,6 @@ extern bool ParsingKeyConf, UnsafeExecutionContext;
extern FString StoredWarp; // [RH] +warp at the command line extern FString StoredWarp; // [RH] +warp at the command line
extern bool CheckCheatmode (bool printmsg = true, bool sponly = false);
FExecList *C_ParseCmdLineParams(FExecList *exec); FExecList *C_ParseCmdLineParams(FExecList *exec);
// Add commands to the console as if they were typed in. Can handle wait // Add commands to the console as if they were typed in. Can handle wait

View file

@ -17,6 +17,8 @@ bool AppActive = true;
int chatmodeon; int chatmodeon;
gamestate_t gamestate = GS_STARTUP; gamestate_t gamestate = GS_STARTUP;
bool ToggleFullscreen; bool ToggleFullscreen;
int paused;
bool pauseext;
FStartupInfo GameStartupInfo; FStartupInfo GameStartupInfo;

View file

@ -35,6 +35,7 @@ struct SystemCallbacks
void (*ToggleFullConsole)(); void (*ToggleFullConsole)();
void (*StartCutscene)(bool blockui); void (*StartCutscene)(bool blockui);
void (*SetTransition)(int type); void (*SetTransition)(int type);
bool (*CheckCheatmode)(bool printmsg, bool sponly);
}; };
extern SystemCallbacks sysCallbacks; extern SystemCallbacks sysCallbacks;
@ -50,5 +51,7 @@ extern FString endoomName;
extern bool batchrun; extern bool batchrun;
extern float menuBlurAmount; extern float menuBlurAmount;
extern bool generic_ui; extern bool generic_ui;
extern int paused;
extern bool pauseext;
void UpdateGenericUI(bool cvar); void UpdateGenericUI(bool cvar);

View file

@ -69,6 +69,7 @@
#include "s_music.h" #include "s_music.h"
#include "texturemanager.h" #include "texturemanager.h"
#include "v_draw.h" #include "v_draw.h"
#include "d_main.h"
extern FILE *Logfile; extern FILE *Logfile;
extern bool insave; extern bool insave;

View file

@ -50,7 +50,7 @@
#include "i_interface.h" #include "i_interface.h"
EXTERN_CVAR(Bool, queryiwad); EXTERN_CVAR(Bool, queryiwad);
EXTERN_CVAR(Bool, defaultiwad); EXTERN_CVAR(String, defaultiwad);
//========================================================================== //==========================================================================
// //

View file

@ -3529,6 +3529,7 @@ static int D_DoomMain_Internal (void)
System_ToggleFullConsole, System_ToggleFullConsole,
System_StartCutscene, System_StartCutscene,
System_SetTransition, System_SetTransition,
CheckCheatmode,
}; };

View file

@ -161,4 +161,6 @@ inline bool V_IsTrueColor()
return vid_rendermode == 1 || vid_rendermode == 4; return vid_rendermode == 1 || vid_rendermode == 4;
} }
bool CheckCheatmode(bool printmsg = true, bool sponly = false);
#endif #endif

View file

@ -69,6 +69,8 @@
#include "gstrings.h" #include "gstrings.h"
#include "s_music.h" #include "s_music.h"
#include "screenjob.h" #include "screenjob.h"
#include "d_main.h"
#include "i_interface.h"
EXTERN_CVAR (Int, disableautosave) EXTERN_CVAR (Int, disableautosave)
EXTERN_CVAR (Int, autosavecount) EXTERN_CVAR (Int, autosavecount)

View file

@ -108,8 +108,6 @@ EXTERN_CVAR (Float, snd_musicvolume) // maximum volume for music
#include "menustate.h" #include "menustate.h"
extern bool automapactive; // In AutoMap mode? extern bool automapactive; // In AutoMap mode?
extern int paused; // Game Pause?
extern bool pauseext;
extern bool viewactive; extern bool viewactive;

View file

@ -44,6 +44,7 @@
#include "c_functions.h" #include "c_functions.h"
#include "gstrings.h" #include "gstrings.h"
#include "texturemanager.h" #include "texturemanager.h"
#include "d_main.h"
//========================================================================== //==========================================================================
// //

View file

@ -89,6 +89,7 @@
#include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawinfo.h"
#include "doommenu.h" #include "doommenu.h"
#include "screenjob.h" #include "screenjob.h"
#include "i_interface.h"
static FRandom pr_dmspawn ("DMSpawn"); static FRandom pr_dmspawn ("DMSpawn");
@ -145,8 +146,6 @@ extern bool playedtitlemusic;
gameaction_t gameaction; gameaction_t gameaction;
int paused;
bool pauseext;
bool sendpause; // send a pause event next tic bool sendpause; // send a pause event next tic
bool sendsave; // send a save event next tic bool sendsave; // send a save event next tic
bool sendturn180; // [RH] send a 180 degree turn next tic bool sendturn180; // [RH] send a 180 degree turn next tic

View file

@ -46,6 +46,7 @@
#include "filesystem.h" #include "filesystem.h"
#include "am_map.h" #include "am_map.h"
#include "c_dispatch.h" #include "c_dispatch.h"
#include "i_interface.h"
#include "p_setup.h" #include "p_setup.h"
#include "p_local.h" #include "p_local.h"

View file

@ -53,6 +53,7 @@
#include "filesystem.h" #include "filesystem.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "texturemanager.h" #include "texturemanager.h"
#include "d_main.h"
extern void LoadActors (); extern void LoadActors ();
extern void InitBotStuff(); extern void InitBotStuff();

View file

@ -54,6 +54,7 @@
#include "a_morph.h" #include "a_morph.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "vm.h" #include "vm.h"
#include "d_main.h"
uint8_t globalfreeze, globalchangefreeze; // user's freeze state. uint8_t globalfreeze, globalchangefreeze; // user's freeze state.

View file

@ -38,6 +38,7 @@
#include "events.h" #include "events.h"
#include "actorinlines.h" #include "actorinlines.h"
#include "g_game.h" #include "g_game.h"
#include "i_interface.h"
extern gamestate_t wipegamestate; extern gamestate_t wipegamestate;
extern uint8_t globalfreeze, globalchangefreeze; extern uint8_t globalfreeze, globalchangefreeze;

View file

@ -51,6 +51,7 @@
#include "filesystem.h" #include "filesystem.h"
#include "vm.h" #include "vm.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "d_main.h"
IMPLEMENT_CLASS(DBot, false, true) IMPLEMENT_CLASS(DBot, false, true)

View file

@ -61,6 +61,7 @@
#include "g_levellocals.h" #include "g_levellocals.h"
#include "events.h" #include "events.h"
#include "actorinlines.h" #include "actorinlines.h"
#include "d_main.h"
static FRandom pr_botrespawn ("BotRespawn"); static FRandom pr_botrespawn ("BotRespawn");
static FRandom pr_killmobj ("ActorDie"); static FRandom pr_killmobj ("ActorDie");

View file

@ -65,6 +65,7 @@
#include "g_game.h" #include "g_game.h"
#include "i_system.h" #include "i_system.h"
#include "v_draw.h" #include "v_draw.h"
#include "i_interface.h"
// EXTERNAL DATA DECLARATIONS ---------------------------------------------- // EXTERNAL DATA DECLARATIONS ----------------------------------------------

View file

@ -26,6 +26,7 @@
#include "doomdef.h" #include "doomdef.h"
#include "m_swap.h" #include "m_swap.h"
#include "i_interface.h"
#include "filesystem.h" #include "filesystem.h"
#include "c_console.h" #include "c_console.h"

View file

@ -71,8 +71,6 @@
FBoolCVar noisedebug("noise", false, 0); // [RH] Print sound debugging info? FBoolCVar noisedebug("noise", false, 0); // [RH] Print sound debugging info?
CVAR (Bool, i_soundinbackground, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Bool, i_pauseinbackground, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
static FString LastLocalSndInfo; static FString LastLocalSndInfo;
@ -922,52 +920,6 @@ void S_SerializeSounds(FSerializer &arc)
GSnd->UpdateSounds(); GSnd->UpdateSounds();
} }
//==========================================================================
//
// S_SetSoundPaused
//
// Called with state non-zero when the app is active, zero when it isn't.
//
//==========================================================================
void S_SetSoundPaused(int state)
{
if (!netgame && (i_pauseinbackground)
#ifdef _DEBUG
&& !demoplayback
#endif
)
{
pauseext = !state;
}
if ((state || i_soundinbackground) && !pauseext)
{
if (paused == 0)
{
S_ResumeSound(true);
if (GSnd != nullptr)
{
GSnd->SetInactive(SoundRenderer::INACTIVE_Active);
}
}
}
else
{
if (paused == 0)
{
S_PauseSound(false, true);
if (GSnd != nullptr)
{
GSnd->SetInactive(gamestate == GS_LEVEL || gamestate == GS_TITLELEVEL ?
SoundRenderer::INACTIVE_Complete :
SoundRenderer::INACTIVE_Mute);
}
}
}
}
//========================================================================== //==========================================================================
// //
// CalcSectorSoundOrg // CalcSectorSoundOrg
@ -1475,111 +1427,3 @@ CCMD (loopsound)
} }
} }
//==========================================================================
//
// CCMD cachesound <sound name>
//
//==========================================================================
CCMD (cachesound)
{
if (argv.argc() < 2)
{
Printf ("Usage: cachesound <sound> ...\n");
return;
}
for (int i = 1; i < argv.argc(); ++i)
{
FSoundID sfxnum = argv[i];
if (sfxnum != FSoundID(0))
{
soundEngine->CacheSound(sfxnum);
}
}
}
CCMD(listsoundchannels)
{
Printf("%s", soundEngine->ListSoundChannels().GetChars());
}
// intentionally moved here to keep the s_music include out of the rest of the file.
//==========================================================================
//
// S_PauseSound
//
// Stop music and sound effects, during game PAUSE.
//==========================================================================
#include "s_music.h"
void S_PauseSound (bool notmusic, bool notsfx)
{
if (!notmusic)
{
S_PauseMusic();
}
if (!notsfx)
{
soundEngine->SetPaused(true);
GSnd->SetSfxPaused (true, 0);
}
}
DEFINE_ACTION_FUNCTION(DObject, S_PauseSound)
{
PARAM_PROLOGUE;
PARAM_BOOL(notmusic);
PARAM_BOOL(notsfx);
S_PauseSound(notmusic, notsfx);
return 0;
}
//==========================================================================
//
// S_ResumeSound
//
// Resume music and sound effects, after game PAUSE.
//==========================================================================
void S_ResumeSound (bool notsfx)
{
S_ResumeMusic();
if (!notsfx)
{
soundEngine->SetPaused(false);
GSnd->SetSfxPaused (false, 0);
}
}
DEFINE_ACTION_FUNCTION(DObject, S_ResumeSound)
{
PARAM_PROLOGUE;
PARAM_BOOL(notsfx);
S_ResumeSound(notsfx);
return 0;
}
CCMD (snd_status)
{
GSnd->PrintStatus ();
}
CCMD (snd_reset)
{
S_SoundReset();
}
CCMD (snd_listdrivers)
{
GSnd->PrintDriversList ();
}
ADD_STAT (sound)
{
return GSnd->GatherStats ();
}

View file

@ -34,6 +34,7 @@
#include "po_man.h" #include "po_man.h"
#include "gi.h" #include "gi.h"
#include "c_dispatch.h" #include "c_dispatch.h"
#include "i_interface.h"
#include "g_level.h" #include "g_level.h"
#include "serializer_doom.h" #include "serializer_doom.h"

View file

@ -35,6 +35,7 @@
#include "doomstat.h" #include "doomstat.h"
#include "g_level.h" #include "g_level.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "d_main.h"
EXTERN_CVAR (Bool, ticker); EXTERN_CVAR (Bool, ticker);
EXTERN_CVAR (Bool, noisedebug); EXTERN_CVAR (Bool, noisedebug);