Commit 8370d66f authored by nanahira's avatar nanahira

Merge branch 'patch-miniaudio' of github.com:Fluorohydride/ygopro into develop

parents df79cc30 21ec8503
...@@ -1313,10 +1313,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -1313,10 +1313,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
//playing custom bgm //playing custom bgm
case 21: { //HINT_MUSIC case 21: { //HINT_MUSIC
if (data) { if (data) {
char textBufferU[1024];
myswprintf(textBuffer, L"./sound/BGM/custom/%ls.mp3", dataManager.GetDesc(data)); myswprintf(textBuffer, L"./sound/BGM/custom/%ls.mp3", dataManager.GetDesc(data));
BufferIO::EncodeUTF8(textBuffer, textBufferU); soundManager.PlayCustomBGM(textBuffer);
soundManager.PlayCustomBGM(textBufferU);
} else { } else {
soundManager.StopBGM(); soundManager.StopBGM();
} }
...@@ -1325,10 +1323,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -1325,10 +1323,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
//playing custom sound effect //playing custom sound effect
case 22: { //HINT_SOUND case 22: { //HINT_SOUND
if (data) { if (data) {
char textBufferU[1024];
myswprintf(textBuffer, L"./sound/custom/%ls.wav", dataManager.GetDesc(data)); myswprintf(textBuffer, L"./sound/custom/%ls.wav", dataManager.GetDesc(data));
BufferIO::EncodeUTF8(textBuffer, textBufferU); soundManager.PlayCustomSound(textBuffer);
soundManager.PlayCustomSound(textBufferU);
} else { } else {
soundManager.StopSound(); soundManager.StopSound();
} }
...@@ -1337,10 +1333,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -1337,10 +1333,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
//playing custom bgm in ogg format //playing custom bgm in ogg format
case 23: { //HINT_MUSIC_OGG case 23: { //HINT_MUSIC_OGG
if (data) { if (data) {
char textBufferU[1024];
myswprintf(textBuffer, L"./sound/BGM/custom/%ls.ogg", dataManager.GetDesc(data)); myswprintf(textBuffer, L"./sound/BGM/custom/%ls.ogg", dataManager.GetDesc(data));
BufferIO::EncodeUTF8(textBuffer, textBufferU); soundManager.PlayCustomBGM(textBuffer);
soundManager.PlayCustomBGM(textBufferU);
} else { } else {
soundManager.StopBGM(); soundManager.StopBGM();
} }
......
...@@ -1934,7 +1934,6 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) { ...@@ -1934,7 +1934,6 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true; return true;
break; break;
} }
#ifdef YGOPRO_USE_AUDIO
case CHECKBOX_ENABLE_MUSIC: { case CHECKBOX_ENABLE_MUSIC: {
if(!mainGame->chkEnableMusic->isChecked()) if(!mainGame->chkEnableMusic->isChecked())
soundManager.StopBGM(); soundManager.StopBGM();
...@@ -1947,7 +1946,6 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) { ...@@ -1947,7 +1946,6 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true; return true;
break; break;
} }
#endif
case CHECKBOX_DISABLE_CHAT: { case CHECKBOX_DISABLE_CHAT: {
bool show = (mainGame->is_building && !mainGame->is_siding) ? false : true; bool show = (mainGame->is_building && !mainGame->is_siding) ? false : true;
mainGame->wChat->setVisible(show); mainGame->wChat->setVisible(show);
...@@ -2053,7 +2051,6 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) { ...@@ -2053,7 +2051,6 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true; return true;
break; break;
} }
#ifdef YGOPRO_USE_AUDIO
case SCROLL_VOLUME: { case SCROLL_VOLUME: {
mainGame->gameConf.sound_volume = (double)mainGame->scrSoundVolume->getPos() / 100; mainGame->gameConf.sound_volume = (double)mainGame->scrSoundVolume->getPos() / 100;
mainGame->gameConf.music_volume = (double)mainGame->scrMusicVolume->getPos() / 100; mainGame->gameConf.music_volume = (double)mainGame->scrMusicVolume->getPos() / 100;
...@@ -2062,7 +2059,6 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) { ...@@ -2062,7 +2059,6 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true; return true;
break; break;
} }
#endif
case SCROLL_TAB_HELPER: { case SCROLL_TAB_HELPER: {
irr::core::rect<irr::s32> pos = mainGame->tabHelper->getRelativePosition(); irr::core::rect<irr::s32> pos = mainGame->tabHelper->getRelativePosition();
mainGame->tabHelper->setRelativePosition(irr::core::recti(0, mainGame->scrTabHelper->getPos() * -1, pos.LowerRightCorner.X, pos.LowerRightCorner.Y)); mainGame->tabHelper->setRelativePosition(irr::core::recti(0, mainGame->scrTabHelper->getPos() * -1, pos.LowerRightCorner.X, pos.LowerRightCorner.Y));
......
...@@ -85,7 +85,7 @@ void SoundManager::RefershBGMDir(std::wstring path, int scene) { ...@@ -85,7 +85,7 @@ void SoundManager::RefershBGMDir(std::wstring path, int scene) {
} }
}); });
} }
void SoundManager::PlaySound(char* sound) { void SoundManager::PlaySound(wchar_t* sound) {
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_AUDIO
if(!mainGame->chkEnableSound->isChecked()) if(!mainGame->chkEnableSound->isChecked())
return; return;
...@@ -111,17 +111,13 @@ void SoundManager::PlaySound(char* sound) { ...@@ -111,17 +111,13 @@ void SoundManager::PlaySound(char* sound) {
usingSoundEffectPointer = playingSoundEffect[0]; usingSoundEffectPointer = playingSoundEffect[0];
ma_sound_uninit(usingSoundEffectPointer); ma_sound_uninit(usingSoundEffectPointer);
} }
#ifdef _WIN32 ma_sound_init_from_file_w(&engineSound, sound, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, usingSoundEffectPointer);
wchar_t sound_w[1024];
BufferIO::DecodeUTF8(sound, sound_w);
ma_sound_init_from_file_w(&engineSound, sound_w, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, usingSoundEffectPointer);
#else
ma_sound_init_from_file(&engineSound, sound, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, usingSoundEffectPointer);
#endif
ma_sound_start(usingSoundEffectPointer); ma_sound_start(usingSoundEffectPointer);
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
engineSound->play2D(sound); char csound[1024];
BufferIO::EncodeUTF8(sound, csound);
engineSound->play2D(csound);
#endif #endif
#endif #endif
} }
...@@ -258,12 +254,13 @@ void SoundManager::PlaySoundEffect(int sound) { ...@@ -258,12 +254,13 @@ void SoundManager::PlaySoundEffect(int sound) {
default: default:
break; break;
} }
char soundPath[40]; wchar_t soundPathW[40];
std::snprintf(soundPath, 40, "./sound/%s.wav", soundName); myswprintf(soundPathW, L"./sound/%s.wav", soundName);
PlaySound(soundPath); PlaySound(soundPathW);
#endif // YGOPRO_USE_AUDIO #endif // YGOPRO_USE_AUDIO
} }
void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) { void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) {
#ifdef YGOPRO_USE_AUDIO
if(element == mainGame->wMessage) { if(element == mainGame->wMessage) {
PlaySoundEffect(SOUND_INFO); PlaySoundEffect(SOUND_INFO);
} else if(element == mainGame->wQuery) { } else if(element == mainGame->wQuery) {
...@@ -285,37 +282,44 @@ void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) { ...@@ -285,37 +282,44 @@ void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) {
} else if(element == mainGame->wFTSelect) { } else if(element == mainGame->wFTSelect) {
PlaySoundEffect(SOUND_QUESTION); PlaySoundEffect(SOUND_QUESTION);
} }
#endif // YGOPRO_USE_AUDIO
} }
bool SoundManager::IsCurrentlyPlaying(char* song) { bool SoundManager::IsPlayingMusic(wchar_t* music) {
#ifdef YGOPRO_USE_MINIAUDIO #ifdef YGOPRO_USE_MINIAUDIO
return currentPlayingMusic[0] && strcmp(currentPlayingMusic, song) == 0 && ma_sound_is_playing(&soundBGM); if(music) {
return !mywcsncasecmp(currentPlayingMusic, music, 1024) && ma_sound_is_playing(&soundBGM);
} else {
return ma_sound_is_playing(&soundBGM);
}
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
return engineMusic->isCurrentlyPlaying(song); if(music) {
char cmusic[1024];
BufferIO::EncodeUTF8(music, cmusic);
return engineMusic->isCurrentlyPlaying(cmusic);
} else {
return soundBGM && !soundBGM->isFinished();
}
#endif #endif
return false; return false;
} }
void SoundManager::PlayMusic(char* song, bool loop) { void SoundManager::PlayMusic(wchar_t* music, bool loop) {
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_AUDIO
if(!mainGame->chkEnableMusic->isChecked()) if(!mainGame->chkEnableMusic->isChecked())
return; return;
if(!IsCurrentlyPlaying(song)) { if(!IsPlayingMusic(music)) {
StopBGM(); StopBGM();
SetMusicVolume(mainGame->gameConf.music_volume); SetMusicVolume(mainGame->gameConf.music_volume);
#ifdef YGOPRO_USE_MINIAUDIO #ifdef YGOPRO_USE_MINIAUDIO
strcpy(currentPlayingMusic, song); BufferIO::CopyWStr(music, currentPlayingMusic, 1024);
#ifdef _WIN32 ma_sound_init_from_file_w(&engineMusic, music, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM);
wchar_t song_w[1024];
BufferIO::DecodeUTF8(song, song_w);
ma_sound_init_from_file_w(&engineMusic, song_w, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM);
#else
ma_sound_init_from_file(&engineMusic, song, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM);
#endif
ma_sound_set_looping(&soundBGM, loop); ma_sound_set_looping(&soundBGM, loop);
ma_sound_start(&soundBGM); ma_sound_start(&soundBGM);
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
soundBGM = engineMusic->play2D(song, loop, false, true); char cmusic[1024];
BufferIO::EncodeUTF8(music, cmusic);
soundBGM = engineMusic->play2D(cmusic, loop, false, true);
#endif #endif
} }
#endif #endif
...@@ -326,28 +330,22 @@ void SoundManager::PlayBGM(int scene) { ...@@ -326,28 +330,22 @@ void SoundManager::PlayBGM(int scene) {
return; return;
if(!mainGame->chkMusicMode->isChecked()) if(!mainGame->chkMusicMode->isChecked())
scene = BGM_ALL; scene = BGM_ALL;
char BGMName[1024]; if((scene != bgm_scene) && (bgm_scene != BGM_CUSTOM) || (scene != previous_bgm_scene) && (bgm_scene == BGM_CUSTOM) || !IsPlayingMusic()) {
#if defined(YGOPRO_USE_MINIAUDIO)
if((scene != bgm_scene) && (bgm_scene != BGM_CUSTOM) || (scene != previous_bgm_scene) && (bgm_scene == BGM_CUSTOM) || !IsCurrentlyPlaying(currentPlayingMusic)) {
#elif defined(YGOPRO_USE_IRRKLANG)
if((scene != bgm_scene) && (bgm_scene != BGM_CUSTOM) || (scene != previous_bgm_scene) && (bgm_scene == BGM_CUSTOM) || (soundBGM && soundBGM->isFinished())) {
#endif
int count = BGMList[scene].size(); int count = BGMList[scene].size();
if(count <= 0) if(count <= 0)
return; return;
bgm_scene = scene; bgm_scene = scene;
int bgm = rnd.get_random_integer(0, count -1); int bgm = rnd.get_random_integer(0, count -1);
auto name = BGMList[scene][bgm].c_str(); auto name = BGMList[scene][bgm].c_str();
wchar_t fname[1024]; wchar_t BGMName[1024];
myswprintf(fname, L"./sound/BGM/%ls", name); myswprintf(BGMName, L"./sound/BGM/%ls", name);
BufferIO::EncodeUTF8(fname, BGMName);
PlayMusic(BGMName, false); PlayMusic(BGMName, false);
} }
#endif #endif
} }
void SoundManager::PlayCustomBGM(char* BGMName) { void SoundManager::PlayCustomBGM(wchar_t* BGMName) {
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_AUDIO
if(!mainGame->chkEnableMusic->isChecked() || !mainGame->chkMusicMode->isChecked() || bgm_process || IsCurrentlyPlaying(BGMName)) if(!mainGame->chkEnableMusic->isChecked() || !mainGame->chkMusicMode->isChecked() || bgm_process || IsPlayingMusic(BGMName))
return; return;
bgm_process = true; bgm_process = true;
int pscene = bgm_scene; int pscene = bgm_scene;
...@@ -358,7 +356,7 @@ void SoundManager::PlayCustomBGM(char* BGMName) { ...@@ -358,7 +356,7 @@ void SoundManager::PlayCustomBGM(char* BGMName) {
bgm_process = false; bgm_process = false;
#endif #endif
} }
void SoundManager::PlayCustomSound(char* SoundName) { void SoundManager::PlayCustomSound(wchar_t* SoundName) {
PlaySound(SoundName); PlaySound(SoundName);
} }
void SoundManager::StopBGM() { void SoundManager::StopBGM() {
......
...@@ -15,8 +15,8 @@ namespace ygo { ...@@ -15,8 +15,8 @@ namespace ygo {
class SoundManager { class SoundManager {
private: private:
std::vector<std::wstring> BGMList[9]; std::vector<std::wstring> BGMList[9];
int bgm_scene; int bgm_scene{};
int previous_bgm_scene; int previous_bgm_scene{};
bool bgm_process; bool bgm_process;
mt19937 rnd; mt19937 rnd;
#ifdef YGOPRO_USE_MINIAUDIO #ifdef YGOPRO_USE_MINIAUDIO
...@@ -28,7 +28,7 @@ private: ...@@ -28,7 +28,7 @@ private:
ma_engine engineSound; ma_engine engineSound;
ma_engine engineMusic; ma_engine engineMusic;
ma_sound soundBGM; ma_sound soundBGM;
char currentPlayingMusic[1024]{}; wchar_t currentPlayingMusic[1024]{};
ma_sound* playingSoundEffect[10]{}; ma_sound* playingSoundEffect[10]{};
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
...@@ -41,14 +41,14 @@ private: ...@@ -41,14 +41,14 @@ private:
public: public:
bool Init(); bool Init();
void RefreshBGMList(); void RefreshBGMList();
void PlaySound(char* sound); void PlaySound(wchar_t* sound);
void PlaySoundEffect(int sound); void PlaySoundEffect(int sound);
void PlayDialogSound(irr::gui::IGUIElement * element); void PlayDialogSound(irr::gui::IGUIElement * element);
bool IsCurrentlyPlaying(char* song); bool IsPlayingMusic(wchar_t* music = 0);
void PlayMusic(char* song, bool loop); void PlayMusic(wchar_t* music, bool loop);
void PlayBGM(int scene); void PlayBGM(int scene);
void PlayCustomBGM(char* BGMName); void PlayCustomBGM(wchar_t* BGMName);
void PlayCustomSound(char* SoundName); void PlayCustomSound(wchar_t* SoundName);
void StopBGM(); void StopBGM();
void StopSound(); void StopSound();
void SetSoundVolume(double volume); void SetSoundVolume(double volume);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment