You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-14 13:41:12 +00:00
Restart game on GL context loss on Android
Bonus: Remove useless old code about reload hooks Fixes #22955.
This commit is contained in:
@@ -38,6 +38,7 @@ import android.app.AlertDialog;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@@ -318,6 +319,23 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
});
|
||||
}
|
||||
|
||||
public void restart() {
|
||||
// HACK:
|
||||
//
|
||||
// Currently it's very hard to properly deinitialize Godot on Android to restart the game
|
||||
// from scratch. Therefore, we need to kill the whole app process and relaunch it.
|
||||
//
|
||||
// Restarting only the activity, wouldn't be enough unless it did proper cleanup (including
|
||||
// releasing and reloading native libs or resetting their state somehow and clearing statics).
|
||||
//
|
||||
// Using instrumentation is a way of making the whole app process restart, because Android
|
||||
// will kill any process of the same package which was already running.
|
||||
//
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable("intent", mCurrentIntent);
|
||||
startInstrumentation(new ComponentName(Godot.this, GodotInstrumentation.class), null, args);
|
||||
}
|
||||
|
||||
public void alert(final String message, final String title) {
|
||||
final Activity activity = this;
|
||||
runOnUiThread(new Runnable() {
|
||||
@@ -415,7 +433,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
|
||||
mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME);
|
||||
|
||||
GodotLib.initialize(this, io.needsReloadHooks(), getAssets(), use_apk_expansion);
|
||||
GodotLib.initialize(this, getAssets(), use_apk_expansion);
|
||||
|
||||
result_callback = null;
|
||||
|
||||
@@ -921,10 +939,10 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
|
||||
// Audio
|
||||
|
||||
/**
|
||||
* The download state should trigger changes in the UI --- it may be useful
|
||||
* to show the state as being indeterminate at times. This sample can be
|
||||
* considered a guideline.
|
||||
*/
|
||||
* The download state should trigger changes in the UI --- it may be useful
|
||||
* to show the state as being indeterminate at times. This sample can be
|
||||
* considered a guideline.
|
||||
*/
|
||||
@Override
|
||||
public void onDownloadStateChanged(int newState) {
|
||||
setState(newState);
|
||||
|
||||
@@ -500,11 +500,6 @@ public class GodotIO {
|
||||
return (int)(metrics.density * 160f);
|
||||
}
|
||||
|
||||
public boolean needsReloadHooks() {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showKeyboard(String p_existing_text) {
|
||||
if (edit != null)
|
||||
edit.showKeyboard(p_existing_text);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*************************************************************************/
|
||||
/* GodotInstrumentation.java */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
package org.godotengine.godot;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class GodotInstrumentation extends Instrumentation {
|
||||
private Intent intent;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle arguments) {
|
||||
intent = arguments.getParcelable("intent");
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
startActivitySync(intent);
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,9 @@ public class GodotLib {
|
||||
* @param height the current view height
|
||||
*/
|
||||
|
||||
public static native void initialize(Godot p_instance, boolean need_reload_hook, Object p_asset_manager, boolean use_apk_expansion);
|
||||
public static native void initialize(Godot p_instance, Object p_asset_manager, boolean use_apk_expansion);
|
||||
public static native void setup(String[] p_cmdline);
|
||||
public static native void resize(int width, int height, boolean reload);
|
||||
public static native void resize(int width, int height);
|
||||
public static native void newcontext(boolean p_32_bits);
|
||||
public static native void back();
|
||||
public static native void step();
|
||||
|
||||
@@ -79,7 +79,6 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
private Context ctx;
|
||||
|
||||
private GodotIO io;
|
||||
private static boolean firsttime = true;
|
||||
private static boolean use_gl3 = false;
|
||||
private static boolean use_32 = false;
|
||||
private static boolean use_debug_opengl = false;
|
||||
@@ -97,10 +96,8 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
|
||||
activity = p_activity;
|
||||
|
||||
if (!p_io.needsReloadHooks()) {
|
||||
//will only work on SDK 11+!!
|
||||
setPreserveEGLContextOnPause(true);
|
||||
}
|
||||
setPreserveEGLContextOnPause(true);
|
||||
|
||||
mInputManager = InputManagerCompat.Factory.getInputManager(this.getContext());
|
||||
mInputManager.registerInputDeviceListener(this, null);
|
||||
init(false, 16, 0);
|
||||
@@ -718,8 +715,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {
|
||||
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height) {
|
||||
|
||||
GodotLib.resize(width, height, !firsttime);
|
||||
firsttime = false;
|
||||
GodotLib.resize(width, height);
|
||||
for (int i = 0; i < Godot.singleton_count; i++) {
|
||||
Godot.singletons[i].onGLSurfaceChanged(gl, width, height);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user