From c83f36c976d37d4c883ab29b3c56a09922578ed8 Mon Sep 17 00:00:00 2001 From: Xiang Silian Date: Mon, 22 Dec 2025 14:55:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E6=92=AD=E6=94=BE=20=E9=94=99=E8=AF=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vulkan/FaceApp.cpp | 14 +++++++++----- vulkan/FaceApp.h | 4 ++++ vulkan/main.cpp | 31 ++++++++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/vulkan/FaceApp.cpp b/vulkan/FaceApp.cpp index 7f67452..f6e6387 100644 --- a/vulkan/FaceApp.cpp +++ b/vulkan/FaceApp.cpp @@ -692,10 +692,12 @@ void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime) return; } + string curMotionName = _curMotions[_curMotionIndex].name; + int loadMotionIndex = motion_list_map[curMotionName]; //if (cur_left) - { - vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets_left[_curMotionIndex], 0, NULL); - } + //{ + vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets_left[loadMotionIndex], 0, NULL); + //} //else //{ // vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets_right[_curMotionIndex], 0, NULL); @@ -1478,8 +1480,10 @@ void FaceApp::loadMotionThread() string path_name = path + "/" + _loadMotions[i].name + "ex.png"; loadTexture(path_name, pre_texs[i], true, commandPool_ex); #endif // _WIN32 + + motion_list_map[_loadMotions[i].name] = i; } - + update_descriptor_set(m_texs_left, m_descriptor_sets_left); _isLoadMotion = false; _callback_loadfinish(); } @@ -1532,7 +1536,7 @@ void FaceApp::changeMotionList(vector motions, AnimationFinishedCallback //} //else //{ - update_descriptor_set(m_texs_left, m_descriptor_sets_left); + // update_descriptor_set(m_texs_left, m_descriptor_sets_left); // cur_left = true; //} diff --git a/vulkan/FaceApp.h b/vulkan/FaceApp.h index 60886fe..0968f1b 100644 --- a/vulkan/FaceApp.h +++ b/vulkan/FaceApp.h @@ -120,6 +120,10 @@ private: const uint32_t kTextureInit = 1; const uint32_t kTextureMax = 20; vector m_texs_left; + + map motion_list_map; + + //vector m_texs_right; //bool cur_left = true; diff --git a/vulkan/main.cpp b/vulkan/main.cpp index 76715ee..84a3c86 100644 --- a/vulkan/main.cpp +++ b/vulkan/main.cpp @@ -49,7 +49,7 @@ void CppAnimationFinishedCallback() void CppCallback() { - vector motions = {"4", "11", "13"}; + vector motions = {"4"}; g_app->changeMotionList(motions, CppAnimationFinishedCallback, true); } @@ -88,6 +88,27 @@ void loadMotions(const std::string& filePath, std::map& mot } } +bool threadRun = false; + +// 线程要执行的函数 +void threadFunction() { + int startTime = 0; + for (int i = 0; i < 500; ++i) + { + if (!threadRun) + { + break; + } + startTime += 100; + if (startTime == 10 * 1000) + { + vector motions = { "5" }; + g_app->changeMotionList(motions, CppAnimationFinishedCallback, true); + } + std::this_thread::sleep_for(std::chrono::milliseconds(100)); // 暂停200ms + } +} + int main() { @@ -143,13 +164,17 @@ int main() { MotionList s_motions; s_motions.motions.push_back(motions["4"]); - s_motions.motions.push_back(motions["11"]); - s_motions.motions.push_back(motions["13"]); + s_motions.motions.push_back(motions["5"]); + //s_motions.motions.push_back(motions["13"]); json j = s_motions; auto s = j.dump(); app.preLoadMotionList(s, CppCallback); + threadRun = true; + std::thread t(threadFunction); app.mainLoop(); + threadRun = false; + t.join(); //try { // app.mainLoop(); //} catch (const std::exception& e) {