New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.4.1 Android: Java flush game thread tasks #4193
3.4.1 Android: Java flush game thread tasks #4193
Conversation
List<Runnable> tmp = sTaskOnGameThread; | ||
synchronized (sTaskMtx) { | ||
sTaskOnGameThread = Collections.synchronizedList(new ArrayList<>()); | ||
} | ||
while (tmp.size() > 0) { | ||
Runnable r = tmp.remove(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
避免循环中修改队列, 修复潜在无法退出的问题
runOnGameThread(()-> {
...
runOnGameThread(()->{..});
...
});
List<Runnable> tmp = sTaskOnGameThread; | ||
synchronized (sTaskMtx) { | ||
sTaskOnGameThread = Collections.synchronizedList(new ArrayList<>()); | ||
} | ||
while (tmp.size() > 0) { | ||
Runnable r = tmp.remove(0); | ||
if (r != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
if(game) { | ||
// Handle java events send by UI thread. Input events are handled here too. | ||
cc::JniHelper::callStaticVoidMethod("com.cocos.lib.CocosHelper", | ||
"flushTasksOnGameThread"); | ||
} | ||
if (game && cc::cocosApp.animating) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
后台继续执行 runOnGameThread 任务, 不再执行 gameTick
. 和 2.x 保持一致
runInLowRate = !cc::cocosApp.animating || APP_CMD_PAUSE == cc::cocosApp.appState; | ||
|
||
if (readCommandWithTimeout(cmd, runInLowRate ? 100 : 0) > 0) { | ||
if (readCommandWithTimeout(cmd, runInLowRate ? 50 : 0) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
降低延迟
runInLowRate = !cc::cocosApp.animating || APP_CMD_PAUSE == cc::cocosApp.appState; | ||
|
||
if (readCommandWithTimeout(cmd, runInLowRate ? 100 : 0) > 0) { | ||
if (readCommandWithTimeout(cmd, runInLowRate ? 50 : 0) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
降低延迟
ref: https://github.com/cocos-creator/3d-tasks/issues/10902