Skip to content
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

Merged

Conversation

PatriceJiang
Copy link
Contributor

@PatriceJiang PatriceJiang commented Jan 18, 2022

Comment on lines +142 to +147
List<Runnable> tmp = sTaskOnGameThread;
synchronized (sTaskMtx) {
sTaskOnGameThread = Collections.synchronizedList(new ArrayList<>());
}
while (tmp.size() > 0) {
Runnable r = tmp.remove(0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

避免循环中修改队列, 修复潜在无法退出的问题

runOnGameThread(()-> {
  ...
  runOnGameThread(()->{..});
...
});

Comment on lines +130 to +136
List<Runnable> tmp = sTaskOnGameThread;
synchronized (sTaskMtx) {
sTaskOnGameThread = Collections.synchronizedList(new ArrayList<>());
}
while (tmp.size() > 0) {
Runnable r = tmp.remove(0);
if (r != null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

@PatriceJiang PatriceJiang changed the title 3.4.1 fix flush game thread tasks 3.4.1 Flush game thread tasks Jan 19, 2022
@PatriceJiang PatriceJiang changed the title 3.4.1 Flush game thread tasks 3.4.1 Android: Java flush game thread tasks Jan 19, 2022
Comment on lines +166 to +171
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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

降低延迟

@pandamicro pandamicro merged commit 936e49e into cocos:v3.4.1 Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants