Merge pull request #37174 from m4gr3d/make_godot_plugin_callbacks_generic

Update the naming scheme for the GodotPlugin's methods
This commit is contained in:
Rémi Verschelde 2020-03-20 09:00:50 +01:00 committed by GitHub
commit bec9fe2c2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 24 deletions

View file

@ -55,8 +55,6 @@ import android.hardware.SensorManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Messenger;
import android.os.VibrationEffect;
import android.os.Vibrator;
@ -64,7 +62,6 @@ import android.provider.Settings.Secure;
import android.support.annotation.CallSuper;
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.Display;
import android.view.KeyEvent;
@ -197,12 +194,12 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
};
/**
* Invoked on the GL thread when the Godot main loop has started.
* Invoked on the render thread when the Godot main loop has started.
*/
@CallSuper
protected void onGLGodotMainLoopStarted() {
protected void onGodotMainLoopStarted() {
for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
plugin.onGLGodotMainLoopStarted();
plugin.onGodotMainLoopStarted();
}
}
@ -247,7 +244,7 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
// Must occur after GodotLib.setup has completed.
for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
plugin.onGLRegisterPluginWithGodotNative();
plugin.onRegisterPluginWithGodotNative();
}
setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on")));
@ -787,11 +784,11 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
}
/**
* Queue a runnable to be run on the GL thread.
* Queue a runnable to be run on the render thread.
* <p>
* This must be called after the GL thread has started.
* This must be called after the render thread has started.
*/
public final void runOnGLThread(@NonNull Runnable action) {
public final void runOnRenderThread(@NonNull Runnable action) {
if (mView != null) {
mView.queueEvent(action);
}

View file

@ -34,6 +34,7 @@ import android.app.Activity;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Surface;
import android.view.View;
import java.lang.reflect.Method;
import java.util.ArrayList;
@ -84,8 +85,10 @@ public abstract class GodotPlugin {
/**
* Register the plugin with Godot native code.
*
* This method is invoked on the render thread.
*/
public final void onGLRegisterPluginWithGodotNative() {
public final void onRegisterPluginWithGodotNative() {
nativeRegisterSingleton(getPluginName());
Class clazz = getClass();
@ -169,9 +172,9 @@ public abstract class GodotPlugin {
public boolean onMainBackPressed() { return false; }
/**
* Invoked on the GL thread when the Godot main loop has started.
* Invoked on the render thread when the Godot main loop has started.
*/
public void onGLGodotMainLoopStarted() {}
public void onGodotMainLoopStarted() {}
/**
* Invoked once per frame on the GL thread after the frame is drawn.
@ -189,6 +192,22 @@ public abstract class GodotPlugin {
*/
public void onGLSurfaceCreated(GL10 gl, EGLConfig config) {}
/**
* Invoked once per frame on the Vulkan thread after the frame is drawn.
*/
public void onVkDrawFrame() {}
/**
* Called on the Vulkan thread after the surface is created and whenever the surface size
* changes.
*/
public void onVkSurfaceChanged(Surface surface, int width, int height) {}
/**
* Called on the Vulkan thread when the surface is created or recreated.
*/
public void onVkSurfaceCreated(Surface surface) {}
/**
* Returns the name of the plugin.
* <p>
@ -225,12 +244,12 @@ public abstract class GodotPlugin {
}
/**
* Queue the specified action to be run on the GL thread.
* Queue the specified action to be run on the render thread.
*
* @param action the action to run on the GL thread
* @param action the action to run on the render thread
*/
protected void runOnGLThread(Runnable action) {
godot.runOnGLThread(action);
protected void runOnRenderThread(Runnable action) {
godot.runOnRenderThread(action);
}
/**

View file

@ -207,7 +207,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jcl
}
os_android->main_loop_begin();
godot_java->on_gl_godot_main_loop_started(env);
godot_java->on_godot_main_loop_started(env);
++step;
}

View file

@ -66,7 +66,7 @@ GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_godot_instance) {
_is_activity_resumed = p_env->GetMethodID(cls, "isActivityResumed", "()Z");
_vibrate = p_env->GetMethodID(cls, "vibrate", "(I)V");
_get_input_fallback_mapping = p_env->GetMethodID(cls, "getInputFallbackMapping", "()Ljava/lang/String;");
_on_gl_godot_main_loop_started = p_env->GetMethodID(cls, "onGLGodotMainLoopStarted", "()V");
_on_godot_main_loop_started = p_env->GetMethodID(cls, "onGodotMainLoopStarted", "()V");
}
GodotJavaWrapper::~GodotJavaWrapper() {
@ -108,13 +108,13 @@ void GodotJavaWrapper::on_video_init(JNIEnv *p_env) {
p_env->CallVoidMethod(godot_instance, _on_video_init);
}
void GodotJavaWrapper::on_gl_godot_main_loop_started(JNIEnv *p_env) {
if (_on_gl_godot_main_loop_started) {
void GodotJavaWrapper::on_godot_main_loop_started(JNIEnv *p_env) {
if (_on_godot_main_loop_started) {
if (p_env == NULL) {
p_env = ThreadAndroid::get_env();
}
}
p_env->CallVoidMethod(godot_instance, _on_gl_godot_main_loop_started);
p_env->CallVoidMethod(godot_instance, _on_godot_main_loop_started);
}
void GodotJavaWrapper::restart(JNIEnv *p_env) {

View file

@ -61,7 +61,7 @@ private:
jmethodID _is_activity_resumed = 0;
jmethodID _vibrate = 0;
jmethodID _get_input_fallback_mapping = 0;
jmethodID _on_gl_godot_main_loop_started = 0;
jmethodID _on_godot_main_loop_started = 0;
public:
GodotJavaWrapper(JNIEnv *p_env, jobject p_godot_instance);
@ -73,7 +73,7 @@ public:
jobject get_class_loader();
void on_video_init(JNIEnv *p_env = NULL);
void on_gl_godot_main_loop_started(JNIEnv *p_env = NULL);
void on_godot_main_loop_started(JNIEnv *p_env = NULL);
void restart(JNIEnv *p_env = NULL);
void force_quit(JNIEnv *p_env = NULL);
void set_keep_screen_on(bool p_enabled);