From 56de9ea6496d35a26b1b77ff4ab2f2084a5e4c48 Mon Sep 17 00:00:00 2001 From: XProger Date: Sat, 24 Nov 2018 06:55:05 +0300 Subject: [PATCH] pause game sounds in then inventory menu and while video playing --- src/camera.h | 3 +++ src/inventory.h | 13 +++++++++++++ src/sound.h | 17 +++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/camera.h b/src/camera.h index d24b58b..a0cd50d 100644 --- a/src/camera.h +++ b/src/camera.h @@ -38,6 +38,9 @@ struct Camera : ICamera { } void reset() { + Sound::listener[cameraIndex].matrix.identity(); + Sound::listener[cameraIndex].matrix.translate(vec3(0x7FFFFFFF)); + lookAngle = vec3(0.0f); changeView(false); diff --git a/src/inventory.h b/src/inventory.h index 56847cc..c3c623e 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -683,6 +683,7 @@ struct Inventory { } void startVideo() { + applySounds(true); new Stream(playVideo ? TR::getGameVideo(game->getLevel()->id) : NULL, loadVideo, this); } @@ -826,6 +827,15 @@ struct Inventory { return false; } + void applySounds(bool pause) { + for (int i = 0; i < Sound::channelsCount; i++) + if (Sound::channels[i]->flags & Sound::PAN) + if (pause) + Sound::channels[i]->pause(); + else + Sound::channels[i]->resume(); + } + void toggle(int playerIndex = 0, Page curPage = PAGE_INVENTORY, TR::Entity::Type type = TR::Entity::NONE) { if (titleTimer != 0.0f || (isActive() != active)) return; @@ -839,6 +849,8 @@ struct Inventory { active = !active; vec3 p; + applySounds(active); + if (curPage == PAGE_SAVEGAME) { phaseRing = active ? 1.0f : 0.0f; slot = 1; @@ -1075,6 +1087,7 @@ struct Inventory { toggle(0, Inventory::PAGE_OPTION); } Input::reset(); + applySounds(false); } void update() { diff --git a/src/sound.h b/src/sound.h index 635a165..bd0a5d4 100644 --- a/src/sound.h +++ b/src/sound.h @@ -706,10 +706,12 @@ namespace Sound { int flags; int id; bool isPlaying; + bool isPaused; bool stopAfterFade; Sample(Decoder *decoder, float volume, float pitch, int flags, int id) : uniquePtr(NULL), decoder(decoder), volume(volume), volumeTarget(volume), volumeDelta(0.0f), pitch(pitch), flags(flags), id(id) { isPlaying = decoder != NULL; + isPaused = false; } Sample(Stream *stream, const vec3 *pos, float volume, float pitch, int flags, int id) : uniquePtr(pos), decoder(NULL), volume(volume), volumeTarget(volume), volumeDelta(0.0f), pitch(pitch), flags(flags), id(id) { @@ -771,6 +773,7 @@ namespace Sound { delete stream; isPlaying = decoder != NULL; + isPaused = false; } ~Sample() { @@ -807,6 +810,12 @@ namespace Sound { bool render(Frame *frames, int count) { if (!isPlaying) return false; + + if (isPaused) { + memset(frames, 0, sizeof(Frame) * count); + return true; + } + // decode int i = 0; while (i < count) { @@ -855,6 +864,14 @@ namespace Sound { void replay() { decoder->replay(); } + + void pause() { + isPaused = true; + } + + void resume() { + isPaused = false; + } } *channels[SND_CHANNELS_MAX]; int channelsCount;