Game Development Reference
In-Depth Information
// Load native code library
GPTJNILib.Load();
// Create views and set current view to scene editor
scriptEditorView = new GPTScriptEditorView(this);
scenePlayerView = new GPTScenePlayerView(this);
sceneEditorView = new GPTSceneEditorView(this);
SetCurrentView(sceneEditorView);
}
public void SetCurrentView(View v)
{
mCurrentView = v;
setContentView(v);
}
@Override
public void onBackPressed()
{
if (mCurrentView == scriptEditorView)
scriptEditorView.onBackPressed(this);
else if (mCurrentView == sceneEditorView)
sceneEditorView.onBackPressed(this);
else if(mCurrentView == scenePlayerView)
scenePlayerView.onBackPressed(this);
}
}
GPTJNILib
Rather than give native member methods to each class that requires C/C++ interaction, the project will have an
abstract class that exposes all the necessary native functions to the rest of the Java code. This simplifies JNI function
naming on the C/C++ side. There are two main things the native code should do to interact with the scripting engine:
set up a scene and update a scene. GPTJNILib.java only declares those two static functions, plus an additional
function to load the C/C++ library itself, as shown in Listing 12-2.
Listing 12-2. GPTJNILib Abstract Class
public abstract class GPTJNILib
{
public static void Load()
{
System.loadLibrary("gptjni");
}
public static native void Initialize(
GPTEditorGameObject[] gameObjects);
public static native void Update(
float deltaTime,
ArrayList<GPTGameObject> updatedGameObjects);
}
 
Search WWH ::




Custom Search