Skip to content

Commit 915c53e

Browse files
committed
Add game pause detection to OpenAL music system
1 parent e1906bf commit 915c53e

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

cl_dll/audio/openal_wav.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,32 @@ void CSoundtrackSystem::Update()
431431
// otherwise: stop
432432
}
433433

434+
void CSoundtrackSystem::PauseMusic()
435+
{
436+
if (m_paused)
437+
return;
438+
439+
ALint state;
440+
alGetSourcei(m_source, AL_SOURCE_STATE, &state);
441+
442+
if (state == AL_PLAYING)
443+
{
444+
m_paused = true;
445+
alSourcePause(m_source);
446+
gEngfuncs.Con_Printf("MUSIC PAUSED\n");
447+
}
448+
}
449+
450+
void CSoundtrackSystem::ResumeMusic()
451+
{
452+
if (!m_paused)
453+
return;
454+
455+
m_paused = false;
456+
alSourcePlay(m_source);
457+
gEngfuncs.Con_Printf("MUSIC RESUMED\n");
458+
}
459+
434460
CON_COMMAND(soundtrack_play, "file.ext [loop]")
435461
{
436462
if (!g_SoundtrackSystem.Init())

cl_dll/audio/openal_wav.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class CSoundtrackSystem
4343
void Shutdown();
4444
void Update();
4545

46+
void PauseMusic();
47+
void ResumeMusic();
48+
4649
void Queue(const std::string& filename, bool loop = false);
4750

4851
ALuint m_source = 0;
@@ -60,6 +63,8 @@ class CSoundtrackSystem
6063
ALCdevice* m_device = nullptr;
6164
ALCcontext* m_context = nullptr;
6265
ALuint m_buffer = 0;
66+
67+
bool m_paused = false;
6368
};
6469

6570
extern CSoundtrackSystem g_SoundtrackSystem;

cl_dll/cl_util.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,6 @@ HSPRITE LoadSprite(const char *pszName);
287287

288288
// frac should always be multiplied by frametime
289289
float lerp(float start, float end, float frac);
290-
double dlerp(double start, double end, double frac);
290+
double dlerp(double start, double end, double frac);
291+
292+
inline bool g_Paused = false;

cl_dll/gameui/gameui_viewport.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ CGameUIViewport::CGameUIViewport() : BaseClass(nullptr, "ClientGameUIViewport")
4747
{
4848
Assert(!m_sInstance);
4949
m_sInstance = this;
50-
5150
vgui2::VPANEL parent = g_pEngineVGui->GetPanel(PANEL_GAMEUIDLL);
5251
SetParent(parent);
5352

cl_dll/view.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "hltv.h"
2323
#include "Exports.h"
2424
#include "Platform.h"
25+
#include "audio/openal_wav.h"
2526
#include <pm_shared.h>
2627

2728

@@ -1275,6 +1276,13 @@ void V_CalcNormalRefdef(struct ref_params_s* pparams)
12751276
}
12761277

12771278
v_origin = pparams->vieworg;
1279+
1280+
g_Paused = pparams->paused != 0;
1281+
1282+
if (g_Paused)
1283+
g_SoundtrackSystem.PauseMusic();
1284+
else
1285+
g_SoundtrackSystem.ResumeMusic();
12781286
}
12791287

12801288
void V_SmoothInterpolateAngles(float* startAngle, float* endAngle, float* finalAngle, float degreesPerSec)

0 commit comments

Comments
 (0)