{"id":23,"date":"2012-12-17T01:38:50","date_gmt":"2012-12-17T01:38:50","guid":{"rendered":"http:\/\/www.fuguelike.com\/blog\/?p=23"},"modified":"2013-01-14T14:32:38","modified_gmt":"2013-01-14T14:32:38","slug":"physics-engine-performance-on-mobile-air-haxenme-native","status":"publish","type":"post","link":"https:\/\/fuguelike.com\/blog\/physics-engine-performance-on-mobile-air-haxenme-native\/","title":{"rendered":"Physics Engine Performance on Mobile &#8211; AIR, HaxeNME, Native"},"content":{"rendered":"<p>I\u2019ve 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\u00a0<a href=\"http:\/\/www.nulldesign.de\/\" target=\"_blank\">ND2D<\/a>\u00a0over\u00a0<a href=\"http:\/\/gamua.com\/starling\/\" target=\"_blank\">Starling<\/a>\u00a0and\u00a0<a href=\"http:\/\/blog.flash-core.com\/?tag=genome2d\" target=\"_blank\">Genome2D<\/a>, since unlike Starling the API was flexible and nicely similar to the Flixel and FlashPunk engines, and unlike Genome2D was open source. Using the\u00a0<a href=\"https:\/\/github.com\/rolfd\/nd2d\" target=\"_blank\">ROLF fork<\/a>\u00a0I was able to get performance comparable to Genome2D.<\/p>\n<p>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\u00a0<a href=\"http:\/\/deltaluca.me.uk\/\" target=\"_blank\">Nape<\/a>\u00a0engine (a really nice engine &#8211; 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).<\/p>\n<p>So I decided to run some tests using\u00a0<a href=\"http:\/\/www.haxenme.org\/\" target=\"_blank\">HaxeNME<\/a>. 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 &#8211; 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.<\/p>\n<p>So I took a look at native, deciding on\u00a0<a href=\"http:\/\/www.cocos2d-x.org\/\" target=\"_blank\">Cocos2Dx<\/a>\u00a0for the rendering, which is an open source C++ port of Cocos2D, and the\u00a0<a href=\"http:\/\/chipmunk-physics.net\/\" target=\"_blank\">Chipmunk<\/a>\u00a0physics engine. Here I was able to get over 450 colliding objects before the frame rate even started to drop below 60 &#8211; 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 \u00a0given that the rendering speed across the various platforms, all utilizing OpenGL ES, is virtually the same.<\/p>\n<p>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\u2019m still using it in other projects), when it comes to computationally intense features of games like physics or AI it still isn\u2019t a viable platform, at least on mobile. Recent developments like the new\u00a0<a href=\"http:\/\/www.bytearray.org\/?p=4789\" target=\"_blank\">Falcon compiler<\/a>\u00a0and\u00a0<a href=\"http:\/\/www.bytearray.org\/?p=4516\" target=\"_blank\">AS workers<\/a>\u00a0are 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\u2019s to hoping that\u00a0<a href=\"http:\/\/bhbooker.com\/2012\/02\/29\/flash-actionscript-4\/\" target=\"_blank\">hints about Actionscript 4<\/a>\u00a0are followed through on.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve 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\u00a0ND2D\u00a0over\u00a0Starling\u00a0and\u00a0Genome2D, since unlike Starling the API was flexible and nicely similar to the Flixel and FlashPunk engines, and unlike Genome2D was open source. Using the\u00a0ROLF [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[14],"tags":[9,10,11,13,12,8,7],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-programming","tag-as3","tag-as4","tag-c","tag-chipmunk","tag-cocos2dx","tag-mobiledev","tag-physics"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2YXmV-n","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/fuguelike.com\/blog\/wp-json\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fuguelike.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fuguelike.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fuguelike.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fuguelike.com\/blog\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":6,"href":"https:\/\/fuguelike.com\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":70,"href":"https:\/\/fuguelike.com\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions\/70"}],"wp:attachment":[{"href":"https:\/\/fuguelike.com\/blog\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fuguelike.com\/blog\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fuguelike.com\/blog\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}