Commit e337da72 authored by mercury233's avatar mercury233

Revert "less conversion"

This reverts commit 15687a2c.
parent 15687a2c
...@@ -250,35 +250,37 @@ void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) { ...@@ -250,35 +250,37 @@ void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) {
PlaySoundEffect(SOUND_QUESTION); PlaySoundEffect(SOUND_QUESTION);
} }
} }
bool SoundManager::IsCurrentlyPlaying(wchar_t* music) { bool SoundManager::IsCurrentlyPlaying(char* song) {
#ifdef YGOPRO_USE_MINIAUDIO #ifdef YGOPRO_USE_MINIAUDIO
return currentPlayingMusic[0] && !mywcsncasecmp(currentPlayingMusic, music, 1024) && ma_sound_is_playing(&soundBGM); return currentPlayingMusic[0] && strcmp(currentPlayingMusic, song) == 0 && ma_sound_is_playing(&soundBGM);
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
char cmusic[1024]; return engineMusic->isCurrentlyPlaying(song);
BufferIO::EncodeUTF8(music, cmusic);
return engineMusic->isCurrentlyPlaying(cmusic);
#endif #endif
return false; return false;
} }
void SoundManager::PlayMusic(wchar_t* music, bool loop) { void SoundManager::PlayMusic(char* song, bool loop) {
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_AUDIO
if(!mainGame->chkEnableMusic->isChecked()) if(!mainGame->chkEnableMusic->isChecked())
return; return;
if(!IsCurrentlyPlaying(music)) { if(!IsCurrentlyPlaying(song)) {
StopBGM(); StopBGM();
#ifdef YGOPRO_USE_MINIAUDIO #ifdef YGOPRO_USE_MINIAUDIO
BufferIO::CopyWStr(music, currentPlayingMusic, 1024); strcpy(currentPlayingMusic, song);
ma_sound_init_from_file_w(&engineMusic, music, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM); #ifdef _WIN32
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
engineMusic->stopAllSounds(); engineMusic->stopAllSounds();
engineMusic->setSoundVolume(mainGame->gameConf.music_volume); engineMusic->setSoundVolume(mainGame->gameConf.music_volume);
char cmusic[1024]; soundBGM = engineMusic->play2D(song, loop, false, true);
BufferIO::EncodeUTF8(music, cmusic);
soundBGM = engineMusic->play2D(cmusic, loop, false, true);
#endif #endif
} }
#endif #endif
...@@ -289,6 +291,7 @@ void SoundManager::PlayBGM(int scene) { ...@@ -289,6 +291,7 @@ 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 defined(YGOPRO_USE_MINIAUDIO) #if defined(YGOPRO_USE_MINIAUDIO)
if(scene != bgm_scene || !IsCurrentlyPlaying(currentPlayingMusic)) { if(scene != bgm_scene || !IsCurrentlyPlaying(currentPlayingMusic)) {
#elif defined(YGOPRO_USE_IRRKLANG) #elif defined(YGOPRO_USE_IRRKLANG)
...@@ -300,8 +303,9 @@ void SoundManager::PlayBGM(int scene) { ...@@ -300,8 +303,9 @@ void SoundManager::PlayBGM(int scene) {
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 BGMName[1024]; wchar_t fname[1024];
myswprintf(BGMName, L"./sound/BGM/%ls", name); myswprintf(fname, L"./sound/BGM/%ls", name);
BufferIO::EncodeUTF8(fname, BGMName);
PlayMusic(BGMName, false); PlayMusic(BGMName, false);
} }
#endif #endif
......
...@@ -26,7 +26,7 @@ private: ...@@ -26,7 +26,7 @@ private:
ma_engine engineSound; ma_engine engineSound;
ma_engine engineMusic; ma_engine engineMusic;
ma_sound soundBGM; ma_sound soundBGM;
wchar_t currentPlayingMusic[1024]{}; char currentPlayingMusic[1024]{};
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
irrklang::ISoundEngine* engineSound; irrklang::ISoundEngine* engineSound;
...@@ -40,8 +40,8 @@ public: ...@@ -40,8 +40,8 @@ public:
void RefreshBGMList(); void RefreshBGMList();
void PlaySoundEffect(int sound); void PlaySoundEffect(int sound);
void PlayDialogSound(irr::gui::IGUIElement * element); void PlayDialogSound(irr::gui::IGUIElement * element);
bool IsCurrentlyPlaying(wchar_t* music); bool IsCurrentlyPlaying(char* song);
void PlayMusic(wchar_t* music, bool loop); void PlayMusic(char* song, bool loop);
void PlayBGM(int scene); void PlayBGM(int scene);
void StopBGM(); void StopBGM();
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