Slide 1

Slide 1 text

Native Under the Skin Sunday, 9 October 11

Slide 2

Slide 2 text

Why go native? • Access platform features early. • Faster data processing. - Faster mathematical operations. - Faster memory access. • Access to existing libraries. Sunday, 9 October 11

Slide 3

Slide 3 text

Why go native? • Access platform features early. • Faster data processing. - Faster mathematical operations. - Faster memory access. • Access to existing libraries. Sunday, 9 October 11

Slide 4

Slide 4 text

Speed • Can access ASM libraries. • Can access SIMD operands. • Code compiled by sane compilers. (Sometimes) • Box2D, Nexus One, braindead ANE: AS Only ANE 122 objects ~110ms ~25ms Sunday, 9 October 11

Slide 5

Slide 5 text

Sunday, 9 October 11

Slide 6

Slide 6 text

The Good • If you use C or C++, your extension is pretty portable. native ᵓᴷᴷ android (0 source files) ᵓᴷᴷ box2d (136 source files) ᵓᴷᴷ ios (0 source files) ᵋᴷᴷ shared (4 source files) Sunday, 9 October 11

Slide 7

Slide 7 text

The Good • For the ‘droids - it kicks the pants off JNI. jclass cls = (*env)->GetObjectClass(env, obj); jmethodID mid = (*env)->GetMethodID(env, cls, "callback", "(I)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, obj, mid, depth); FRECallObjectMethod(store, "callback", 0, NULL, &methodReturn, NULL); VS Sunday, 9 October 11

Slide 8

Slide 8 text

The Good • You get to play with C, which is awesome. #define _ -F<00||--F-OO--; int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO() { _-_-_-_ _-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_ _-_-_-_ } Sunday, 9 October 11

Slide 9

Slide 9 text

The Bad • Probably going to double your development environments. Sunday, 9 October 11

Slide 10

Slide 10 text

The Bad • Have to remember how to code in stupid languages. ‘\0’ terminated strings dude. char strA[] = "Dammit"; char strB[] = " Janet"; char strCombined[256] = "\0"; strncat(strCombined, strA, 256); strncat(strCombined, strB, 256); Sunday, 9 October 11

Slide 11

Slide 11 text

The Bad • Switching mental contexts. public function foo():void { int wut = inAS() ? 0 : 1; } Sunday, 9 October 11

Slide 12

Slide 12 text

The Ugly • Code it wrong, explode your app. • Lots of boiler plate code. • Errors are cryptic. • Say goodbye to source level debugging. Sunday, 9 October 11

Slide 13

Slide 13 text

Design Sanity Sunday, 9 October 11

Slide 14

Slide 14 text

ActionScript • Make your interface an interface. • Package your shareable source separately. • Create at least a stub AS only version. Make it functional if you can. Sunday, 9 October 11

Slide 15

Slide 15 text

ActionScript • Do ActionScript things in ActionScript if you can. public function getBody( bodyID:uint, createIfNeeded:Boolean = false):b2BodyProxy { if(_bodies[bodyID] == null && createIfNeeded) { _bodies[bodyID] = new b2BodyProxy(); } return _bodies[bodyID]; } Sunday, 9 October 11

Slide 16

Slide 16 text

Native • Write once, compile everywhere. • Abuse the ActionScriptData object. • Take advantage of the fact you control the ActionScript interface for validation. • Keep the interface boundary thin, build complexity at the sides. Sunday, 9 October 11

Slide 17

Slide 17 text

All Together • You control the ActionScript and native boundaries. Make them dance a beautiful dance. • Abuse the Status event for communication. - Logging - Errors - General WTF investigation (printf is your debug) Sunday, 9 October 11

Slide 18

Slide 18 text

Gotchas and Tips Sunday, 9 October 11

Slide 19

Slide 19 text

iOS + AIR × ANE = suck • Optimisation level can break things. • AIR recompilation step can break function pointers. • Choose the right compiler. Sunday, 9 October 11

Slide 20

Slide 20 text

Script Everything Sunday, 9 October 11

Slide 21

Slide 21 text

Android is your friend Sunday, 9 October 11

Slide 22

Slide 22 text

ANE is newly open • Documentation isn’t perfect. • Some things don’t work. • Very small, but growing, community. Sunday, 9 October 11

Slide 23

Slide 23 text

? Unanswered Questions Sunday, 9 October 11

Slide 24

Slide 24 text

Including VM/native boundary, is ANE faster than Alchemy? Sunday, 9 October 11

Slide 25

Slide 25 text

Flash + ANE is more accessible to developers than Java + JNI. It’s also cross platform. Implications for Android? Sunday, 9 October 11

Slide 26

Slide 26 text

1. HaXe 2. Air Native Extensions 3. NME 4. ??? 5. Profit Sunday, 9 October 11

Slide 27

Slide 27 text

Buildr, Buildr, Buildr Sunday, 9 October 11

Slide 28

Slide 28 text

Libraries • Third party platform libraries - Facebook - Open Feint - Analytics - BLAS, LAPACK - fmod Sunday, 9 October 11