Game Development Reference
In-Depth Information
Native Script Engine Implementation
In the last section, you declared two native functions in the GPTJNILib class, Initialize and Update . Their
implementations are still missing, so you will take care of that in this section. What does it mean to initialize the script
engine? It means setting up the scene as it was created in the editor, but now in the context of scripted objects. How
about updating? So many different things can be thought of as taking part in updating a scene. For example, collision
detection and input handling may be a part of updating. Creating and destroying objects can also be considered
updating. But for your purposes, updating a scene means calling the OnUpdate script function on every game object.
Detecting collisions, handling touch input, and creating and destroying objects are left as an exercise to the reader.
Building GPT's Native Library with Android NDK
Preparing the build setup for native code can be tricky at first, but once it works, it's highly unlikely that it will require
changes. The first thing to do is build AngelScript for Android as a static library. There are many ways to set up for
building, but the following is an easy way.
Inside the AngelScript source distribution, there is a /projects/android folder.
Navigate to it, and create a subfolder named jni .
1.
Move the Android.mk file from /projects/android to the new
/projects/android/jni folder.
2.
Open the Android.mk file and make the following changes:
3.
Replace the line
LOCAL_PATH:= $(call my-dir)/../../source
with
LOCAL_PATH:= $(call my-dir)/../../../source
Add the following lines at the end of the file:
include $(CLEAR_VARS)
LOCAL_MODULE := dummy
LOCAL_STATIC_LIBRARIES := libangelscript
include $(BUILD_SHARED_LIBRARY)
4.
Open Cygwin, navigate to the android project's folder within AngelScript
(i.e., /cygdrive/c/angelcode/angelscript/projects/android ) and run the ndk-build
script. For example, if the Android NDK was installed in C:\android-ndk-r9d , then the
command would be
/cygdrive/c/android-ndk-r9d/ndk-build [ENTER]
Adding an extra ../ to Android.mk is required because in the previous step, that file was moved one folder deeper
than it used to be. Adding the four lines at the end is necessary because a static library doesn't have to build on its
own—unless other code depends on it. In this case, you are using a dummy library to create a dependency. After
running ndk-build , you should have a libangelscript.a static library file.
 
Search WWH ::




Custom Search