码迷,mamicode.com
首页 > 其他好文 > 详细

Starling 2.0 Beta Note 翻译

时间:2016-07-12 06:49:35      阅读:377      评论:0      收藏:0      [点我收藏+]

标签:

Starling 2.0 Beta

Daniel Sperl on February 29, 2016

 

Seven months ago, I set myself the goal of bringing Starling to the next level. To completely rethink its rendering architecture; to make it more extendable; to clean up all the tiny little compromises that had built up since its first release, and make every single class something to be proud of.

几个月前,我给自己设定一个目标,要把Starling升级到下一个版本。重新思考它的渲染架构,使他更加具有扩展性,清理掉那些长久以来的折中方案,使每一个类都神采奕奕。

I can tell you, it was quite a trip. More than once, I found myself at a dead end, thinking I‘d never be able to pull this off. But I knew what I had signed up for, and every time I managed to finish another small part of the puzzle, I became more confident that it would work out in the end, until finally, all parts fell into place.

 

这是一个漫长的旅途,不止一次,我发现我再一个死胡同里面,感觉自己永远无法完成之情。但是我已经签约了。但是解开一个小小的困惑后,我变得越来越自信,相信自己可以完成这件事情,直至最后。

 

The new version is miles ahead of what Starling has ever been, and it lays the foundations of even greater things. As you can imagine, it‘s a huge relief and joy for me to finally be able to write this blog post, introducing: Starling 2.0!

这个新版本已经远远超越之前的版本,它有一个强大的基础。正如你能想象的,我很欣慰可以在这里编写和发布介绍Starling 2.0的文章。

 

Completely new Rendering Architecture

全新的渲染架构

In the past, the basic building blocks of all rendering were the Quad and Image classes. That was somewhat limiting, since you‘re not always interested in rectangular objects. Thus, I inserted a new base class into that inheritance chain: the Mesh.

之前,Quad和Image类作为最基础的渲染单元。这个或多或少会由一些限制,因为他们都是矩形的。这样就在继承树上增加了一个Mesh类

As its name suggests, a mesh describes an arbitrary shape; anything that can be built up with triangles can be displayed by a mesh. Quad and Image are now both inheriting from this class, but you could easily create, say, a Triangle or Circle and still get full batching.

正如它的名字,Mesh描述了一个任意形状;所有东西都可以通过三角形进行构建,并使用mesh进行展现。Quad和Image现在都是继承了Mesh类,但是使用起来还是依然方便的,三角形或圆形可以批量提交到GPU处理。

Defining the shape of an object is one part of rendering; another is how it‘s going to appear on the screen. Do you map a texture onto it? Are the colors modified in any way? What about lighting? Multi-texturing? In previous versions, you were pretty much stuck with the basics in that respect. Not any more: now, the new MeshStyle class takes care of that.

定义一个物体的形状是渲染的一部分,另外就是如何让在屏幕上呈现。你是否需要映射纹理进行显示?颜色是否可以岁修改?光照效果? 多纹理? 使用之前的版本时,在这些方面,你肯定会有诸多不爽。现在不需要了MeshStyle类可以消除你的烦恼。

Each mesh now has a style property. Per default, that points to the standard MeshStyle implementation, which supports textured and colored vertices. However, you can assign arbitrary styles, too; the class was designed to be extended.

每个mesh都会有一个style属性,默认情况下它指向默认的MeshStyle实现,这个默认实现支持纹理和色彩顶点。当然,也可以设置任何样式到Mesh上。这个默认实现是可以被继承扩展的。

Let‘s look at a sample. We start with a standard image and then attach a LightStyle to it, which is part of the new Dynamic Lighting Extension.

看一下下面这个例子,我们使用一个标准的Image,然后使用一个LightStyle(光照效果)。

var image:Image = new Image(assets.getTexture("hero"));

trace(image.style); // -> MeshStyle

addChild(image);

 

var style:LightStyle = new LightStyle(assets.getTexture("hero_normalmap"));

image.style = style;

This style uses a normal map (created with Andreas Löw‘s SpriteIlluminator) to add realistic lighting effects to your meshes.

 

升级向导

http://feathersui.com/help/migration-guide-3.0.html

 

With custom styles, the possibilities are nearly endless; and since styles fully support batching, there is no performance penalty at all for using them. In fact, you can even let Starling use a custom style for all meshes per default! Want to write a style that supports batching across multiple textures? Yes you can!

如果是自定义样式,那么它的可能性是无穷无尽的。由于批处理可以支持到样式,所以即使使用样式也没有太大的性能损失。事实上,即使给所有的Mesh使用一个默认的自定义样式也没有太大问题。另外,使样式支持多纹理的批处理也是可以的

Behind the Scenes

场景绑定

If you want to create your own styles, you can follow this new tutorial in the Starling Wiki. Along the way, you‘ll notice that the new version not only introduces the Mesh and MeshStyle classes, but a whole new infrastructure for Stage3D rendering.

如果想要创建自己的样式,你可以参考wiki中的方法。按照里面的方法,你会发现新的Starling版本不仅有Mesh和MeshStyle类,还好包含了一个全新的Stage3D渲染设施。

  • The Program class wraps fragment and vertex shaders together in a single object that automatically survives a context loss.

Program类包含了一个对象中的fragment  shaders(碎片着色器)和vertex shaders(顶点着色器),并且可以自动处理上下文丢失的情况。

  • The Painter replaces the old RenderSupport class, simplifying a lot of common rendering tasks and providing a stack of RenderStates.

Painter类替换了原来的RenderSupport类,简化了常用渲染任务,并提供一个RenderStates。

  • The VertexData class now not only uses a ByteArray to store all its data efficiently, but can be configured to hold arbitrary formats.

VertexData类现在不仅可用ByteArray类存数据,并且可以被配置成持有任一格式的数据。

  • The IndexData accompanies VertexData now, so you can handle indices just as easily as vertices.

IndexData类与VertexData类相似,可以用处理顶点的方法来处理indices。

Effect类(包括FilterEffect类和MeshEffect类)封装了所有 Stage3D操作在drawing操作中。

For advanced Starling users, all of those new building blocks greatly simplify custom rendering code, removing a lot of boiler-plate code and preventing problems before they arise.

对于高级的Starling用户来说,以上这些改进极大的简化了自定义渲染的代码。

Render Cache

渲染缓存

One thing that always bugged me in the past was the high CPU load in scenes with a big number of static objects. There must be a way to automatically optimize static scenes, I thought, but I never quite came up with a solution for this problem. Until now!

之前一直困扰我的一个问题就是场景中的大量静态对象引起的高cpu负载。所以必须有一个方法可以自动优化静态场景。但是我之前一直没有深入去解决这个问题,直到今天。

If an object and its parents do not change in a given frame, they are now rendered directly from the new render cache. This means much less work for the CPU: no iterating over children, no transformations of vertices, just a single ByteArray copy operation. That‘s especially great for Feathers applications: while your users look at a static screen, the CPU load is now minimal, enhancing battery life significantly.

在给定的帧中,如果一个对象的parent没有发生改变,那么他们可以直接从渲染缓存直接渲染。这就意味着CPU可以执行更少的工作,仅仅是一个简单的ByteArray拷贝的操作。对于Feathers应用来说会更好一些,当用户正在使用一个静态的场景时,CPU的负载就会下来,延长电池的使用时间。

But even in games where there‘s constantly a lot going on, there are almost always some static objects on the screen. Having the render cache for those parts of the display tree frees up valuable CPU time for everything else. And even in worst-case scenarios (everything is moving), the overhead of the cache is reasonably small (no more than 10% compared to Starling 1.7).

即便在游戏中,动态对象占多数,也会有一些静态对象存在,使用了render缓存后或多或少总可以释放一些CPU负载。最糟糕的情况是所有的对象都在动,也会有一定的负载下降,大概是starling 1.7 版本的 10%。

Here‘s how this looks like in Scout. What you see below is the CPU usage of a mostly static scene, rendered with Starling 1.7 (top) and Starling 2.0 (bottom).

以下是Scout中看到的CPU使用情况

 技术分享

Think of this as Starling‘s contribution to fight climate change. ;-)

New Filter API

新的滤镜API

Here‘s another API I was never fully satisfied with: fragment filters. They did their job, but some parts of them felt more complicated than necessary. That‘s why I completely rewrote them, as well. The new API has several advantages:

还有API我不太满意,fragment滤镜。。他们确实做了他们该做的工作,但是某些部分感觉有点乱。这就是我也要重写他们的原因

  • It automatically makes use of the render cache: if your object doesn‘t move, the filter won‘t need to be processed again, but will use the output from the previous frame

自动利用渲染缓存:如果你的对象没有移动,那么滤镜就无需进行二次处理,而是直接使用上一桢的输出。

  • It‘s much easier to create your own filters. I already wrote a tutorial that gets you started.

需要有更加简洁的API来创建你自己的滤镜,我已经写了一个简单的说明。

阴影滤镜和发光滤镜现在被分离到连个单独的类。

  • You can easily combine several filters on one display object via the new FilterChain.

可以使用FilterChain把多个滤镜应用到一个对象上

Here‘s the filter chain in action:

var hueFilter:ColorMatrixFilter = new ColorMatrixFilter();

hueFilter.adjustHue(1);

var dropShadowFilter:DropShadowFilter = new DropShadowFilter();

 

var image:Image = new Image(assets.getTexture("starling"));

image.filter = new FilterChain(hueFilter, dropShadowFilter);

addChild(image);

 

Convenience Features

更加简洁方便

While I was refactoring all the code that had been created over the last couple of years, I also took the time to revisit several other topics that I‘d been wanting to address for a long time.

