Game Development Reference
In-Depth Information
@Override
public void
update(
float
deltaTime) {
}
@Override
public void
present(
float
deltaTime) {
}
@Override
public void
pause() {
}
@Override
public void
resume() {
}
@Override
public void
dispose() {
}
}
}
All the important stuff happens in the screen's constructor. We start off by creating a small
float[]
array with some dummy values and a direct
ByteBuffer
instance that can hold 12 bytes,
or 4 floats. We also make sure that the
ByteBuffer
instance uses native byte order, so that we
don't run into some nasty issues when we pass it to our C/C++ code.
We then copy over three floats from the
float[]
array, starting at index 1, to our
ByteBuffer
instance. The final few lines output the copied floats via our native logging method.
Executing this code on a device will output the following in LogCat:
08-15 17:28:31.953: V/JniUtilsTest(1901): 554.3
08-15 17:28:31.953: V/JniUtilsTest(1901): 348.6
08-15 17:28:31.953: V/JniUtilsTest(1901): 499.3
Exactly what we were expecting. Let's quickly modify the
Vertices
and
Vertices3
classes to use
our new, faster
copy()
method.
Modifying the vertices classes starts with a problem: the
JniUtils
class is not in the
com.badlogic.androidgames.framework
package; instead, it is in the
com.badlogic.androidgames.ndk
package. Let's move it to the
framework
package so
we can reuse it.
This leads to a new problem. Our C/C++ header and source file rely on the fact that the
JniUtils
class is in the
ndk
package. Now that we moved it to the
framework
package, we have to modify
the header and source file accordingly. The first thing we need to do is call
javah
again. This will
update the
jniutils.h
file. Next, we have to copy the new function names to the
jniutils.cpp
file. Finally, we need to recompile the shared libraries by invoking
ndk-build
. Quite a bit of work
for such a small change.