Game Development Reference
In-Depth Information
const char* scriptCode =
env->GetStringUTFChars(objScript, NULL);
gScriptEngine.AddGameObject(
objId, objX, objY, objColor, scriptCode);
// Release string
env->ReleaseStringUTFChars(objScript, scriptCode);
}
}
The Update function receives the number of seconds elapsed since the last time you updated, and an empty
Java ArrayList , which will be filled with GPTGameObject instances. The script system's Update method is called to
run one step on every object, and then the GetUpdatedObjects function is called to collect the updated objects in a
std::vector . For every element in the vector, a GPTGameObject instance will be created and added to the ArrayList .
And as you saw earlier in the Java GUI code, this is how you draw the updated scene (see Listing 12-22).
Listing 12-22. JNI Update Function
JNIEXPORT void JNICALL
Java_com_gametoolgems_gpt_GPTJNILib_Update(
JNIEnv * env, jobject obj, jfloat deltaTime,
jobject objArrayList)
{
// Update game objects and script system
gScriptEngine.Update(deltaTime);
// Get updated game objects
std::vector<GameObject> gameObjects;
gScriptEngine.GetUpdatedObjects(gameObjects);
// Send updated objects to Java
const char* className =
"com/gametoolgems/gpt/GPTGameObject";
jclass gameObjectClass =
env->FindClass(className);
jmethodID gameObjectCtor =
env->GetMethodID(gameObjectClass,
"<init>", "(IFFI)V");
jclass arrayListClass =
env->FindClass("java/util/ArrayList");
jmethodID arrayListCtor =
env->GetMethodID(arrayListClass, "<init>", "()V");
jmethodID addFunction =
env->GetMethodID(arrayListClass,
"add", "(Ljava/lang/Object;)Z");
Search WWH ::




Custom Search