过去几年,当我在重构我的代码的时候,我也花了一点时间去重新回顾其它的一些主题,这些东西也是我只在思考的。

  • The TextField class is now accompanied by the new TextFormat. The setup is quite similar to classic Flash — but without the pain of constantly having to re-assign the format for changes to show up. In Starling, when you change the TextField‘s format, it‘s going to be updated right away!

Textfield类现在已经和TextFormat类协同,设置方法和传统的Flash类似。不同的时,当TextFormat更改后不需要在给TextField设置一次。它会直接更新掉的。

  • The TextField class also includes a new wordWrap property.

TextField增加了一个换行属性wordWrap

  • The Image class contains two new properties: scale9Grid and tileGrid. For Feathers-users, this will sound familiar: they replace Scale3Image, Scale9Image and TiledImage.
  • Image类增加了scale9Grid属性和tileGrid属性,对于Feathers的用户来说会很熟悉,这个替换了原来在Feathers中的几个类。
  • All Display Objects can now be scaled uniformly with a single property: scale.

所有的显示对象现在可以被缩放,只要使用scale这个属性即可。

  • My personal favorite: the new pixelSnapping property, which is enabled per default, makes sure that all objects are rendered as sharp and crisp as possible. No more casting to int to avoid blurriness!

我个人比较喜欢的一个属性是pixelSnapping,它默认是开启的,确信每个对象可以被渲染的尽可能锐利和清爽。不再使用转换成int的方式来避免模糊度。

 

  • You can now attach "frame actions" to MovieClips, i.e. code to execute at certain frames.

你可以给MovieClip附件一个Action,可以在某一个指定的帧执行。

  • The Pool provides simple object-pooling for standard classes like Point, Rectangle and Matrix.

Pool可以把一些要频繁实例化的对象进行缓存,例如 Point,Rect,Matrix等

  • The juggler now supports uint handles for IAnimatable removal, which prevents nasty pooling bugs.

Juggler 现在可以为IAnimatable移除使用uint类型的句柄,这样可以避免pooling bugs

How to Upgrade

如何升级

As you probably guessed from what I wrote above, this update is much more extensive than any previous release — it‘s called "2.0" for a reason! This also means, however, that upgrading a project to Starling 2.0 is not as straight-forward as before, depending on your code (custom rendering?) and external dependencies.

从我上面介绍中你可以想象到,这次更新的变化的有点厉害,这就是为什么叫他2.0的原因了。这也意味着,要把一个项目更新到2.0不会那么直接了当,其中的难易程度取决于项目代码本身。

To help you with that, I wrote a migration guide that helps you decide if you should upgrade, and if so, what you need to change. The most important information in advance: the upcoming Feathers 3.0 already works great with Starling 2! (A huge thanks to Josh Tynjala!)

为了更好的帮助你升级,我编写了一个migration guide 向导,可以帮助你决定是否需要升级,哪些东西是需要在升级过程中有所改变的。一个重要的消息是,Feathers 3.0已经可以和Starling2.0一起工作了,

If it turns out that you‘d rather stick with the old version for the time being, I have a small gift for you, as well: as of today, I‘m also releasing Starling 1.8, fixing several bugs and issues that popped up since the last release. Henceforth, I‘ll support this release via its own branch on GitHub, while all 2.x development will happen on the master branch.

如果你的项目一下子升级不了,你可以使用1.8版本。这个我们已经安排专人来进行技术支持。

Now Get Started!

现在开始

Finally, I want to thank all of you for the continuing support for Starling. The new version is a gift to the community; it wouldn‘t have happened if Starling weren‘t as popular as it is today. While it was a lot of hard work to build it, it was also one of the most rewarding journeys of my life as a developer, and I loved every minute of it.

最后,我还是要感谢你们长期以来的支持,这个新的版本是给社区的一个礼物,如果starling没有像今天这样流行,这些事情也不会发生。尽管这是一个艰难的构建工作,但也是我程序员生涯中最有价值的一段旅程,我热爱其中的每一分,每一秒。

Please, everyone: download the new version, play around with it and let me know any issues you run into! I want to get rid of that "beta" flag as soon as possible. I already have so many ideas for Starling 2.1, I want to get this done with! :-)

I‘d also appreciate any comments below. Let me know what you think of the new version, and tell us if the upgrade went smoothly for you. Thanks a lot in advance!

请大家下载最新的版本,尽情的玩转它,并且告诉我任何其中的一些问题。我真的很想去掉“beta”,我已经有很多关于Starling2.1的想法了,我也想尽快的把它完善掉。我也喜欢你们在楼下的任何评论,让我知道你们关于这个版本的想法,你们的项目升级是否顺利。我先提前感谢大家。

— UPDATE (March 4th) —

A quick heads-up: several developers have reported performance issues with the new version. I‘m currently looking into it and hope to get this fixed in a second beta. Sorry for the troubles!

Starling 2.0 Beta Note 翻译

标签:

原文地址:http://www.cnblogs.com/leefj/p/5662224.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!