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

fix subContextView.update() bug #4721

Merged
merged 5 commits into from Jun 28, 2019

Conversation

@umbrellaPP
Copy link
Contributor

commented Jun 26, 2019

Re: cocos-creator/2d-tasks#1504

changeLog:

  • 修复 subContextView.update() 无法更新子域贴图的问题

每次 update 通知子域执行一次 cc.game.step()

关联pr:
cocos-creator-packages/weapp-adapter#104
cocos-creator-packages/baidu-adapter#19

// Resume animation
cc.director.startAnimation();
// To get the correct deltaTime
cc.director.resetLateUpdate();

This comment has been minimized.

Copy link
@umbrellaPP

umbrellaPP Jun 26, 2019

Author Contributor

之前加 startAnimation() 是为了更新 cc.direcotr._lateUpdate
但是不应该影响 cc.director.invalid,会造成 cc.game.step() 调用无效

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jun 28, 2019

Member

stopAnimation 的意义就是停止 Director 的逻辑执行(主要就是影响游戏动画),以前就没有考虑过 step 的需求。

不过有了 pause 和 resume 是可以比较好得替代 stopAnimation,做下面几件事更合理:

  1. 废弃 startAnimation & stopAnimation,直接在 deprecated 里面对接 resume 和 pause 接口
  2. 不要增加 resetLateUpdate 接口,在 resume 中直接更新 _lastUpdate
  3. 将 invalid 状态移除并废弃,简化逻辑,在 deprecated 中提示不会有任何效果

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jun 28, 2019

Member

顺便说一下,这是 lastUpdate,并不是 lateUpdate,意义完全不一样

// Resume animation
cc.director.startAnimation();
// To get the correct deltaTime
cc.director.resetLateUpdate();

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jun 28, 2019

Member

stopAnimation 的意义就是停止 Director 的逻辑执行(主要就是影响游戏动画),以前就没有考虑过 step 的需求。

不过有了 pause 和 resume 是可以比较好得替代 stopAnimation,做下面几件事更合理:

  1. 废弃 startAnimation & stopAnimation,直接在 deprecated 里面对接 resume 和 pause 接口
  2. 不要增加 resetLateUpdate 接口,在 resume 中直接更新 _lastUpdate
  3. 将 invalid 状态移除并废弃,简化逻辑,在 deprecated 中提示不会有任何效果
// Resume animation
cc.director.startAnimation();
// To get the correct deltaTime
cc.director.resetLateUpdate();

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jun 28, 2019

Member

顺便说一下,这是 lastUpdate,并不是 lateUpdate,意义完全不一样

// wait util render finish in sub context
setTimeout(function () {
self._updateSubContextTexture();
}, DELAY_TO_UPDATE_TEXTURE);

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jun 28, 2019

Member

这个 delay 太长了,而且这里也不适合使用 setTimeout,引擎里尽量不要新开任何 timer 计时器,这会跟引擎的主循环造成竞争关系,可能导致丢帧。postMessage 应该可以理解为同步操作(确认一下这点),如果是异步的话,其实我们不用考虑这一次 step 结果什么时候可以被更新到贴图上,step 按照 update 节奏来,渲染按照渲染帧率来,也就是 fps 属性的设置。

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jun 28, 2019

Member

哦,才发现是手动执行的操作,用户不应该手动执行组件的 update,你应该将这个逻辑拆分为一个独立函数让用户调用,否则混在一起 update 的语义可能造成混淆。

比如提供 step 函数执行子域的 step,然后用 scheduleOnce 来更新贴图。

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jun 28, 2019

Member

组件有自己的计时系统,应该更好地理解它的机制,而不是使用 setTimeout 这种接口,作为引擎开发人员这是基本的要求。

This comment has been minimized.

Copy link
@umbrellaPP

umbrellaPP Jun 28, 2019

Author Contributor

哦,才发现是手动执行的操作,用户不应该手动执行组件的 update
比如提供 step 函数执行子域的 step

有几个理由不建议新增 step 接口:

  1. 我们文档是这么写的,通过 update 去更新贴图。。。
    已经有用户这么去做了,就算新增 step 接口,也得兼容旧项目的做法
  2. 另外一个原因是平台剔除组件后,就没有 step 接口了,用户调用 step 之前还得做一层保护

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jun 28, 2019

Member

理解了,那么保留 update 函数中的这个实现,但是去除 setTimeout 的使用

This comment has been minimized.

Copy link
@umbrellaPP

umbrellaPP Jun 28, 2019

Author Contributor

stopAnimation 的意义就是停止 Director 的逻辑执行

我看之前的实现不是停止 Director 的逻辑
而是相当于 cc.game.pause(), 把逻辑、渲染和事件处理全都停止了

@umbrellaPP umbrellaPP force-pushed the umbrellaPP:2.1_opendata branch from efb02f9 to 01162af Jun 28, 2019

@umbrellaPP umbrellaPP force-pushed the umbrellaPP:2.1_opendata branch from 2b83afc to 350981c Jun 28, 2019

fromEngine: true,
event: 'step',
});
this._updateSubContextTexture();

This comment has been minimized.

Copy link
@umbrellaPP

umbrellaPP Jun 28, 2019

Author Contributor

安卓 iOS 上测试过,postMessage 都是同步操作

update (dt) {
let calledUpdateMannually = (dt === undefined);
if (calledUpdateMannually) {
this._context && this._context.postMessage({

This comment has been minimized.

Copy link
@umbrellaPP

umbrellaPP Jun 28, 2019

Author Contributor

安卓 iOS 上测试过,postMessage 都是同步操作

this.invalid = false;
this._lastUpdate = performance.now();
cc.warnID(5400, 'cc.director.startAnimation()', 'cc.game.resume()');
cc.game.resume();

This comment has been minimized.

Copy link
@pandamicro

pandamicro Jun 28, 2019

Member

可以写在 deprecated 里面做代码隔离,这样 release 版本就不会带出去了

@pandamicro pandamicro merged commit 661a658 into cocos-creator:v2.1.2 Jun 28, 2019

1 check passed

ci/circleci: test Your tests passed on CircleCI!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.