debug_fix_screen_change #2

Merged
xsl merged 35 commits from debug_fix_screen_change into main 2026-04-26 10:58:01 +08:00
4 changed files with 57 additions and 34 deletions
Showing only changes of commit 634d22f3be - Show all commits
+12 -6
View File
@@ -82,7 +82,7 @@ void android_main(struct android_app *pApp) {
auto frameTime = end_time - last_update_time;
last_update_time = end_time;
auto function_time = (end_time - start_time);
aout << "function_time:" << function_time << " fps:" << (1000/frameTime) << std::endl;
//aout << "function_time:" << function_time << " fps:" << (1000/frameTime) << std::endl;
if(function_time < 35)
{
this_thread::sleep_for(chrono::milliseconds((35-function_time)));
@@ -246,7 +246,18 @@ extern "C"
JNIEXPORT jstring JNICALL
Java_com_hmwl_face_1sdk_FaceActivity_PreReadAction(JNIEnv *env, jobject thiz, jstring motion,
jobject callback) {
// 清理旧的全局引用
if (g_callback != nullptr) {
env->DeleteGlobalRef(g_callback);
g_callback = nullptr;
}
// 保存新的回调
if (callback != nullptr) {
g_callback = env->NewGlobalRef(callback);
} else {
g_callback = nullptr;
}
const char *nativeString = env->GetStringUTFChars(motion, nullptr);
jsize len = env->GetStringUTFLength(motion);
@@ -254,12 +265,7 @@ Java_com_hmwl_face_1sdk_FaceActivity_PreReadAction(JNIEnv *env, jobject thiz, js
{
aout << "ArgLen to long:" << len << std::endl;
}
if(g_Application->isInited())
{
g_Application->changeMotion(nativeString);
}
// TODO: implement PreReadAction()
std::string ret = g_Application->preReadyMotion(nativeString, CppCallback);
return env->NewStringUTF(ret.c_str());
}
@@ -282,7 +282,7 @@ public class FaceActivity extends GameActivity implements FaceLandmarkerHelper.L
}
protected native void ChangeStateCpp(String json);
protected void ChangeState(String json){
protected void ChangeMotion(String json){
Log.i("FaceActivity", "ChangeState:" + json);
ChangeStateCpp(json);
}
@@ -291,6 +291,6 @@ public class FaceActivity extends GameActivity implements FaceLandmarkerHelper.L
@Override
public void onEmpty() {
// 当没有检测到人脸时的处理逻辑
Log.d(TAG, "No face detected in the current frame");
//Log.d(TAG, "No face detected in the current frame");
}
}
@@ -9,7 +9,6 @@ import android.widget.Toast
import com.hmwl.face_sdk.FaceActivity
import com.hmwl.face_sdk.InitArg
import com.hmwl.face_sdk.Motion
import org.json.JSONArray
import org.json.JSONObject
import java.io.BufferedReader
import java.io.InputStreamReader
@@ -17,11 +16,11 @@ import java.io.InputStreamReader
class MakeupActivity : FaceActivity()
{
private var curIndex = 0
private var pngFilesByFolder: List<FolderInfo>? = null
override fun onCreate(savedInstanceState: Bundle?) {
FaceInit(this)
val initArg = InitArg().apply {
@@ -34,13 +33,15 @@ class MakeupActivity : FaceActivity()
super.onCreate(savedInstanceState)
var motion = getMotionByIndex(0);
var jsonString = motion.toJson()
val result = PreLoadAction(jsonString) { motion_type ->
// 在这里处理回调结果
println("OnLoadActionFinished: $motion_type")
ChangeState(motion_type);
var motionJsonString = motion.toJson()
val result = PreLoadAction(motionJsonString,object : CallbackInterface {
override fun OnLoadActionFinished(motion_type: String) {
//加载完成后,切断到对应的动画
Log.i("info","加载完成后,切换到对应的动画")
ChangeMotion(motion_type)
}
//Toast.makeText(this, "4.png", Toast.LENGTH_LONG).show()
})
Toast.makeText(this, "开始加载动画: $result", Toast.LENGTH_SHORT).show()
}
private fun getMotionByIndex(index: Int): Motion {
@@ -65,31 +66,45 @@ class MakeupActivity : FaceActivity()
return ""
}
var nextMotionLoadFinished = false
var nextMotionType = ""
override fun onTouchEvent(event: MotionEvent): Boolean {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
Log.d("TouchEvent", "手指按下 - X: ${event.x}, Y: ${event.y}")
if(curIndex == 31)
{
}
}
MotionEvent.ACTION_MOVE -> {
Log.d("TouchEvent", "手指移动 - X: ${event.x}, Y: ${event.y}")
}
MotionEvent.ACTION_UP -> {
Log.d("TouchEvent", "手指抬起")
curIndex++
pngFilesByFolder?.let { folders ->
if (curIndex > folders.size - 1) {
//动画播放完成,切换到主界面
curIndex = 0
Stop();
finish();
}
ChangeState(getCurMotionState(curIndex))
Toast.makeText(this, folders[curIndex].folderName, Toast.LENGTH_LONG).show()
}
}
MotionEvent.ACTION_UP -> {
if (!nextMotionLoadFinished)
{
var nextMotion = getMotionByIndex(curIndex + 1);
var json_str = nextMotion.toJson()
PreLoadAction(json_str,object : CallbackInterface {
override fun OnLoadActionFinished(motion_type: String) {
Log.i("info","加载完成后,还会继续播放当前的动画,可以手动切换动画")
nextMotionLoadFinished = true;
nextMotionType = motion_type;
}
})
Toast.makeText(this, "开始加载下一个动画 ${nextMotion.type}", Toast.LENGTH_SHORT).show()
}
else
{
//手动切换动画
ChangeMotion(nextMotionType);
nextMotionLoadFinished = false;
curIndex++;
Toast.makeText(this, "切换到下一个动画 $nextMotionType", Toast.LENGTH_SHORT).show()
}
}
}
return true
}
+4 -2
View File
@@ -1371,12 +1371,13 @@ void FaceApp::changeMotion(const string motion_type)
std::unique_lock<std::mutex> lock_changeMotion(changeMotionMtx);
for (int i = 0; i < this->m_texs.size(); ++i)
for (int i = 0; i < _nextMotion.png_names.size(); ++i)
{
destroyTexture(device, m_texs[i]);
}
for (int i = 0; i < m_texs_next.size(); ++i)
for (int i = 0; i < _nextMotion.png_names.size(); ++i)
{
m_texs[i] = m_texs_next[i];
m_texs_next[i].reset();
@@ -1385,6 +1386,7 @@ void FaceApp::changeMotion(const string motion_type)
update_descriptor_set(m_texs);
_curMotion_type = motion_type;
_curMotion_png_size = _nextMotion.png_names.size();
_motionState = ready;
// for (int i = 0; i < _curMotion.png_names.size(); ++i)