Google I/O Writing Real-Time Games for Android

http://www.youtube.com/watch?v=U4Bk5rmIpic

Androidで開発するためのパフォーマンス上の工夫について、色々と述べられているので面白いですね。大分特殊な感じの開発になるかなという印象です。Android上では、オブジェクト指向開発は忘れてしまわないといけなそうです。

全体のデザイン

3つのスレッドに分けている

  • Main Thred
  • Game Thread
    • non rendering parts of the game
    • Rendering threadをblocking
  • Rendering thread

モリー管理

  • Never allocate memory or release it.
    • GCが発生するとゲーム系は止まるからダメ。
    • 100〜300ms止まるのでReal timeゲーム系にはダメ。
  • MemoryをAlocateするものを使うな
    • Collections, enums, Arrays.sortとか標準ライブラリは軒並みダメ。
    • DDMS is your tool to name and blame

関数

  • Don't call functions
    • static関数を可能な限り使う
  • Don't call functions through an interface.
    • 30% slower than regular virtual functions
  • JNI系関数が遅い
    • gIXX() functions

その他Tips

  • Use local variables, especially in inner loops
  • Use final keyword on fields whenever you possibly can
    • avoid float math
  • Log.d()
    • System.out.print()使わずにTraceViewつかえ

2D描画系

  • Canvas
    • 2D
  • OpenGL ES
    • 2D, 3D
  • 2Dの描画系の速度
    • draw_texture > VBOs > Basic Quads > Canvas
  • OpenGL ES + the draw_texture extension is the fas
    • draw_textureは全てのプラットフォームでサポートはしてない
  • Canvasは描画する物が少ないとき
  • single static image が早い

その他の tips

  • Screenをtouchすると、MotionEventであふれて、それで遅くなる
    • onTouchEvent callbackでfloodをslowさせるのがいい。16msのsleepから初めてみるのがよい。
  • GLSurfaceViewをpausing, resuming用途に使う

# Javaネタをどこで書こうかと思っていたのですが、本家日記を復活させてみることにしました。