save code

This commit is contained in:
xsl
2025-12-19 13:47:16 +08:00
parent e38da96e37
commit 6bbbb3c3ef
8 changed files with 137 additions and 102 deletions
+4 -7
View File
@@ -1370,7 +1370,7 @@ void FaceApp::drawFrame(long long frameTime)
// changeMotion(motion);
//}
string FaceApp::preLoadMotionList(const vector<string>& motions, Callback callback)
string FaceApp::preLoadMotionList(string motion_list_str, Callback callback)
{
if (_isLoadMotion)
{
@@ -1379,12 +1379,9 @@ string FaceApp::preLoadMotionList(const vector<string>& motions, Callback callba
_isLoadMotion = true;
_callback_loadfinish = callback;
_preLoadMotions.clear();
for (auto s : motions)
{
json j = json::parse(s);
Motion motion = j.get<Motion>();
_preLoadMotions.push_back(motion);
}
json j = json::parse(motion_list_str);
MotionList motion_list = j.get<MotionList>();
_preLoadMotions = motion_list.motions;
worker_ = std::thread(&FaceApp::loadMotionThread, this);
return "ok";
}
+7 -1
View File
@@ -28,6 +28,12 @@ struct Motion {
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Motion, name, frames)
};
struct MotionList
{
vector<Motion> motions;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MotionList, motions)
};
struct InitArg
{
int action_fps;
@@ -152,7 +158,7 @@ public:
Callback _callback_loadfinish;
AnimationFinishedCallback _animationFinishedCallback;
bool _animationLoop = true;
string preLoadMotionList(const vector<string>& motions, Callback callback);
string preLoadMotionList(string motion_list_str, Callback callback);
vector<Motion>_preLoadMotions;
vector<Motion>_curMotions;
void changeMotionList(AnimationFinishedCallback callback, bool loop);
+5 -4
View File
@@ -140,11 +140,12 @@ int main() {
std::cout << "Warning: Empty motion string" << std::endl;
}
vector<string> s_motions;
json j = motions["4"];
s_motions.push_back(j.dump());
MotionList s_motions;
s_motions.motions.push_back(motions["4"]);
json j = s_motions;
auto s = j.dump();
app.preLoadMotionList(s_motions, CppCallback);
app.preLoadMotionList(s, CppCallback);
app.mainLoop();
//try {
// app.mainLoop();