You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Merge pull request #101050 from jamie-pate/fix_android_godot_app_create_instance
Fix create_instance in android GodotApp so non-editor apps can restart
This commit is contained in:
@@ -71,8 +71,6 @@ abstract class BaseGodotEditor : GodotActivity() {
|
|||||||
|
|
||||||
private const val WAIT_FOR_DEBUGGER = false
|
private const val WAIT_FOR_DEBUGGER = false
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
protected val EXTRA_COMMAND_LINE_PARAMS = "command_line_params"
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
protected val EXTRA_PIP_AVAILABLE = "pip_available"
|
protected val EXTRA_PIP_AVAILABLE = "pip_available"
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@@ -130,7 +128,6 @@ abstract class BaseGodotEditor : GodotActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val editorMessageDispatcher = EditorMessageDispatcher(this)
|
private val editorMessageDispatcher = EditorMessageDispatcher(this)
|
||||||
private val commandLineParams = ArrayList<String>()
|
|
||||||
private val editorLoadingIndicator: View? by lazy { findViewById(R.id.editor_loading_indicator) }
|
private val editorLoadingIndicator: View? by lazy { findViewById(R.id.editor_loading_indicator) }
|
||||||
|
|
||||||
override fun getGodotAppLayout() = R.layout.godot_editor_layout
|
override fun getGodotAppLayout() = R.layout.godot_editor_layout
|
||||||
@@ -183,10 +180,6 @@ abstract class BaseGodotEditor : GodotActivity() {
|
|||||||
// requested on demand based on use cases.
|
// requested on demand based on use cases.
|
||||||
PermissionsUtil.requestManifestPermissions(this, getExcludedPermissions())
|
PermissionsUtil.requestManifestPermissions(this, getExcludedPermissions())
|
||||||
|
|
||||||
val params = intent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS)
|
|
||||||
Log.d(TAG, "Starting intent $intent with parameters ${params.contentToString()}")
|
|
||||||
updateCommandLineParams(params?.asList() ?: emptyList())
|
|
||||||
|
|
||||||
editorMessageDispatcher.parseStartIntent(packageManager, intent)
|
editorMessageDispatcher.parseStartIntent(packageManager, intent)
|
||||||
|
|
||||||
if (BuildConfig.BUILD_TYPE == "dev" && WAIT_FOR_DEBUGGER) {
|
if (BuildConfig.BUILD_TYPE == "dev" && WAIT_FOR_DEBUGGER) {
|
||||||
@@ -219,20 +212,16 @@ abstract class BaseGodotEditor : GodotActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
protected open fun updateCommandLineParams(args: List<String>) {
|
protected override fun updateCommandLineParams(args: Array<String>) {
|
||||||
// Update the list of command line params with the new args
|
val args = if (BuildConfig.BUILD_TYPE == "dev") {
|
||||||
commandLineParams.clear()
|
args + "--benchmark"
|
||||||
if (args.isNotEmpty()) {
|
} else {
|
||||||
commandLineParams.addAll(args)
|
args
|
||||||
}
|
|
||||||
if (BuildConfig.BUILD_TYPE == "dev") {
|
|
||||||
commandLineParams.add("--benchmark")
|
|
||||||
}
|
}
|
||||||
|
super.updateCommandLineParams(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
final override fun getCommandLine() = commandLineParams
|
protected open fun retrieveEditorWindowInfo(args: Array<String>): EditorWindowInfo {
|
||||||
|
|
||||||
protected fun retrieveEditorWindowInfo(args: Array<String>): EditorWindowInfo {
|
|
||||||
var hasEditor = false
|
var hasEditor = false
|
||||||
var xrMode = XR_MODE_DEFAULT
|
var xrMode = XR_MODE_DEFAULT
|
||||||
|
|
||||||
@@ -335,14 +324,7 @@ abstract class BaseGodotEditor : GodotActivity() {
|
|||||||
val newInstance = getNewGodotInstanceIntent(editorWindowInfo, args)
|
val newInstance = getNewGodotInstanceIntent(editorWindowInfo, args)
|
||||||
if (editorWindowInfo.windowClassName == javaClass.name) {
|
if (editorWindowInfo.windowClassName == javaClass.name) {
|
||||||
Log.d(TAG, "Restarting ${editorWindowInfo.windowClassName} with parameters ${args.contentToString()}")
|
Log.d(TAG, "Restarting ${editorWindowInfo.windowClassName} with parameters ${args.contentToString()}")
|
||||||
val godot = godot
|
triggerRebirth(activityOptions?.toBundle(), newInstance)
|
||||||
if (godot != null) {
|
|
||||||
godot.destroyAndKillProcess {
|
|
||||||
ProcessPhoenix.triggerRebirth(this, activityOptions?.toBundle(), newInstance)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ProcessPhoenix.triggerRebirth(this, activityOptions?.toBundle(), newInstance)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Starting ${editorWindowInfo.windowClassName} with parameters ${args.contentToString()}")
|
Log.d(TAG, "Starting ${editorWindowInfo.windowClassName} with parameters ${args.contentToString()}")
|
||||||
newInstance.putExtra(EXTRA_NEW_LAUNCH, true)
|
newInstance.putExtra(EXTRA_NEW_LAUNCH, true)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ open class GodotXRGame: GodotGame() {
|
|||||||
|
|
||||||
override fun overrideOrientationRequest() = true
|
override fun overrideOrientationRequest() = true
|
||||||
|
|
||||||
override fun updateCommandLineParams(args: List<String>) {
|
override fun updateCommandLineParams(args: Array<String>) {
|
||||||
val updatedArgs = ArrayList<String>()
|
val updatedArgs = ArrayList<String>()
|
||||||
if (!args.contains(XRMode.OPENXR.cmdLineArg)) {
|
if (!args.contains(XRMode.OPENXR.cmdLineArg)) {
|
||||||
updatedArgs.add(XRMode.OPENXR.cmdLineArg)
|
updatedArgs.add(XRMode.OPENXR.cmdLineArg)
|
||||||
@@ -51,7 +51,7 @@ open class GodotXRGame: GodotGame() {
|
|||||||
}
|
}
|
||||||
updatedArgs.addAll(args)
|
updatedArgs.addAll(args)
|
||||||
|
|
||||||
super.updateCommandLineParams(updatedArgs)
|
super.updateCommandLineParams(updatedArgs.toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getEditorWindowInfo() = XR_RUN_GAME_INFO
|
override fun getEditorWindowInfo() = XR_RUN_GAME_INFO
|
||||||
|
|||||||
@@ -823,9 +823,26 @@ class Godot(private val context: Context) {
|
|||||||
* Returns true if `Vulkan` is used for rendering.
|
* Returns true if `Vulkan` is used for rendering.
|
||||||
*/
|
*/
|
||||||
private fun usesVulkan(): Boolean {
|
private fun usesVulkan(): Boolean {
|
||||||
val renderer = GodotLib.getGlobal("rendering/renderer/rendering_method")
|
var rendererSource = "ProjectSettings"
|
||||||
val renderingDevice = GodotLib.getGlobal("rendering/rendering_device/driver")
|
var renderer = GodotLib.getGlobal("rendering/renderer/rendering_method")
|
||||||
return ("forward_plus" == renderer || "mobile" == renderer) && "vulkan" == renderingDevice
|
var renderingDeviceSource = "ProjectSettings"
|
||||||
|
var renderingDevice = GodotLib.getGlobal("rendering/rendering_device/driver")
|
||||||
|
val cmdline = getCommandLine()
|
||||||
|
var index = cmdline.indexOf("--rendering-method")
|
||||||
|
if (index > -1 && cmdline.size > index + 1) {
|
||||||
|
rendererSource = "CommandLine"
|
||||||
|
renderer = cmdline.get(index + 1)
|
||||||
|
}
|
||||||
|
index = cmdline.indexOf("--rendering-driver")
|
||||||
|
if (index > -1 && cmdline.size > index + 1) {
|
||||||
|
renderingDeviceSource = "CommandLine"
|
||||||
|
renderingDevice = cmdline.get(index + 1)
|
||||||
|
}
|
||||||
|
val result = ("forward_plus" == renderer || "mobile" == renderer) && "vulkan" == renderingDevice
|
||||||
|
Log.d(TAG, """usesVulkan(): ${result}
|
||||||
|
renderingDevice: ${renderingDevice} (${renderingDeviceSource})
|
||||||
|
renderer: ${renderer} (${rendererSource})""")
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
package org.godotengine.godot
|
package org.godotengine.godot
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.ComponentName
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -52,18 +53,32 @@ abstract class GodotActivity : FragmentActivity(), GodotHost {
|
|||||||
companion object {
|
companion object {
|
||||||
private val TAG = GodotActivity::class.java.simpleName
|
private val TAG = GodotActivity::class.java.simpleName
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
protected val EXTRA_COMMAND_LINE_PARAMS = "command_line_params"
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
protected val EXTRA_NEW_LAUNCH = "new_launch_requested"
|
protected val EXTRA_NEW_LAUNCH = "new_launch_requested"
|
||||||
|
|
||||||
|
// This window must not match those in BaseGodotEditor.RUN_GAME_INFO etc
|
||||||
|
@JvmStatic
|
||||||
|
private final val DEFAULT_WINDOW_ID = 664;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val commandLineParams = ArrayList<String>()
|
||||||
/**
|
/**
|
||||||
* Interaction with the [Godot] object is delegated to the [GodotFragment] class.
|
* Interaction with the [Godot] object is delegated to the [GodotFragment] class.
|
||||||
*/
|
*/
|
||||||
protected var godotFragment: GodotFragment? = null
|
protected var godotFragment: GodotFragment? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
val params = intent.getStringArrayExtra(EXTRA_COMMAND_LINE_PARAMS)
|
||||||
|
Log.d(TAG, "Starting intent $intent with parameters ${params.contentToString()}")
|
||||||
|
updateCommandLineParams(params ?: emptyArray())
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
setContentView(getGodotAppLayout())
|
setContentView(getGodotAppLayout())
|
||||||
|
|
||||||
handleStartIntent(intent, true)
|
handleStartIntent(intent, true)
|
||||||
@@ -79,6 +94,29 @@ abstract class GodotActivity : FragmentActivity(), GodotHost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onNewGodotInstanceRequested(args: Array<String>): Int {
|
||||||
|
Log.d(TAG, "Restarting with parameters ${args.contentToString()}")
|
||||||
|
val intent = Intent()
|
||||||
|
.setComponent(ComponentName(this, javaClass.name))
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
.putExtra(EXTRA_COMMAND_LINE_PARAMS, args)
|
||||||
|
triggerRebirth(null, intent)
|
||||||
|
// fake 'process' id returned by create_instance() etc
|
||||||
|
return DEFAULT_WINDOW_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun triggerRebirth(bundle: Bundle?, intent: Intent) {
|
||||||
|
// Launch a new activity
|
||||||
|
val godot = godot
|
||||||
|
if (godot != null) {
|
||||||
|
godot.destroyAndKillProcess {
|
||||||
|
ProcessPhoenix.triggerRebirth(this, bundle, intent)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ProcessPhoenix.triggerRebirth(this, bundle, intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@LayoutRes
|
@LayoutRes
|
||||||
protected open fun getGodotAppLayout() = R.layout.godot_app_layout
|
protected open fun getGodotAppLayout() = R.layout.godot_app_layout
|
||||||
|
|
||||||
@@ -176,4 +214,15 @@ abstract class GodotActivity : FragmentActivity(), GodotHost {
|
|||||||
protected open fun initGodotInstance(): GodotFragment {
|
protected open fun initGodotInstance(): GodotFragment {
|
||||||
return GodotFragment()
|
return GodotFragment()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
protected open fun updateCommandLineParams(args: Array<String>) {
|
||||||
|
// Update the list of command line params with the new args
|
||||||
|
commandLineParams.clear()
|
||||||
|
if (args.isNotEmpty()) {
|
||||||
|
commandLineParams.addAll(args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final override fun getCommandLine() = commandLineParams
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user