Game Development Reference
In-Depth Information
Listing 12-21. JNI Initialize Function
JNIEXPORT void JNICALL
Java_com_gametoolgems_gpt_GPTJNILib_Initialize(JNIEnv * env,
jobject obj, jobjectArray objects)
{
// Reset script engine
gScriptEngine.Reset();
// Initialize script system with scene
const char* className =
"com/gametoolgems/gpt/GPTEditorGameObject";
jclass editorGameObjClass = env->FindClass(className);
jfieldID goId =
env->GetFieldID(editorGameObjClass, "id", "I");
jfieldID goX =
env->GetFieldID(editorGameObjClass, "x", "F");
jfieldID goY =
env->GetFieldID(editorGameObjClass, "y", "F");
jfieldID goColor =
env->GetFieldID(editorGameObjClass, "color", "I");
jfieldID goScript =
env->GetFieldID(editorGameObjClass,
"script", "Ljava/lang/String;");
jsize len = env->GetArrayLength(objects);
for (int i = 0; i < len; ++i)
{
jobject gameObj =
(jobject)env->GetObjectArrayElement(objects, i);
jint objId =
env->GetIntField(gameObj, goId);
jfloat objX =
env->GetFloatField(gameObj, goX);
jfloat objY =
env->GetFloatField(gameObj, goY);
jint objColor =
env->GetIntField(gameObj, goColor);
jstring objScript =
(jstring)env->GetObjectField(gameObj, goScript);
Search WWH ::




Custom Search