STARK: Don't always wait for sounds to complete in the menu screens

With this change, changing screens and using widgets feels much more
responsive.
This commit is contained in:
Bastien Bouclet 2018-12-02 06:23:14 +01:00
parent 3c80722658
commit b534956955
5 changed files with 41 additions and 8 deletions

View File

@ -54,7 +54,8 @@ Sound::Sound(Object *parent, byte subType, uint16 index, const Common::String &n
_volume(0),
_fadeDurationRemaining(0),
_fadeTargetVolume(0.0),
_fadeTargetPan(0.0) {
_fadeTargetPan(0.0),
_shouldStopOnDestroy(true) {
_type = TYPE;
}
@ -140,7 +141,10 @@ void Sound::stop() {
void Sound::onPreDestroy() {
Object::onPreDestroy();
stop();
if (_shouldStopOnDestroy) {
stop();
}
}
void Sound::readData(Formats::XRCReadStream *stream) {
@ -255,5 +259,9 @@ void Sound::onEnginePause(bool pause) {
g_system->getMixer()->pauseHandle(_handle, pause);
}
void Sound::setStopOnDestroy(bool stopOnDestroy) {
_shouldStopOnDestroy = stopOnDestroy;
}
} // End of namespace Resources
} // End of namespace Stark

View File

@ -87,6 +87,12 @@ public:
/** Set whether to loop or not */
void setLooping(bool looping) { _looping = looping; }
/**
* In the menus, we don't want sounds to be cut when changing screens.
* The actual sounds need to outlive the entity. This flag allows to do so.
*/
void setStopOnDestroy(bool stopOnDestroy);
protected:
void printData() override;
@ -107,6 +113,7 @@ protected:
uint32 _soundType;
float _pan;
float _volume;
bool _shouldStopOnDestroy;
int32 _fadeDurationRemaining;
float _fadeTargetVolume;

View File

@ -35,6 +35,7 @@
#include "engines/stark/visual/text.h"
#include "audio/mixer.h"
#include "common/system.h"
namespace Stark {
@ -135,6 +136,14 @@ void StaticLocationScreen::onScreenChanged() {
}
}
void StaticLocationScreen::waitForSoundsToComplete() {
while (g_system->getMixer()->hasActiveChannelOfType(Audio::Mixer::kSFXSoundType)) {
StarkGfx->clearScreen();
g_system->delayMillis(10);
StarkGfx->flipBuffer();
}
}
StaticLocationWidget::StaticLocationWidget(const char *renderEntryName, WidgetOnClickCallback *onClickCallback,
WidgetOnMouseMoveCallback *onMouseMoveCallback):
_onClick(onClickCallback),
@ -184,11 +193,7 @@ void StaticLocationWidget::onClick() {
if (_soundMouseClick) {
_soundMouseClick->play();
// Ensure the click sound is played completely
while (_soundMouseClick->isPlaying()) {
g_system->delayMillis(10);
StarkGfx->flipBuffer();
}
_soundMouseClick->setStopOnDestroy(false);
}
if (_onClick) {

View File

@ -46,13 +46,22 @@ class StaticLocationWidget;
class StaticLocationScreen : public SingleWindowScreen {
public:
StaticLocationScreen(Gfx::Driver *gfx, Cursor *cursor, const char *locationName, Screen::Name screenName);
virtual ~StaticLocationScreen();
~StaticLocationScreen() override;
// Screen API
void open() override;
void close() override;
void onScreenChanged() override;
/**
* Wait for all effect sounds to complete
*
* Used to ensure the button press sounds are no longer
* playing before performing the next action that
* would produce a sound.
*/
void waitForSoundsToComplete();
protected:
// Window API
void onMouseMove(const Common::Point &pos) override;

View File

@ -135,11 +135,14 @@ void MainMenuScreen::helpTextHandler(StaticLocationWidget &widget, const Common:
void MainMenuScreen::creditsHandler() {
if (!StarkSettings->isDemo()) {
waitForSoundsToComplete();
StarkUserInterface->requestFMVPlayback("0e02.bbb");
}
}
void MainMenuScreen::newGameHandler() {
waitForSoundsToComplete();
StarkUserInterface->changeScreen(kScreenGame);
StarkResourceProvider->initGlobal();
@ -182,6 +185,7 @@ void MainMenuScreen::boxHandler() {
void MainMenuScreen::quitHandler() {
if (StarkUserInterface->confirm(GameMessage::kQuitPrompt)) {
waitForSoundsToComplete();
StarkUserInterface->notifyShouldExit();
}
}