基本调通 回调

This commit is contained in:
xsl
2025-11-29 23:44:22 +08:00
parent 1859706412
commit 835f768a4a
8 changed files with 311 additions and 76 deletions
+119 -46
View File
@@ -567,7 +567,11 @@ void FaceApp::setup_descriptor_set()
alloc_info.pSetLayouts = layouts.data();
alloc_info.descriptorSetCount = m_descriptor_sets.size();
VK_CHECK(vkAllocateDescriptorSets(device, &alloc_info, m_descriptor_sets.data()));
update_descriptor_set(m_texs);
}
void FaceApp::update_descriptor_set(vector<Texture>& texs)
{
for (int i = 0; i < kMaxTexture; ++i)
{
VkDescriptorBufferInfo buffer_descriptor{};
@@ -577,9 +581,9 @@ void FaceApp::setup_descriptor_set()
VkDescriptorImageInfo image_descriptor;
image_descriptor.imageView = m_texs[i].view;
image_descriptor.sampler = m_texs[i].sampler;
image_descriptor.imageLayout = m_texs[i].image_layout;
image_descriptor.imageView = texs[i].view;
image_descriptor.sampler = texs[i].sampler;
image_descriptor.imageLayout = texs[i].image_layout;
VkWriteDescriptorSet write_descriptor_set_uniform{};
write_descriptor_set_uniform.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
@@ -635,17 +639,7 @@ void FaceApp::setup_descriptor_set()
vkUpdateDescriptorSets(device, static_cast<uint32_t>(write_descriptor_sets.size()), write_descriptor_sets.data(), 0, NULL);
}
}
}
void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime)
@@ -718,6 +712,7 @@ void FaceApp::initVulkan()
createVmaAllocator();
LoadOBJ("face_picture_3dmax.obj", obj_vertices, obj_indices);
m_texs.resize(kMaxTexture);
m_texs_next.resize(kMaxTexture);
if (kThick)
{
m_texs_ex.resize(kMaxTexture);
@@ -731,6 +726,7 @@ void FaceApp::initVulkan()
for (int i = 0; i < kMaxTexture; ++i)
{
loadTexture(image, image.size(), w, h, m_texs[i], true);
loadTexture(image, image.size(), w, h, m_texs_next[i], true);
if (kThick)
{
loadTexture(image, image.size(), w, h, m_texs_ex[i], true);
@@ -753,7 +749,7 @@ void FaceApp::initVulkan()
uploadVertexData();
last_update_time = getCurrentTimeMillis();
changeMotion(_initArg.motion);
//changeMotion(_initArg.motion);
_running = true;
faceAppInited = true;
#if _WIN32
@@ -1153,11 +1149,13 @@ void FaceApp::destroyTexture(VkDevice device, Texture& texture) {
if (texture.stagingBuffer != VK_NULL_HANDLE)
{
vkDestroyBuffer(device, texture.stagingBuffer, nullptr);
texture.stagingBuffer = VK_NULL_HANDLE;
}
if (texture.stagingBufferMemory != VK_NULL_HANDLE)
{
vkFreeMemory(device, texture.stagingBufferMemory, nullptr);
texture.stagingBufferMemory = VK_NULL_HANDLE;
}
}
@@ -1261,6 +1259,11 @@ void FaceApp::cleanup()
destroyTexture(device, m_texs[i]);
}
for (int i = 0; i < this->m_texs_next.size(); ++i)
{
destroyTexture(device, m_texs_next[i]);
}
destroyTexture(device, tex_bg);
vkDestroyCommandPool(device, commandPool, nullptr);
Application::cleanup();
@@ -1284,6 +1287,32 @@ void FaceApp::drawFrame(long long frameTime)
return;
}
if (_motionState == loading_next_motion)
{
int i = _nextMotionIndex;
//for (int i = 0; i < _curMotion.png_names.size(); ++i)
{
#ifdef _WIN32
string path = "pic";
string path_name = path + "/" + _nextMotion.type + "/" + _nextMotion.png_names[i];// +std::to_string(i) + ".png";
loadTextureExample(UTF8ToWideString(path_name), m_texs_next[i], true);
#else
//string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
string path = "pic";
string path_name = path + "/" + _nextMotion.type + "/" + _nextMotion.png_names[i];// +std::to_string(i) + ".png";
loadTexture(path_name, m_texs_next[i], true);
#endif // _WIN32
_nextMotionIndex++;
if (_nextMotionIndex >= _nextMotion.png_names.size())
{
_motionState = load_next_motion_finished;
_callback(_nextMotion.type);
}
}
}
std::unique_lock lock(changeMotionMtx);
static long long game_time = 0;
game_time += frameTime;
@@ -1291,7 +1320,7 @@ void FaceApp::drawFrame(long long frameTime)
if (game_time > actionTime)
{
_curTexIndex++;
if (_curTexIndex >= _curMotion.png_names.size())
if (_curTexIndex >= _curMotion_png_size)
{
_curTexIndex = 0;
}
@@ -1300,44 +1329,88 @@ void FaceApp::drawFrame(long long frameTime)
Application::drawFrame(frameTime);
}
void FaceApp::changeMotion(const char* json)
//void FaceApp::changeMotion(const char* motion_type)
//{
// //Motion motion = json::parse(json);
// changeMotion(motion);
//}
string FaceApp::preReadyMotion(const std::string& json, Callback callback)
{
Motion motion = json::parse(json);
changeMotion(motion);
if (_motionState == loading_next_motion)
{
return "busy on loading:" + _nextMotion.type;
}
else if (_motionState == load_next_motion_finished)
{
return "waitting change next action:" + _nextMotion.type;
}
else if (_motionState == ready)
{
Motion motion = json::parse(json);
_nextMotion = motion;
_motionState = loading_next_motion;
_nextMotionIndex = 0;
_callback = callback;
return "success";
}
return "failure";
}
void FaceApp::changeMotion(Motion& motion)
void FaceApp::changeMotion(const string motion_type)
{
if (_curMotion.getMotionId() == motion.getMotionId())
if (_curMotion_type == motion_type)
{
return;
}
std::unique_lock<std::mutex> lock_changeMotion(changeMotionMtx);
_curMotion = motion;
for (int i = 0; i < _curMotion.png_names.size(); ++i)
if (_motionState != load_next_motion_finished)
{
#ifdef _WIN32
//string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
string path = "pic";
string path_name = path + "/" + _curMotion.type + "/" + _curMotion.png_names[i];// +std::to_string(i) + ".png";
loadTextureExample(UTF8ToWideString(path_name), m_texs[i], true);
if (kThick)
{
string path_name_ex = path + "/" + _curMotion.type + "/" + _curMotion.png_names[i] + std::to_string(i) + "_thick.png";
loadTextureExample(UTF8ToWideString(path_name_ex), m_texs_ex[i], true);
}
#else
//string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
string path = "pic";
string path_name = path + "/" + _curMotion.type + "/" + _curMotion.png_names[i];// +std::to_string(i) + ".png";
loadTexture(path_name, m_texs[i], true);
if (kThick)
{
loadTexture(path_name, m_texs_ex[i], true);
}
#endif // _WIN32
return;
}
std::unique_lock<std::mutex> lock_changeMotion(changeMotionMtx);
for (int i = 0; i < this->m_texs.size(); ++i)
{
destroyTexture(device, m_texs[i]);
}
for (int i = 0; i < m_texs_next.size(); ++i)
{
m_texs[i] = m_texs_next[i];
m_texs_next[i].reset();
}
update_descriptor_set(m_texs);
_curMotion_type = motion_type;
_curMotion_png_size = _nextMotion.png_names.size();
// for (int i = 0; i < _curMotion.png_names.size(); ++i)
// {
//
//#ifdef _WIN32
// //string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
// string path = "pic";
// string path_name = path + "/" + _curMotion.type + "/" + _curMotion.png_names[i];// +std::to_string(i) + ".png";
// loadTextureExample(UTF8ToWideString(path_name), m_texs[i], true);
// if (kThick)
// {
// string path_name_ex = path + "/" + _curMotion.type + "/" + _curMotion.png_names[i] + std::to_string(i) + "_thick.png";
// loadTextureExample(UTF8ToWideString(path_name_ex), m_texs_ex[i], true);
// }
//#else
// //string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
// string path = "pic";
// string path_name = path + "/" + _curMotion.type + "/" + _curMotion.png_names[i];// +std::to_string(i) + ".png";
// loadTexture(path_name, m_texs[i], true);
// if (kThick)
// {
// loadTexture(path_name, m_texs_ex[i], true);
// }
//#endif // _WIN32
//
//
// }
}