Skip to content

Commit

Permalink
Handle BGM Fade through Game_System and always force a BGM Play after…
Browse files Browse the repository at this point in the history
… a fadeout otherwise this playing the same BGM again won't work.

Fix #1354
  • Loading branch information
Ghabry committed May 6, 2018
1 parent bb9cfaf commit b994ddc
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/game_interpreter.cpp
Expand Up @@ -1478,7 +1478,7 @@ bool Game_Interpreter::CommandPlayBGM(RPG::EventCommand const& com) { // code 11

bool Game_Interpreter::CommandFadeOutBGM(RPG::EventCommand const& com) { // code 11520
int fadeout = com.parameters[0];
Audio().BGM_Fade(fadeout);
Game_System::BgmFade(fadeout);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game_interpreter_map.cpp
Expand Up @@ -492,7 +492,7 @@ bool Game_Interpreter_Map::ContinuationShowInnStart(RPG::EventCommand const& /*
actor->RemoveAllStates();
}
Graphics::Transition(Graphics::TransitionFadeOut, 36, true);
Audio().BGM_Fade(800);
Game_System::BgmFade(800);
SetContinuation(static_cast<ContinuationFunction>(&Game_Interpreter_Map::ContinuationShowInnContinue));
return false;
}
Expand Down
11 changes: 10 additions & 1 deletion src/game_system.cpp
Expand Up @@ -34,6 +34,8 @@
namespace {
FileRequestBinding music_request_id;
std::map<std::string, FileRequestBinding> se_request_ids;
/** When true (BgmFade called) always forces a BGM_Play even when the same music is used */
bool force_bgm_play = false;

/**
* Determines if the requested file is supposed to Stop BGM/SE play.
Expand Down Expand Up @@ -101,7 +103,7 @@ void Game_System::BgmPlay(RPG::Music const& bgm) {
// (OFF) means play nothing
if (!bgm.name.empty() && bgm.name != "(OFF)") {
// Same music: Only adjust volume and speed
if (previous_music.name == bgm.name) {
if (!force_bgm_play && previous_music.name == bgm.name) {
if (previous_music.volume != data.current_music.volume) {
if (!bgm_pending) { // Delay if not ready
Audio().BGM_Volume(data.current_music.volume);
Expand All @@ -122,6 +124,8 @@ void Game_System::BgmPlay(RPG::Music const& bgm) {
} else {
BgmStop();
}

force_bgm_play = false;
}

void Game_System::BgmStop() {
Expand All @@ -130,6 +134,11 @@ void Game_System::BgmStop() {
Audio().BGM_Stop();
}

void Game_System::BgmFade(int duration) {
Audio().BGM_Fade(duration);
force_bgm_play = true;
}

void Game_System::SePlay(RPG::Sound const& se) {
static bool ineluki_warning_shown = false;

Expand Down
7 changes: 7 additions & 0 deletions src/game_system.h
Expand Up @@ -106,6 +106,13 @@ namespace Game_System {
*/
void BgmStop();

/**
* Fades out the current BGM
*
* @param duration Duration in ms
*/
void BgmFade(int duration);

/**
* Plays a Sound.
*
Expand Down
2 changes: 1 addition & 1 deletion src/player.cpp
Expand Up @@ -297,7 +297,7 @@ void Player::Update(bool update_scene) {
if (Scene::Find(Scene::Title) && Scene::instance->type != Scene::Title) {
Scene::PopUntil(Scene::Title);
// Fade out music and stop sound effects before returning
Audio().BGM_Fade(800);
Game_System::BgmFade(800);
Audio().SE_Stop();
// Do not update this scene until it's properly set up in the next main loop
update_scene = false;
Expand Down
2 changes: 1 addition & 1 deletion src/scene_end.cpp
Expand Up @@ -47,7 +47,7 @@ void Scene_End::Update() {
Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Decision));
switch (command_window->GetIndex()) {
case 0: // Yes
Audio().BGM_Fade(800);
Game_System::BgmFade(800);
Scene::PopUntil(Scene::Title);
break;
case 1: // No
Expand Down
1 change: 0 additions & 1 deletion src/scene_gamebrowser.cpp
Expand Up @@ -50,7 +50,6 @@ void Scene_GameBrowser::Continue() {
#ifdef _WIN32
SetCurrentDirectory(L"..");
#endif
Audio().BGM_Fade(800);

Main_Data::SetProjectPath(browser_dir);

Expand Down

0 comments on commit b994ddc

Please sign in to comment.