Pause audio when the pause menu is opened
This commit is contained in:
parent
9c161d74a2
commit
86ade0b0ab
|
@ -13,6 +13,7 @@ ALSndPlayer gSoundPlayer;
|
|||
#define SOUND_FLAGS_3D (1 << 0)
|
||||
#define SOUND_FLAGS_LOOPING (1 << 1)
|
||||
#define SOUND_HAS_STARTED (1 << 2)
|
||||
#define SOUND_FLAGS_PAUSED (1 << 3)
|
||||
|
||||
#define SPEED_OF_SOUND 343.2f
|
||||
|
||||
|
@ -201,6 +202,12 @@ void soundPlayerUpdate() {
|
|||
while (index < gActiveSoundCount) {
|
||||
struct ActiveSound* sound = &gActiveSounds[index];
|
||||
|
||||
if (sound->flags & SOUND_FLAGS_PAUSED) {
|
||||
++writeIndex;
|
||||
++index;
|
||||
continue;
|
||||
}
|
||||
|
||||
sound->estimatedTimeLeft -= FIXED_DELTA_TIME;
|
||||
|
||||
alSndpSetSound(&gSoundPlayer, sound->soundId);
|
||||
|
@ -322,4 +329,30 @@ void soundListenerUpdate(struct Vector3* position, struct Quaternion* rotation,
|
|||
|
||||
void soundListenerSetCount(int count) {
|
||||
gActiveListenerCount = count;
|
||||
}
|
||||
|
||||
void soundPlayerPause() {
|
||||
for (int i = 0; i < gActiveSoundCount; ++i) {
|
||||
struct ActiveSound* activeSound = &gActiveSounds[i];
|
||||
if (activeSound->soundId != SOUND_ID_NONE) {
|
||||
activeSound->flags |= SOUND_FLAGS_PAUSED;
|
||||
|
||||
alSndpSetSound(&gSoundPlayer, activeSound->soundId);
|
||||
alSndpSetPitch(&gSoundPlayer, 0.0f);
|
||||
alSndpSetVol(&gSoundPlayer, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void soundPlayerResume() {
|
||||
for (int i = 0; i < gActiveSoundCount; ++i) {
|
||||
struct ActiveSound* activeSound = &gActiveSounds[i];
|
||||
if (activeSound->flags & SOUND_FLAGS_PAUSED) {
|
||||
activeSound->flags &= ~SOUND_FLAGS_PAUSED;
|
||||
|
||||
alSndpSetSound(&gSoundPlayer, activeSound->soundId);
|
||||
alSndpSetPitch(&gSoundPlayer, activeSound->basePitch);
|
||||
alSndpSetVol(&gSoundPlayer, (short)(32767 * activeSound->volume));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,6 +24,9 @@ ALSndId soundPlayerPlay(int soundClipId, float volume, float pitch, struct Vecto
|
|||
void soundPlayerStop(ALSndId soundId);
|
||||
void soundPlayerStopAll();
|
||||
|
||||
void soundPlayerPause();
|
||||
void soundPlayerResume();
|
||||
|
||||
void soundPlayerUpdatePosition(ALSndId soundId, struct Vector3* at, struct Vector3* velocity);
|
||||
void soundPlayerAdjustVolume(ALSndId soundId, float newVolume);
|
||||
|
||||
|
|
|
@ -108,6 +108,8 @@ void sceneInitNoPauseMenu(struct Scene* scene) {
|
|||
scene->camera.transform.rotation = scene->player.lookTransform.rotation;
|
||||
scene->camera.transform.position = scene->player.lookTransform.position;
|
||||
|
||||
sceneUpdateListeners(scene);
|
||||
|
||||
if (gCurrentLevelIndex >= LEVEL_INDEX_WITH_GUN_0) {
|
||||
playerGivePortalGun(&scene->player, PlayerHasFirstPortalGun);
|
||||
}
|
||||
|
@ -480,6 +482,10 @@ void sceneUpdate(struct Scene* scene) {
|
|||
gGameMenu.state = GameMenuStateResumeGame;
|
||||
}
|
||||
|
||||
if (gGameMenu.state == GameMenuStateResumeGame) {
|
||||
soundPlayerResume();
|
||||
}
|
||||
|
||||
if (gGameMenu.state == GameMenuStateQuit) {
|
||||
levelQueueLoad(MAIN_MENU, NULL, NULL);
|
||||
return;
|
||||
|
@ -490,6 +496,7 @@ void sceneUpdate(struct Scene* scene) {
|
|||
savefileGrabScreenshot();
|
||||
gGameMenu.state = GameMenuStateLanding;
|
||||
gGameMenu.landingMenu.selectedItem = 0;
|
||||
soundPlayerPause();
|
||||
}
|
||||
|
||||
signalsReset();
|
||||
|
|
Loading…
Reference in a new issue