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

particle frame update optimize #1915

Merged
merged 10 commits into from Nov 1, 2019
Merged

Conversation

@Jno1995
Copy link
Contributor

Jno1995 commented Oct 31, 2019

#1902 的修改。
issues:cocos-creator/2d-tasks#1919

@Jno1995

This comment has been minimized.

Copy link
Contributor Author

Jno1995 commented Oct 31, 2019

我本地没有出现这个格式问题。
image

@minggo

This comment has been minimized.

Copy link
Contributor

minggo commented Oct 31, 2019

格式问题你得看看你的编辑器设置,要把 tab 键改成空格。

@Jno1995

This comment has been minimized.

Copy link
Contributor Author

Jno1995 commented Oct 31, 2019

嗯,是这个原因。我这次用的是 Tab。

@@ -37,6 +38,7 @@ NS_CC_BEGIN

// global particle pool
static ParticlePool _pool;
extern LONGLONG desiredInterval;

This comment has been minimized.

Copy link
@minggo

minggo Oct 31, 2019

Contributor

desiredInterval 变量在哪里定义的?又是在哪里赋值的?
另外,LONGLONG 这种类型应该是 windows 特有的吧,这样代码就无法跨平台了。

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Oct 31, 2019

Author Contributor

定义:
image
赋值:
image
我没考虑到跨平台,现在考虑使用 long 。

This comment has been minimized.

Copy link
@minggo

minggo Oct 31, 2019

Contributor

这个值应该可以根据 fps 计算得到到吧?

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Oct 31, 2019

Author Contributor

嗯。 fps 在 CCApplication.h 中。可以将 fps 设为全局变量。

MiddlewareManager::getInstance()->addTimer(this);
_maxParticleDeltaTime = (float)desiredInterval / nFreq.QuadPart * 2;

This comment has been minimized.

Copy link
@minggo

minggo Oct 31, 2019

Contributor

这个原理是什么?没太看明白。

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Oct 31, 2019

Author Contributor

我希望 _maxParticleDeltaTime 的值能够限制 dt ,所以通过这个计算取得一个略大于 dt 的值。
这是我在 js 那边的修改。
image
cocos-creator/engine@cdcf0de

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Oct 31, 2019

Author Contributor

image
image
image

上面是关于这个 PR 的一些讨论,没在 pr 上进行。

This comment has been minimized.

Copy link
@minggo

minggo Oct 31, 2019

Contributor

那这个值是和 desired fps 相关,并且随着它而改变是吗?如果是固定值到话,那么直接设置在 particle 模块就可以了。

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Oct 31, 2019

Author Contributor

js 目前的设定是 当游戏调用修改的 FPS 的接口时,会跟着修改一次这个值。为了和 js 引擎保持一致,还是不采用固定值了。

This comment has been minimized.

Copy link
@minggo

minggo Oct 31, 2019

Contributor

既然这样的话,那么这个逻辑应该是适用于所有平台。目前的修改只考虑的 windows 平台。

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Oct 31, 2019

Author Contributor

issues上说是 模拟器上才会有这个问题,我测试过后,发现 web 也会有类似问题,所以修改了 JS 引擎。我现在验证下 android 和 ios 上是否也会有一样的问题。

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Oct 31, 2019

Author Contributor

验证了,在 android 和 ios 上不会有这个问题。现在认为直接在 particle system 中定义个常量 _maxParticleDeltaTime ,限制 particle system 的 render 函数接收的 dt 即可。

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Oct 31, 2019

Author Contributor

那我就这样改了。

@@ -232,6 +232,7 @@ class ParticleSimulator : public cocos2d::middleware::IMiddleware, public cocos2
bool _finished = false;
float _elapsed = 0;
float _emitCounter = 0;
float _maxParticleDeltaTime = 0.0333; //ParticleSystem max step delta time

This comment has been minimized.

Copy link
@minggo

minggo Oct 31, 2019

Contributor

这样的话用 宏 或者是,static const 类型的常量会更合适。

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Oct 31, 2019

Author Contributor

嗯,我修改下。

Jno1995 added 4 commits Oct 31, 2019
@@ -37,7 +37,7 @@ NS_CC_BEGIN

// global particle pool
static ParticlePool _pool;
static const float _maxParticleDeltaTime = 0.03; //ParticleSystem max step delta time
static const float _maxParticleDeltaTime = 0.0333; //ParticleSystem max step delta time

This comment has been minimized.

Copy link
@minggo

minggo Oct 31, 2019

Contributor

0.0333f,否则是 double 类型

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Oct 31, 2019

Author Contributor

@@ -218,7 +218,7 @@ public void onResponse(Call call, Response response) throws IOException {
while ((len = is.read(buf)) != -1) {
current += len;
fos.write(buf, 0, len);
downloader.onProgress(id, current, len, total);

This comment has been minimized.

Copy link
@minggo

minggo Nov 1, 2019

Contributor

这些修改和这个 PR 没有关系吧。请单独提 PR 修复。

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Nov 1, 2019

Author Contributor

嗯,我昨天不知道要等当前的这个 pr 合并之后才能提交。我修改下。

This comment has been minimized.

Copy link
@minggo

minggo Nov 1, 2019

Contributor

每个任务都要单独都 PR。

This comment has been minimized.

Copy link
@Jno1995

Jno1995 Nov 1, 2019

Author Contributor

以后我会新建一个分支提交。

@holycanvas holycanvas merged commit dc7e5ea into cocos-creator:v2.2.1-release Nov 1, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Jno1995

This comment has been minimized.

Copy link
Contributor Author

Jno1995 commented Nov 1, 2019

这个修改对 android 和 ios 都是生效的。

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.