Game Development Reference
In-Depth Information
By using our native copy() method, we can gain quite a lot of speed, especially when we draw
many sprites via the SpriteBatcher class. Having to move vertices from the CPU to the GPU
every frame costs performance, while doing so by making a copy first and converting everything
to ints is even worse. Our new JniUtils reduces the amount of copying considerably, while also
being faster than the IntBuffer trick we employed earlier!
To test our implementation, simply copy over the SpriteBatcherTest and the ObjTest along with
all the necessary assets from previous chapters. Hook them up with the NdkStarter activity and
try them out on your Android device.
Summary
We only scratched the surface of what's possible with the NDK. But, as you witnessed, even
lightweight use of the NDK can pay off quite a bit. Our copy() method was simple to implement
but let us display more sprites per frame by being a lot faster than the old, Java-based
implementation. This is a recurring theme with NDK development: identify your bottlenecks
and implement only very small pieces of code on the native side. Don't go overboard, because
calling native methods has an overhead. Just making everything a native method is unlikely to
increase the performance of your application.
It's now time to look into marketing considerations for our game.
 
Search WWH ::




Custom Search