Physics Engine Performance on Mobile – AIR, HaxeNME, Native

I’ve been developing a game for mobile devices, primarily tablets, and my first choice was to use AIR for mobile and one of the nice new Stage3D game libraries. I chose ND2D over Starling and Genome2D, since unlike Starling the API was flexible and nicely similar to the Flixel and FlashPunk engines, and unlike Genome2D was open source. Using the ROLF fork I was able to get performance comparable to Genome2D.

The rendering performance of all these engines is pretty impressive, about on par here with native rendering on mobile devices, with some language overhead only when you get into the thousands of objects. Problem is the game also makes use of a physics engine, and it this is where the limitations of the platform really start to become a problem. Using the as3 version of the Nape engine (a really nice engine – way faster that Box2DAS3 and with a much better API), I was only able to simulate around 50 dynamic bodies on an iPad2 (hardly a low end device) with decent frame rates (above 40 FPS).

So I decided to run some tests using HaxeNME. Since it compiles to C++ and runs without a VM I expected to see a big performance gain. Using DrawTiles for batched rendering and the Haxe version of Nape for physics I was able to get a pretty good improvement here – about 90 dynamic bodies before dropping below 40FPS on the iPad2. Since I really would like to target lower end devices and am building creatures that each have over 20 dynamic bodies, this was still pretty limiting though.

So I took a look at native, deciding on Cocos2Dx for the rendering, which is an open source C++ port of Cocos2D, and the Chipmunk physics engine. Here I was able to get over 450 colliding objects before the frame rate even started to drop below 60 – more than a 10 fold increase in performance over the best possible solution in AS3, and more than 5 fold increase over HaxeNME. This was way more than I expected, especially  given that the rendering speed across the various platforms, all utilizing OpenGL ES, is virtually the same.

I guess the take away from this is that although Stage3D was a great step forward for the Flash platform in bringing native rendering (and I’m still using it in other projects), when it comes to computationally intense features of games like physics or AI it still isn’t a viable platform, at least on mobile. Recent developments like the new Falcon compiler and AS workers are nice but Adobe is going to have to make more radical changes to the language and VM to be a competitive platform for gaming. Here’s to hoping that hints about Actionscript 4 are followed through on.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>