Skip to content

to use a animation scheduler to update all animation at a time, so th… #30

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

Closed
wants to merge 4 commits into from

Conversation

SijieCai
Copy link
Contributor

@SijieCai SijieCai commented Sep 3, 2018

…at to use one nowtime for all calculation, benchmark show for animation sprites larger than 1000 we have 20% more fps gain. this commit depends on two other commmit in sprite-timeline and sprite-animation as bellow:
spritejs/sprite-animator#1
spritejs/sprite-timeline#1

…at to use one nowtime for all calculation, benchmark show for animation sprites larger than 1000 we have 20% more fps gain. this commit depends on two other commmit in sprite-timeline and sprite-animation.
@akira-cn
Copy link
Contributor

akira-cn commented Sep 4, 2018

这样改动太大了,要测试和回归的工作太多,而且涉及小程序版、Node版多个平台以及一些扩展。

现在2.x版本是线上用的版本,建议先不做这样激进的重构。

我根据你的这个思路微改了一下,给timeline提供了一个nowtime的参数,用来获取当前时间,然后在requestAnimationFrame的时候把时间戳传给timeline内部用来获取nowtime。

关于timeline不可变,之前有考虑过,主要是两个方面因素最终没有采用

  • 因为timeline遵循Mozilla的AnimationTimeline,所以API方面希望保持一致

  • timeline自身本身就是与时间(历史)有关的,无法直接做到immutable,比如:“在动画运行2.5秒的时候,把速度加倍,在动画运行7秒的时候,把速度复原”像这样的操作本身就是时序相关的,getCurrent(globalTime)是无法实现成纯函数的,因为它的值取决于前面设置过的playbackRate(在timeline里面是通过创建timeMark来实现的),这个是无法做到immutable的

  • 仔细想想immutalbe其实是一个不错的思路,而要做的话需要把history数据对象给抽象出来,也就是说每次playbackRate的改变要返回一个history纯对象,然后每次getCurrentTIme需要传globalTime和history两个参数进去,这样可以做到纯函数。

在sprite-timeline 2.0中准备尝试这么做,这样也许能极大提升运行效率

@akira-cn akira-cn closed this Sep 4, 2018
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.

2 participants