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

particle frame update optimize #1915

merged 10 commits into from Nov 1, 2019

Conversation

zhefengzhang
Copy link
Contributor

@zhefengzhang zhefengzhang commented Oct 31, 2019

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

@zhefengzhang
Copy link
Contributor Author

@zhefengzhang zhefengzhang commented Oct 31, 2019

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

@minggo
Copy link
Contributor

@minggo minggo commented Oct 31, 2019

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

@zhefengzhang
Copy link
Contributor Author

@zhefengzhang zhefengzhang commented Oct 31, 2019

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

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

// global particle pool
static ParticlePool _pool;
extern LONGLONG desiredInterval;
Copy link
Contributor

@minggo minggo Oct 31, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@zhefengzhang zhefengzhang Oct 31, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor

@minggo minggo Oct 31, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@zhefengzhang zhefengzhang Oct 31, 2019

Choose a reason for hiding this comment

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

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

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

@minggo minggo Oct 31, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@zhefengzhang zhefengzhang Oct 31, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@zhefengzhang zhefengzhang Oct 31, 2019

Choose a reason for hiding this comment

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

image
image
image

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

Copy link
Contributor

@minggo minggo Oct 31, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@zhefengzhang zhefengzhang Oct 31, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor

@minggo minggo Oct 31, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@zhefengzhang zhefengzhang Oct 31, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@zhefengzhang zhefengzhang Oct 31, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@zhefengzhang zhefengzhang Oct 31, 2019

Choose a reason for hiding this comment

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

那我就这样改了。

@@ -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
Copy link
Contributor

@minggo minggo Oct 31, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@zhefengzhang zhefengzhang Oct 31, 2019

Choose a reason for hiding this comment

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

嗯,我修改下。

@@ -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
Copy link
Contributor

@minggo minggo Oct 31, 2019

Choose a reason for hiding this comment

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

0.0333f,否则是 double 类型

Copy link
Contributor Author

@zhefengzhang zhefengzhang Oct 31, 2019

Choose a reason for hiding this comment

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

@@ -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);
Copy link
Contributor

@minggo minggo Nov 1, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

@zhefengzhang zhefengzhang Nov 1, 2019

Choose a reason for hiding this comment

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

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

Copy link
Contributor

@minggo minggo Nov 1, 2019

Choose a reason for hiding this comment

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

每个任务都要单独都 PR。

Copy link
Contributor Author

@zhefengzhang zhefengzhang Nov 1, 2019

Choose a reason for hiding this comment

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

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

@holycanvas holycanvas merged commit dc7e5ea into cocos:v2.2.1-release Nov 1, 2019
1 check passed
@zhefengzhang
Copy link
Contributor Author

@zhefengzhang zhefengzhang commented Nov 1, 2019

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

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