mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Add support for using an Android Service to host the Godot engine
- Provide a `GodotService` Android service implementation which can be used to host an instance of the Godot engine - Provide a `RemoteGodotFragment` Android fragment implementation which provides the view and logic to wrap connection to a `GodotService` instance
This commit is contained in:
parent
4261cc07a5
commit
dc589e239c
22 changed files with 1118 additions and 400 deletions
|
@ -37,9 +37,8 @@
|
|||
|
||||
// TODO we could probably create a base class for this...
|
||||
|
||||
GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_godot_instance) {
|
||||
GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_godot_instance) {
|
||||
godot_instance = p_env->NewGlobalRef(p_godot_instance);
|
||||
activity = p_env->NewGlobalRef(p_activity);
|
||||
|
||||
// get info about our Godot class so we can get pointers and stuff...
|
||||
godot_class = p_env->FindClass("org/godotengine/godot/Godot");
|
||||
|
@ -49,13 +48,6 @@ GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_
|
|||
// this is a pretty serious fail.. bail... pointers will stay 0
|
||||
return;
|
||||
}
|
||||
activity_class = p_env->FindClass("android/app/Activity");
|
||||
if (activity_class) {
|
||||
activity_class = (jclass)p_env->NewGlobalRef(activity_class);
|
||||
} else {
|
||||
// this is a pretty serious fail.. bail... pointers will stay 0
|
||||
return;
|
||||
}
|
||||
|
||||
// get some Godot method pointers...
|
||||
_restart = p_env->GetMethodID(godot_class, "restart", "()V");
|
||||
|
@ -94,6 +86,7 @@ GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_
|
|||
_enable_immersive_mode = p_env->GetMethodID(godot_class, "nativeEnableImmersiveMode", "(Z)V");
|
||||
_is_in_immersive_mode = p_env->GetMethodID(godot_class, "isInImmersiveMode", "()Z");
|
||||
_on_editor_workspace_selected = p_env->GetMethodID(godot_class, "nativeOnEditorWorkspaceSelected", "(Ljava/lang/String;)V");
|
||||
_get_activity = p_env->GetMethodID(godot_class, "getActivity", "()Landroid/app/Activity;");
|
||||
}
|
||||
|
||||
GodotJavaWrapper::~GodotJavaWrapper() {
|
||||
|
@ -105,12 +98,16 @@ GodotJavaWrapper::~GodotJavaWrapper() {
|
|||
ERR_FAIL_NULL(env);
|
||||
env->DeleteGlobalRef(godot_instance);
|
||||
env->DeleteGlobalRef(godot_class);
|
||||
env->DeleteGlobalRef(activity);
|
||||
env->DeleteGlobalRef(activity_class);
|
||||
}
|
||||
|
||||
jobject GodotJavaWrapper::get_activity() {
|
||||
return activity;
|
||||
if (_get_activity) {
|
||||
JNIEnv *env = get_jni_env();
|
||||
ERR_FAIL_NULL_V(env, nullptr);
|
||||
jobject activity = env->CallObjectMethod(godot_instance, _get_activity);
|
||||
return activity;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GodotJavaViewWrapper *GodotJavaWrapper::get_godot_view() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue