Skip to content

Commit

Permalink
将音频播放挪至新线程运行
Browse files Browse the repository at this point in the history
  • Loading branch information
HalcyonAlcedo committed Sep 20, 2021
1 parent ac3986e commit 9d9327c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 1 addition & 8 deletions Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,7 @@ namespace Base {
//音频播放
#pragma region SoundPlay
namespace SoundPlay {
static void PlaySoundFile(string SoundFile) {
Player* player = new Player();
Sound* sound = new Sound();
player->Create();
sound->LoadFromFile(SoundFile);
player->SetSound(*sound);
player->Play();
}
vector<string> SoundList;
}
#pragma endregion
//委托
Expand Down
16 changes: 16 additions & 0 deletions ControlProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ namespace ControlProgram {
};
map<string, TextureCache> ImgTextureCache;

static void PlaySoundFile(string SoundFile) {
Player* player = new Player();
Sound* sound = new Sound();
player->Create();
sound->LoadFromFile(SoundFile);
player->SetSound(*sound);
player->Play();
}

void InitImGui()
{
ImGui::CreateContext();
Expand Down Expand Up @@ -180,6 +189,12 @@ namespace ControlProgram {
Checkhotkey[(string)ImHotKey::hotkeys.at(hotkey).functionName] = true;
}

//声音处理
if (!Base::SoundPlay::SoundList.empty()) {
PlaySoundFile(Base::SoundPlay::SoundList.back());
Base::SoundPlay::SoundList.pop_back();
}

ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
Expand Down Expand Up @@ -554,4 +569,5 @@ namespace ControlProgram {
initConsole = true;
CreateThread(nullptr, 0, MainThread, hMod, 0, nullptr);
}

}
2 changes: 1 addition & 1 deletion LuaScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ static int System_UI_GetGameWindowSize(lua_State* pL) {
}
static int System_Sound_PlaySound(lua_State* pL) {
string file = (string)lua_tostring(pL, 1);
Base::SoundPlay::PlaySoundFile(file);
Base::SoundPlay::SoundList.push_back(file);
return 0;
}
static int System_GetProcessList(lua_State* pL)
Expand Down

0 comments on commit 9d9327c

Please sign in to comment.