diff options
Diffstat (limited to 'platform/android/java/lib')
39 files changed, 675 insertions, 282 deletions
diff --git a/platform/android/java/lib/AndroidManifest.xml b/platform/android/java/lib/AndroidManifest.xml index fa39bc0f1d..3034794d69 100644 --- a/platform/android/java/lib/AndroidManifest.xml +++ b/platform/android/java/lib/AndroidManifest.xml @@ -6,6 +6,11 @@      <application> +        <!-- Records the version of the Godot library --> +        <meta-data +            android:name="org.godotengine.library.version" +            android:value="${godotLibraryVersion}" /> +          <service android:name=".GodotDownloaderService" />      </application> diff --git a/platform/android/java/lib/build.gradle b/platform/android/java/lib/build.gradle index e3c5a02203..663ba73d40 100644 --- a/platform/android/java/lib/build.gradle +++ b/platform/android/java/lib/build.gradle @@ -13,9 +13,13 @@ android {      compileSdkVersion versions.compileSdk      buildToolsVersion versions.buildTools +    ndkVersion versions.ndkVersion +      defaultConfig {          minSdkVersion versions.minSdk          targetSdkVersion versions.targetSdk + +        manifestPlaceholders = [godotLibraryVersion: getGodotLibraryVersion()]      }      compileOptions { @@ -32,8 +36,10 @@ android {          exclude 'META-INF/LICENSE'          exclude 'META-INF/NOTICE' -        // Should be uncommented for development purpose within Android Studio -        // doNotStrip '**/*.so' +        // 'doNotStrip' is enabled for development within Android Studio +        if (shouldNotStrip()) { +            doNotStrip '**/*.so' +        }      }      sourceSets { @@ -64,10 +70,42 @@ android {              throw new GradleException("Invalid default abi: " + defaultAbi)          } +        // Find scons' executable path +        File sconsExecutableFile = null +        def sconsName = "scons" +        def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows() +            ? [".bat", ".cmd", ".ps1", ".exe"] +            : [""]) +        logger.lifecycle("Looking for $sconsName executable path") +        for (ext in sconsExts) { +            String sconsNameExt = sconsName + ext +            logger.lifecycle("Checking $sconsNameExt") + +            sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt) +            if (sconsExecutableFile != null) { +                // We're done! +                break +            } + +            // Check all the options in path +            List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt) +            if (!allOptions.isEmpty()) { +                // Pick the first option and we're done! +                sconsExecutableFile = allOptions.get(0) +                break +            } +        } + +        if (sconsExecutableFile == null) { +            throw new GradleException("Unable to find executable path for the '$sconsName' command.") +        } else { +            logger.lifecycle("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}") +        } +          // Creating gradle task to generate the native libraries for the default abi.          def taskName = getSconsTaskName(buildType)          tasks.create(name: taskName, type: Exec) { -            executable "scons" + sconsExt +            executable sconsExecutableFile.absolutePath              args "--directory=${pathToRootDir}", "platform=android", "target=${releaseTarget}", "android_arch=${defaultAbi}", "-j" + Runtime.runtime.availableProcessors()          } diff --git a/platform/android/java/lib/src/org/godotengine/godot/Dictionary.java b/platform/android/java/lib/src/org/godotengine/godot/Dictionary.java index 8b7a9c6c74..0572cf3589 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Dictionary.java +++ b/platform/android/java/lib/src/org/godotengine/godot/Dictionary.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java b/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java index 5aa48d87da..ec2ace4821 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java +++ b/platform/android/java/lib/src/org/godotengine/godot/FullScreenGodotApp.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -34,6 +34,7 @@ import android.content.Intent;  import android.os.Bundle;  import android.view.KeyEvent; +import androidx.annotation.CallSuper;  import androidx.annotation.NonNull;  import androidx.annotation.Nullable;  import androidx.fragment.app.FragmentActivity; @@ -44,7 +45,7 @@ import androidx.fragment.app.FragmentActivity;   * It's also a reference implementation for how to setup and use the {@link Godot} fragment   * within an Android app.   */ -public abstract class FullScreenGodotApp extends FragmentActivity { +public abstract class FullScreenGodotApp extends FragmentActivity implements GodotHost {  	@Nullable  	private Godot godotFragment; @@ -64,6 +65,28 @@ public abstract class FullScreenGodotApp extends FragmentActivity {  	public void onNewIntent(Intent intent) {  		if (godotFragment != null) {  			godotFragment.onNewIntent(intent); +		} else { +			super.onNewIntent(intent); +		} +	} + +	@CallSuper +	@Override +	public void onActivityResult(int requestCode, int resultCode, Intent data) { +		if (godotFragment != null) { +			godotFragment.onActivityResult(requestCode, resultCode, data); +		} else { +			super.onActivityResult(requestCode, resultCode, data); +		} +	} + +	@CallSuper +	@Override +	public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { +		if (godotFragment != null) { +			godotFragment.onRequestPermissionsResult(requestCode, permissions, grantResults); +		} else { +			super.onRequestPermissionsResult(requestCode, permissions, grantResults);  		}  	} diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java index 6cf340c418..0c16214c8a 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -103,6 +103,7 @@ import java.io.File;  import java.io.FileInputStream;  import java.io.InputStream;  import java.security.MessageDigest; +import java.util.Arrays;  import java.util.LinkedList;  import java.util.List;  import java.util.Locale; @@ -131,6 +132,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  	private boolean activityResumed;  	private int mState; +	private GodotHost godotHost;  	private GodotPluginRegistry pluginRegistry;  	static private Intent mCurrentIntent; @@ -178,7 +180,25 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  	public ResultCallback result_callback;  	@Override +	public void onAttach(Context context) { +		super.onAttach(context); +		if (getParentFragment() instanceof GodotHost) { +			godotHost = (GodotHost)getParentFragment(); +		} else if (getActivity() instanceof GodotHost) { +			godotHost = (GodotHost)getActivity(); +		} +	} + +	@Override +	public void onDetach() { +		super.onDetach(); +		godotHost = null; +	} + +	@CallSuper +	@Override  	public void onActivityResult(int requestCode, int resultCode, Intent data) { +		super.onActivityResult(requestCode, resultCode, data);  		if (result_callback != null) {  			result_callback.callback(requestCode, resultCode, data);  			result_callback = null; @@ -189,8 +209,10 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  		}  	} +	@CallSuper  	@Override  	public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { +		super.onRequestPermissionsResult(requestCode, permissions, grantResults);  		for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {  			plugin.onMainRequestPermissionsResult(requestCode, permissions, grantResults);  		} @@ -201,6 +223,20 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  	};  	/** +	 * Invoked on the render thread when the Godot setup is complete. +	 */ +	@CallSuper +	protected void onGodotSetupCompleted() { +		for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) { +			plugin.onGodotSetupCompleted(); +		} + +		if (godotHost != null) { +			godotHost.onGodotSetupCompleted(); +		} +	} + +	/**  	 * Invoked on the render thread when the Godot main loop has started.  	 */  	@CallSuper @@ -208,6 +244,10 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  		for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {  			plugin.onGodotMainLoopStarted();  		} + +		if (godotHost != null) { +			godotHost.onGodotMainLoopStarted(); +		}  	}  	/** @@ -228,7 +268,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  		GodotLib.setup(command_line); -		final String videoDriver = GodotLib.getGlobal("rendering/quality/driver/driver_name"); +		final String videoDriver = GodotLib.getGlobal("rendering/driver/driver_name");  		if (videoDriver.equals("Vulkan")) {  			mRenderView = new GodotVulkanRenderView(activity, this);  		} else { @@ -301,7 +341,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  				if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {  					v.vibrate(VibrationEffect.createOneShot(durationMs, VibrationEffect.DEFAULT_AMPLITUDE));  				} else { -					//deprecated in API 26 +					// deprecated in API 26  					v.vibrate(durationMs);  				}  			} @@ -356,6 +396,21 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  	@CallSuper  	protected String[] getCommandLine() { +		String[] original = parseCommandLine(); +		String[] updated; +		List<String> hostCommandLine = godotHost != null ? godotHost.getCommandLine() : null; +		if (hostCommandLine == null || hostCommandLine.isEmpty()) { +			updated = original; +		} else { +			updated = Arrays.copyOf(original, original.length + hostCommandLine.size()); +			for (int i = 0; i < hostCommandLine.size(); i++) { +				updated[original.length + i] = hostCommandLine.get(i); +			} +		} +		return updated; +	} + +	private String[] parseCommandLine() {  		InputStream is;  		try {  			is = getActivity().getAssets().open("_cl_"); @@ -464,14 +519,16 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  	}  	@Override -	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) { +	public void onCreate(Bundle icicle) { +		super.onCreate(icicle); +  		final Activity activity = getActivity();  		Window window = activity.getWindow();  		window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);  		mClipboard = (ClipboardManager)activity.getSystemService(Context.CLIPBOARD_SERVICE);  		pluginRegistry = GodotPluginRegistry.initializePluginRegistry(this); -		//check for apk expansion API +		// check for apk expansion API  		boolean md5mismatch = false;  		command_line = getCommandLine();  		String main_pack_md5 = null; @@ -527,9 +584,9 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  			command_line = new_args.toArray(new String[new_args.size()]);  		}  		if (use_apk_expansion && main_pack_md5 != null && main_pack_key != null) { -			//check that environment is ok! +			// check that environment is ok!  			if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { -				//show popup and die +				// show popup and die  			}  			// Build the full path to the app's expansion files @@ -572,24 +629,11 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  					if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {  						// This is where you do set up to display the download -						// progress (next step) +						// progress (next step in onCreateView)  						mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this,  								GodotDownloaderService.class); -						View downloadingExpansionView = -								inflater.inflate(R.layout.downloading_expansion, container, false); -						mPB = (ProgressBar)downloadingExpansionView.findViewById(R.id.progressBar); -						mStatusText = (TextView)downloadingExpansionView.findViewById(R.id.statusText); -						mProgressFraction = (TextView)downloadingExpansionView.findViewById(R.id.progressAsFraction); -						mProgressPercent = (TextView)downloadingExpansionView.findViewById(R.id.progressAsPercentage); -						mAverageSpeed = (TextView)downloadingExpansionView.findViewById(R.id.progressAverageSpeed); -						mTimeRemaining = (TextView)downloadingExpansionView.findViewById(R.id.progressTimeRemaining); -						mDashboard = downloadingExpansionView.findViewById(R.id.downloaderDashboard); -						mCellMessage = downloadingExpansionView.findViewById(R.id.approveCellular); -						mPauseButton = (Button)downloadingExpansionView.findViewById(R.id.pauseButton); -						mWiFiSettingsButton = (Button)downloadingExpansionView.findViewById(R.id.wifiSettingsButton); - -						return downloadingExpansionView; +						return;  					}  				} catch (NameNotFoundException e) {  					// TODO Auto-generated catch block @@ -600,6 +644,27 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  		mCurrentIntent = activity.getIntent();  		initializeGodot(); +	} + +	@Override +	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) { +		if (mDownloaderClientStub != null) { +			View downloadingExpansionView = +					inflater.inflate(R.layout.downloading_expansion, container, false); +			mPB = (ProgressBar)downloadingExpansionView.findViewById(R.id.progressBar); +			mStatusText = (TextView)downloadingExpansionView.findViewById(R.id.statusText); +			mProgressFraction = (TextView)downloadingExpansionView.findViewById(R.id.progressAsFraction); +			mProgressPercent = (TextView)downloadingExpansionView.findViewById(R.id.progressAsPercentage); +			mAverageSpeed = (TextView)downloadingExpansionView.findViewById(R.id.progressAverageSpeed); +			mTimeRemaining = (TextView)downloadingExpansionView.findViewById(R.id.progressTimeRemaining); +			mDashboard = downloadingExpansionView.findViewById(R.id.downloaderDashboard); +			mCellMessage = downloadingExpansionView.findViewById(R.id.approveCellular); +			mPauseButton = (Button)downloadingExpansionView.findViewById(R.id.pauseButton); +			mWiFiSettingsButton = (Button)downloadingExpansionView.findViewById(R.id.wifiSettingsButton); + +			return downloadingExpansionView; +		} +  		return containerLayout;  	} @@ -760,9 +825,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  	/*  	@Override public boolean dispatchKeyEvent(KeyEvent event) { -  		if (event.getKeyCode()==KeyEvent.KEYCODE_BACK) { -  			System.out.printf("** BACK REQUEST!\n");  			GodotLib.quit(); @@ -990,4 +1053,9 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  	public void initInputDevices() {  		mRenderView.initInputDevices();  	} + +	@Keep +	private GodotRenderView getRenderView() { // used by native side to get renderView +		return mRenderView; +	}  } diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotDownloaderAlarmReceiver.java b/platform/android/java/lib/src/org/godotengine/godot/GodotDownloaderAlarmReceiver.java index a3dae15980..9784d51182 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotDownloaderAlarmReceiver.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotDownloaderAlarmReceiver.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotDownloaderService.java b/platform/android/java/lib/src/org/godotengine/godot/GodotDownloaderService.java index 434da95bc0..d33faab641 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotDownloaderService.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotDownloaderService.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java index d731e080c4..63c91561ff 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -144,6 +144,11 @@ public class GodotGLRenderView extends GLSurfaceView implements GodotRenderView  		return inputHandler.onGenericMotionEvent(event) || super.onGenericMotionEvent(event);  	} +	@Override +	public boolean onCapturedPointerEvent(MotionEvent event) { +		return inputHandler.onGenericMotionEvent(event); +	} +  	private void init(XRMode xrMode, boolean translucent, int depth, int stencil) {  		setPreserveEGLContextOnPause(true);  		setFocusableInTouchMode(true); @@ -183,15 +188,15 @@ public class GodotGLRenderView extends GLSurfaceView implements GodotRenderView  				if (GLUtils.use_32) {  					setEGLConfigChooser(translucent ? -												new RegularFallbackConfigChooser(8, 8, 8, 8, 24, stencil, +												  new RegularFallbackConfigChooser(8, 8, 8, 8, 24, stencil,  														new RegularConfigChooser(8, 8, 8, 8, 16, stencil)) : -												new RegularFallbackConfigChooser(8, 8, 8, 8, 24, stencil, +												  new RegularFallbackConfigChooser(8, 8, 8, 8, 24, stencil,  														new RegularConfigChooser(5, 6, 5, 0, 16, stencil)));  				} else {  					setEGLConfigChooser(translucent ? -												new RegularConfigChooser(8, 8, 8, 8, 16, stencil) : -												new RegularConfigChooser(5, 6, 5, 0, 16, stencil)); +												  new RegularConfigChooser(8, 8, 8, 8, 16, stencil) : +												  new RegularConfigChooser(5, 6, 5, 0, 16, stencil));  				}  				break;  		} diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotHost.java b/platform/android/java/lib/src/org/godotengine/godot/GodotHost.java new file mode 100644 index 0000000000..317fd13535 --- /dev/null +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotHost.java @@ -0,0 +1,56 @@ +/*************************************************************************/ +/*  GodotHost.java                                                       */ +/*************************************************************************/ +/*                       This file is part of:                           */ +/*                           GODOT ENGINE                                */ +/*                      https://godotengine.org                          */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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 java.util.Collections; +import java.util.List; + +/** + * Denotate a component (e.g: Activity, Fragment) that hosts the {@link Godot} fragment. + */ +public interface GodotHost { +	/** +	 * Provides a set of command line parameters to setup the engine. +	 */ +	default List<String> getCommandLine() { +		return Collections.emptyList(); +	} + +	/** +	 * Invoked on the render thread when the Godot setup is complete. +	 */ +	default void onGodotSetupCompleted() {} + +	/** +	 * Invoked on the render thread when the Godot main loop has started. +	 */ +	default void onGodotMainLoopStarted() {} +} diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java index 874fd88848..c7c7c1b40c 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -515,13 +515,13 @@ public class GodotIO {  				activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);  			} break;  			case SCREEN_SENSOR_LANDSCAPE: { -				activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); +				activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE);  			} break;  			case SCREEN_SENSOR_PORTRAIT: { -				activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); +				activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);  			} break;  			case SCREEN_SENSOR: { -				activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); +				activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER);  			} break;  		}  	} diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotInstrumentation.java b/platform/android/java/lib/src/org/godotengine/godot/GodotInstrumentation.java index 965e616ef3..7f5fd8627c 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotInstrumentation.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotInstrumentation.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java index 6ccbe91e60..534a50e9ed 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java index 68b8a16641..2047c88070 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java index 64395f7d1e..59bdbf7f8d 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java index 6cd5ca7b4e..2e59dbc0d0 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -120,6 +120,11 @@ public class GodotVulkanRenderView extends VkSurfaceView implements GodotRenderV  	}  	@Override +	public boolean onCapturedPointerEvent(MotionEvent event) { +		return mInputHandler.onGenericMotionEvent(event); +	} + +	@Override  	public void onResume() {  		super.onResume(); diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java index c95339c583..d1e8ae5ca9 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java index fb151fa504..2c39d06832 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java index f3e985f944..435b8b325f 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -38,6 +38,8 @@ import org.godotengine.godot.input.InputManagerCompat.InputDeviceListener;  import android.os.Build;  import android.util.Log; +import android.util.SparseArray; +import android.util.SparseIntArray;  import android.view.InputDevice;  import android.view.InputDevice.MotionRange;  import android.view.KeyEvent; @@ -46,17 +48,24 @@ import android.view.MotionEvent;  import java.util.ArrayList;  import java.util.Collections;  import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet;  import java.util.List; +import java.util.Map; +import java.util.Set;  /**   * Handles input related events for the {@link GodotRenderView} view.   */  public class GodotInputHandler implements InputDeviceListener { -	private final ArrayList<Joystick> mJoysticksDevices = new ArrayList<Joystick>(); -  	private final GodotRenderView mRenderView;  	private final InputManagerCompat mInputManager; +	private final String tag = this.getClass().getSimpleName(); + +	private final SparseIntArray mJoystickIds = new SparseIntArray(4); +	private final SparseArray<Joystick> mJoysticksDevices = new SparseArray<Joystick>(4); +  	public GodotInputHandler(GodotRenderView godotView) {  		mRenderView = godotView;  		mInputManager = InputManagerCompat.Factory.getInputManager(mRenderView.getView().getContext()); @@ -82,19 +91,20 @@ public class GodotInputHandler implements InputDeviceListener {  		if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {  			return false; -		}; +		}  		int source = event.getSource();  		if (isKeyEvent_GameDevice(source)) { -			final int button = getGodotButton(keyCode); -			final int device_id = findJoystickDevice(event.getDeviceId()); -  			// Check if the device exists -			if (device_id > -1) { +			final int deviceId = event.getDeviceId(); +			if (mJoystickIds.indexOfKey(deviceId) >= 0) { +				final int button = getGodotButton(keyCode); +				final int godotJoyId = mJoystickIds.get(deviceId); +  				queueEvent(new Runnable() {  					@Override  					public void run() { -						GodotLib.joybutton(device_id, button, false); +						GodotLib.joybutton(godotJoyId, button, false);  					}  				});  			} @@ -107,7 +117,7 @@ public class GodotInputHandler implements InputDeviceListener {  					GodotLib.key(keyCode, scanCode, chr, false);  				}  			}); -		}; +		}  		return true;  	} @@ -122,24 +132,25 @@ public class GodotInputHandler implements InputDeviceListener {  		if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {  			return false; -		}; +		}  		int source = event.getSource();  		//Log.e(TAG, String.format("Key down! source %d, device %d, joystick %d, %d, %d", event.getDeviceId(), source, (source & InputDevice.SOURCE_JOYSTICK), (source & InputDevice.SOURCE_DPAD), (source & InputDevice.SOURCE_GAMEPAD))); +		final int deviceId = event.getDeviceId(); +		// Check if source is a game device and that the device is a registered gamepad  		if (isKeyEvent_GameDevice(source)) {  			if (event.getRepeatCount() > 0) // ignore key echo  				return true; -			final int button = getGodotButton(keyCode); -			final int device_id = findJoystickDevice(event.getDeviceId()); +			if (mJoystickIds.indexOfKey(deviceId) >= 0) { +				final int button = getGodotButton(keyCode); +				final int godotJoyId = mJoystickIds.get(deviceId); -			// Check if the device exists -			if (device_id > -1) {  				queueEvent(new Runnable() {  					@Override  					public void run() { -						GodotLib.joybutton(device_id, button, true); +						GodotLib.joybutton(godotJoyId, button, true);  					}  				});  			} @@ -152,7 +163,7 @@ public class GodotInputHandler implements InputDeviceListener {  					GodotLib.key(keyCode, scanCode, chr, true);  				}  			}); -		}; +		}  		return true;  	} @@ -181,6 +192,7 @@ public class GodotInputHandler implements InputDeviceListener {  				arr[i * 3 + 2] = event.getY(i);  			}  			final int action = event.getActionMasked(); +			final int pointer_idx = event.getPointerId(event.getActionIndex());  			mRenderView.queueOnRenderThread(new Runnable() {  				@Override @@ -189,12 +201,9 @@ public class GodotInputHandler implements InputDeviceListener {  						case MotionEvent.ACTION_DOWN:  						case MotionEvent.ACTION_CANCEL:  						case MotionEvent.ACTION_UP: -						case MotionEvent.ACTION_MOVE: { -							GodotLib.touch(event.getSource(), action, 0, evcount, arr); -						} break; +						case MotionEvent.ACTION_MOVE:  						case MotionEvent.ACTION_POINTER_UP:  						case MotionEvent.ACTION_POINTER_DOWN: { -							int pointer_idx = event.getPointerId(event.getActionIndex());  							GodotLib.touch(event.getSource(), action, pointer_idx, evcount, arr);  						} break;  					} @@ -205,38 +214,52 @@ public class GodotInputHandler implements InputDeviceListener {  	}  	public boolean onGenericMotionEvent(MotionEvent event) { -		if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE) { -			final int device_id = findJoystickDevice(event.getDeviceId()); - +		if (event.isFromSource(InputDevice.SOURCE_JOYSTICK) && event.getAction() == MotionEvent.ACTION_MOVE) {  			// Check if the device exists -			if (device_id > -1) { -				Joystick joy = mJoysticksDevices.get(device_id); - -				for (int i = 0; i < joy.axes.size(); i++) { -					InputDevice.MotionRange range = joy.axes.get(i); -					final float value = (event.getAxisValue(range.getAxis()) - range.getMin()) / range.getRange() * 2.0f - 1.0f; -					final int idx = i; -					queueEvent(new Runnable() { -						@Override -						public void run() { -							GodotLib.joyaxis(device_id, idx, value); -						} -					}); +			final int deviceId = event.getDeviceId(); +			if (mJoystickIds.indexOfKey(deviceId) >= 0) { +				final int godotJoyId = mJoystickIds.get(deviceId); +				Joystick joystick = mJoysticksDevices.get(deviceId); + +				for (int i = 0; i < joystick.axes.size(); i++) { +					final int axis = joystick.axes.get(i); +					final float value = event.getAxisValue(axis); +					/** +					 * As all axes are polled for each event, only fire an axis event if the value has actually changed. +					 * Prevents flooding Godot with repeated events. +					 */ +					if (joystick.axesValues.indexOfKey(axis) < 0 || (float)joystick.axesValues.get(axis) != value) { +						// save value to prevent repeats +						joystick.axesValues.put(axis, value); +						final int godotAxisIdx = i; +						queueEvent(new Runnable() { +							@Override +							public void run() { +								GodotLib.joyaxis(godotJoyId, godotAxisIdx, value); +								//Log.i(tag, "GodotLib.joyaxis("+godotJoyId+", "+godotAxisIdx+", "+value+");"); +							} +						}); +					}  				} -				for (int i = 0; i < joy.hats.size(); i += 2) { -					final int hatX = Math.round(event.getAxisValue(joy.hats.get(i).getAxis())); -					final int hatY = Math.round(event.getAxisValue(joy.hats.get(i + 1).getAxis())); -					queueEvent(new Runnable() { -						@Override -						public void run() { -							GodotLib.joyhat(device_id, hatX, hatY); -						} -					}); +				if (joystick.hasAxisHat) { +					final int hatX = Math.round(event.getAxisValue(MotionEvent.AXIS_HAT_X)); +					final int hatY = Math.round(event.getAxisValue(MotionEvent.AXIS_HAT_Y)); +					if (joystick.hatX != hatX || joystick.hatY != hatY) { +						joystick.hatX = hatX; +						joystick.hatY = hatY; +						queueEvent(new Runnable() { +							@Override +							public void run() { +								GodotLib.joyhat(godotJoyId, hatX, hatY); +								//Log.i(tag, "GodotLib.joyhat("+godotJoyId+", "+hatX+", "+hatY+");"); +							} +						}); +					}  				}  				return true;  			} -		} else if ((event.getSource() & InputDevice.SOURCE_STYLUS) == InputDevice.SOURCE_STYLUS) { +		} else if (event.isFromSource(InputDevice.SOURCE_STYLUS)) {  			final float x = event.getX();  			final float y = event.getY();  			final int type = event.getAction(); @@ -247,7 +270,8 @@ public class GodotInputHandler implements InputDeviceListener {  				}  			});  			return true; -		} else if ((event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) { + +		} else if (event.isFromSource(InputDevice.SOURCE_MOUSE) || event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)) {  			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {  				return handleMouseEvent(event);  			} @@ -268,67 +292,98 @@ public class GodotInputHandler implements InputDeviceListener {  		}  	} +	private int assignJoystickIdNumber(int deviceId) { +		int godotJoyId = 0; +		while (mJoystickIds.indexOfValue(godotJoyId) >= 0) { +			godotJoyId++; +		} +		mJoystickIds.put(deviceId, godotJoyId); +		return godotJoyId; +	} +  	@Override  	public void onInputDeviceAdded(int deviceId) { -		int id = findJoystickDevice(deviceId); -  		// Check if the device has not been already added -		if (id < 0) { -			InputDevice device = mInputManager.getInputDevice(deviceId); -			//device can be null if deviceId is not found -			if (device != null) { -				int sources = device.getSources(); -				if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || -						((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) { -					id = mJoysticksDevices.size(); - -					Joystick joy = new Joystick(); -					joy.device_id = deviceId; -					joy.name = device.getName(); -					joy.axes = new ArrayList<InputDevice.MotionRange>(); -					joy.hats = new ArrayList<InputDevice.MotionRange>(); - -					List<InputDevice.MotionRange> ranges = device.getMotionRanges(); -					Collections.sort(ranges, new RangeComparator()); - -					for (InputDevice.MotionRange range : ranges) { -						if (range.getAxis() == MotionEvent.AXIS_HAT_X || range.getAxis() == MotionEvent.AXIS_HAT_Y) { -							joy.hats.add(range); -						} else { -							joy.axes.add(range); -						} -					} -					mJoysticksDevices.add(joy); +		if (mJoystickIds.indexOfKey(deviceId) >= 0) { +			return; +		} + +		InputDevice device = mInputManager.getInputDevice(deviceId); +		//device can be null if deviceId is not found +		if (device == null) { +			return; +		} + +		int sources = device.getSources(); -					final int device_id = id; -					final String name = joy.name; -					queueEvent(new Runnable() { -						@Override -						public void run() { -							GodotLib.joyconnectionchanged(device_id, true, name); -						} -					}); +		// Device may not be a joystick or gamepad +		if ((sources & InputDevice.SOURCE_GAMEPAD) != InputDevice.SOURCE_GAMEPAD && +				(sources & InputDevice.SOURCE_JOYSTICK) != InputDevice.SOURCE_JOYSTICK) { +			return; +		} + +		// Assign first available number. Re-use numbers where possible. +		final int id = assignJoystickIdNumber(deviceId); + +		final Joystick joystick = new Joystick(); +		joystick.device_id = deviceId; +		joystick.name = device.getName(); + +		//Helps with creating new joypad mappings. +		Log.i(tag, "=== New Input Device: " + joystick.name); + +		Set<Integer> already = new HashSet<Integer>(); +		for (InputDevice.MotionRange range : device.getMotionRanges()) { +			boolean isJoystick = range.isFromSource(InputDevice.SOURCE_JOYSTICK); +			boolean isGamepad = range.isFromSource(InputDevice.SOURCE_GAMEPAD); +			//Log.i(tag, "axis: "+range.getAxis()+ ", isJoystick: "+isJoystick+", isGamepad: "+isGamepad); +			if (!isJoystick && !isGamepad) { +				continue; +			} +			final int axis = range.getAxis(); +			if (axis == MotionEvent.AXIS_HAT_X || axis == MotionEvent.AXIS_HAT_Y) { +				joystick.hasAxisHat = true; +			} else { +				if (!already.contains(axis)) { +					already.add(axis); +					joystick.axes.add(axis); +				} else { +					Log.w(tag, " - DUPLICATE AXIS VALUE IN LIST: " + axis);  				}  			}  		} +		Collections.sort(joystick.axes); +		for (int idx = 0; idx < joystick.axes.size(); idx++) { +			//Helps with creating new joypad mappings. +			Log.i(tag, " - Mapping Android axis " + joystick.axes.get(idx) + " to Godot axis " + idx); +		} +		mJoysticksDevices.put(deviceId, joystick); + +		queueEvent(new Runnable() { +			@Override +			public void run() { +				GodotLib.joyconnectionchanged(id, true, joystick.name); +			} +		});  	}  	@Override  	public void onInputDeviceRemoved(int deviceId) { -		final int device_id = findJoystickDevice(deviceId); - -		// Check if the evice has not been already removed -		if (device_id > -1) { -			mJoysticksDevices.remove(device_id); - -			queueEvent(new Runnable() { -				@Override -				public void run() { -					GodotLib.joyconnectionchanged(device_id, false, ""); -				} -			}); +		// Check if the device has not been already removed +		if (mJoystickIds.indexOfKey(deviceId) < 0) { +			return;  		} +		final int godotJoyId = mJoystickIds.get(deviceId); +		mJoystickIds.delete(deviceId); +		mJoysticksDevices.delete(deviceId); + +		queueEvent(new Runnable() { +			@Override +			public void run() { +				GodotLib.joyconnectionchanged(godotJoyId, false, ""); +			} +		});  	}  	@Override @@ -409,16 +464,6 @@ public class GodotInputHandler implements InputDeviceListener {  		return button;  	} -	private int findJoystickDevice(int device_id) { -		for (int i = 0; i < mJoysticksDevices.size(); i++) { -			if (mJoysticksDevices.get(i).device_id == device_id) { -				return i; -			} -		} - -		return -1; -	} -  	private boolean handleMouseEvent(final MotionEvent event) {  		switch (event.getActionMasked()) {  			case MotionEvent.ACTION_HOVER_ENTER: @@ -464,6 +509,11 @@ public class GodotInputHandler implements InputDeviceListener {  					}  				});  			} +			case MotionEvent.ACTION_DOWN: +			case MotionEvent.ACTION_UP: { +				// we can safely ignore these cases because they are always come beside ACTION_BUTTON_PRESS and ACTION_BUTTON_RELEASE +				return true; +			}  		}  		return false;  	} diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java index 4dd1054738..3e0e6a65fd 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/Joystick.java b/platform/android/java/lib/src/org/godotengine/godot/input/Joystick.java index 1f3fe1e527..4b7318c718 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/Joystick.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/Joystick.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -30,9 +30,10 @@  package org.godotengine.godot.input; -import android.view.InputDevice.MotionRange; +import android.util.SparseArray;  import java.util.ArrayList; +import java.util.List;  /**   * POJO class to represent a Joystick input device. @@ -40,6 +41,12 @@ import java.util.ArrayList;  class Joystick {  	int device_id;  	String name; -	ArrayList<MotionRange> axes; -	ArrayList<MotionRange> hats; +	List<Integer> axes = new ArrayList<Integer>(); +	protected boolean hasAxisHat = false; +	/* +	 * Keep track of values so we can prevent flooding the engine with useless events. +	 */ +	protected final SparseArray axesValues = new SparseArray<Float>(4); +	protected int hatX; +	protected int hatY;  } diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java index 93c204935c..6c8a3d4219 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java +++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -46,7 +46,10 @@ import androidx.annotation.Nullable;  import java.lang.reflect.Method;  import java.util.ArrayList;  import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet;  import java.util.List; +import java.util.Map;  import java.util.Set;  import java.util.concurrent.ConcurrentHashMap; @@ -107,23 +110,52 @@ public abstract class GodotPlugin {  	 * This method is invoked on the render thread.  	 */  	public final void onRegisterPluginWithGodotNative() { -		nativeRegisterSingleton(getPluginName()); +		registeredSignals.putAll( +				registerPluginWithGodotNative(this, getPluginName(), getPluginMethods(), getPluginSignals(), +						getPluginGDNativeLibrariesPaths())); +	} + +	/** +	 * Register the plugin with Godot native code. +	 * +	 * This method must be invoked on the render thread. +	 */ +	public static void registerPluginWithGodotNative(Object pluginObject, +			GodotPluginInfoProvider pluginInfoProvider) { +		registerPluginWithGodotNative(pluginObject, pluginInfoProvider.getPluginName(), +				Collections.emptyList(), pluginInfoProvider.getPluginSignals(), +				pluginInfoProvider.getPluginGDNativeLibrariesPaths()); + +		// Notify that registration is complete. +		pluginInfoProvider.onPluginRegistered(); +	} + +	private static Map<String, SignalInfo> registerPluginWithGodotNative(Object pluginObject, +			String pluginName, List<String> pluginMethods, Set<SignalInfo> pluginSignals, +			Set<String> pluginGDNativeLibrariesPaths) { +		nativeRegisterSingleton(pluginName, pluginObject); + +		Set<Method> filteredMethods = new HashSet<>(); +		Class clazz = pluginObject.getClass(); -		Class clazz = getClass();  		Method[] methods = clazz.getDeclaredMethods();  		for (Method method : methods) { -			boolean found = false; - -			for (String s : getPluginMethods()) { -				if (s.equals(method.getName())) { -					found = true; -					break; +			// Check if the method is annotated with {@link UsedByGodot}. +			if (method.getAnnotation(UsedByGodot.class) != null) { +				filteredMethods.add(method); +			} else { +				// For backward compatibility, process the methods from the given <pluginMethods> argument. +				for (String methodName : pluginMethods) { +					if (methodName.equals(method.getName())) { +						filteredMethods.add(method); +						break; +					}  				}  			} -			if (!found) -				continue; +		} -			List<String> ptr = new ArrayList<String>(); +		for (Method method : filteredMethods) { +			List<String> ptr = new ArrayList<>();  			Class[] paramTypes = method.getParameterTypes();  			for (Class c : paramTypes) { @@ -133,26 +165,28 @@ public abstract class GodotPlugin {  			String[] pt = new String[ptr.size()];  			ptr.toArray(pt); -			nativeRegisterMethod(getPluginName(), method.getName(), method.getReturnType().getName(), pt); +			nativeRegisterMethod(pluginName, method.getName(), method.getReturnType().getName(), pt);  		}  		// Register the signals for this plugin. -		for (SignalInfo signalInfo : getPluginSignals()) { +		Map<String, SignalInfo> registeredSignals = new HashMap<>(); +		for (SignalInfo signalInfo : pluginSignals) {  			String signalName = signalInfo.getName(); -			nativeRegisterSignal(getPluginName(), signalName, signalInfo.getParamTypesNames()); +			nativeRegisterSignal(pluginName, signalName, signalInfo.getParamTypesNames());  			registeredSignals.put(signalName, signalInfo);  		}  		// Get the list of gdnative libraries to register. -		Set<String> gdnativeLibrariesPaths = getPluginGDNativeLibrariesPaths(); -		if (!gdnativeLibrariesPaths.isEmpty()) { -			nativeRegisterGDNativeLibraries(gdnativeLibrariesPaths.toArray(new String[0])); +		if (!pluginGDNativeLibrariesPaths.isEmpty()) { +			nativeRegisterGDNativeLibraries(pluginGDNativeLibrariesPaths.toArray(new String[0]));  		} + +		return registeredSignals;  	}  	/**  	 * Invoked once during the Godot Android initialization process after creation of the -	 * {@link org.godotengine.godot.GodotView} view. +	 * {@link org.godotengine.godot.GodotRenderView} view.  	 * <p>  	 * The plugin can return a non-null {@link View} layout in order to add it to the Godot view  	 * hierarchy. @@ -198,6 +232,11 @@ public abstract class GodotPlugin {  	public boolean onMainBackPressed() { return false; }  	/** +	 * Invoked on the render thread when the Godot setup is complete. +	 */ +	public void onGodotSetupCompleted() {} + +	/**  	 * Invoked on the render thread when the Godot main loop has started.  	 */  	public void onGodotMainLoopStarted() {} @@ -244,8 +283,11 @@ public abstract class GodotPlugin {  	/**  	 * Returns the list of methods to be exposed to Godot. +	 * +	 * @deprecated Used the {@link UsedByGodot} annotation instead.  	 */  	@NonNull +	@Deprecated  	public List<String> getPluginMethods() {  		return Collections.emptyList();  	} @@ -290,8 +332,8 @@ public abstract class GodotPlugin {  	/**  	 * Emit a registered Godot signal. -	 * @param signalName -	 * @param signalArgs +	 * @param signalName Name of the signal to emit. It will be validated against the set of registered signals. +	 * @param signalArgs Arguments used to populate the emitted signal. The arguments will be validated against the {@link SignalInfo} matching the registered signalName parameter.  	 */  	protected void emitSignal(final String signalName, final Object... signalArgs) {  		try { @@ -301,6 +343,27 @@ public abstract class GodotPlugin {  				throw new IllegalArgumentException(  						"Signal " + signalName + " is not registered for this plugin.");  			} +			emitSignal(getGodot(), getPluginName(), signalInfo, signalArgs); +		} catch (IllegalArgumentException exception) { +			Log.w(TAG, exception.getMessage()); +			if (BuildConfig.DEBUG) { +				throw exception; +			} +		} +	} + +	/** +	 * Emit a Godot signal. +	 * @param godot +	 * @param pluginName Name of the Godot plugin the signal will be emitted from. The plugin must already be registered with the Godot engine. +	 * @param signalInfo Information about the signal to emit. +	 * @param signalArgs Arguments used to populate the emitted signal. The arguments will be validated against the given {@link SignalInfo} parameter. +	 */ +	public static void emitSignal(Godot godot, String pluginName, SignalInfo signalInfo, final Object... signalArgs) { +		try { +			if (signalInfo == null) { +				throw new IllegalArgumentException("Signal must be non null."); +			}  			// Validate the arguments count.  			Class<?>[] signalParamTypes = signalInfo.getParamTypes(); @@ -317,12 +380,8 @@ public abstract class GodotPlugin {  				}  			} -			runOnRenderThread(new Runnable() { -				@Override -				public void run() { -					nativeEmitSignal(getPluginName(), signalName, signalArgs); -				} -			}); +			godot.runOnRenderThread(() -> nativeEmitSignal(pluginName, signalInfo.getName(), signalArgs)); +  		} catch (IllegalArgumentException exception) {  			Log.w(TAG, exception.getMessage());  			if (BuildConfig.DEBUG) { @@ -335,7 +394,7 @@ public abstract class GodotPlugin {  	 * Used to setup a {@link GodotPlugin} instance.  	 * @param p_name Name of the instance.  	 */ -	private native void nativeRegisterSingleton(String p_name); +	private static native void nativeRegisterSingleton(String p_name, Object object);  	/**  	 * Used to complete registration of the {@link GodotPlugin} instance's methods. @@ -344,13 +403,13 @@ public abstract class GodotPlugin {  	 * @param p_ret Return type of the registered method  	 * @param p_params Method parameters types  	 */ -	private native void nativeRegisterMethod(String p_sname, String p_name, String p_ret, String[] p_params); +	private static native void nativeRegisterMethod(String p_sname, String p_name, String p_ret, String[] p_params);  	/**  	 * Used to register gdnative libraries bundled by the plugin.  	 * @param gdnlibPaths Paths to the libraries relative to the 'assets' directory.  	 */ -	private native void nativeRegisterGDNativeLibraries(String[] gdnlibPaths); +	private static native void nativeRegisterGDNativeLibraries(String[] gdnlibPaths);  	/**  	 * Used to complete registration of the {@link GodotPlugin} instance's methods. @@ -358,7 +417,7 @@ public abstract class GodotPlugin {  	 * @param signalName Name of the signal to register  	 * @param signalParamTypes Signal parameters types  	 */ -	private native void nativeRegisterSignal(String pluginName, String signalName, String[] signalParamTypes); +	private static native void nativeRegisterSignal(String pluginName, String signalName, String[] signalParamTypes);  	/**  	 * Used to emit signal by {@link GodotPlugin} instance. @@ -366,5 +425,5 @@ public abstract class GodotPlugin {  	 * @param signalName Name of the signal to emit  	 * @param signalParams Signal parameters  	 */ -	private native void nativeEmitSignal(String pluginName, String signalName, Object[] signalParams); +	private static native void nativeEmitSignal(String pluginName, String signalName, Object[] signalParams);  } diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginInfoProvider.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginInfoProvider.java new file mode 100644 index 0000000000..09366384c2 --- /dev/null +++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginInfoProvider.java @@ -0,0 +1,72 @@ +/*************************************************************************/ +/*  GodotPluginInfoProvider.java                                         */ +/*************************************************************************/ +/*                       This file is part of:                           */ +/*                           GODOT ENGINE                                */ +/*                      https://godotengine.org                          */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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.plugin; + +import androidx.annotation.NonNull; + +import java.util.Collections; +import java.util.Set; + +/** + * Provides the set of information expected from a Godot plugin. + */ +public interface GodotPluginInfoProvider { +	/** +	 * Returns the name of the plugin. +	 */ +	@NonNull +	String getPluginName(); + +	/** +	 * Returns the list of signals to be exposed to Godot. +	 */ +	@NonNull +	default Set<SignalInfo> getPluginSignals() { +		return Collections.emptySet(); +	} + +	/** +	 * Returns the paths for the plugin's gdnative libraries (if any). +	 * +	 * The paths must be relative to the 'assets' directory and point to a '*.gdnlib' file. +	 */ +	@NonNull +	default Set<String> getPluginGDNativeLibrariesPaths() { +		return Collections.emptySet(); +	} + +	/** +	 * This is invoked on the render thread when the plugin described by this instance has been +	 * registered. +	 */ +	default void onPluginRegistered() { +	} +} diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginRegistry.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginRegistry.java index 1c2d1a6563..5b41205253 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginRegistry.java +++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginRegistry.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -44,8 +44,6 @@ import androidx.annotation.Nullable;  import java.lang.reflect.Constructor;  import java.lang.reflect.InvocationTargetException;  import java.util.Collection; -import java.util.HashSet; -import java.util.Set;  import java.util.concurrent.ConcurrentHashMap;  /** @@ -56,13 +54,6 @@ public final class GodotPluginRegistry {  	private static final String GODOT_PLUGIN_V1_NAME_PREFIX = "org.godotengine.plugin.v1."; -	/** -	 * Name for the metadata containing the list of Godot plugins to enable. -	 */ -	private static final String GODOT_ENABLED_PLUGINS_LABEL = "plugins"; - -	private static final String PLUGIN_VALUE_SEPARATOR_REGEX = "\\|"; -  	private static GodotPluginRegistry instance;  	private final ConcurrentHashMap<String, GodotPlugin> registry; @@ -132,37 +123,11 @@ public final class GodotPluginRegistry {  				return;  			} -			// When using the Godot editor for building and exporting the apk, this is used to check -			// which plugins to enable. -			// When using a custom process to generate the apk, the metadata is not needed since -			// it's assumed that the developer is aware of the dependencies included in the apk. -			final Set<String> enabledPluginsSet; -			if (metaData.containsKey(GODOT_ENABLED_PLUGINS_LABEL)) { -				String enabledPlugins = metaData.getString(GODOT_ENABLED_PLUGINS_LABEL, ""); -				String[] enabledPluginsList = enabledPlugins.split(PLUGIN_VALUE_SEPARATOR_REGEX); -				if (enabledPluginsList.length == 0) { -					// No plugins to enable. Aborting early. -					return; -				} - -				enabledPluginsSet = new HashSet<>(); -				for (String enabledPlugin : enabledPluginsList) { -					enabledPluginsSet.add(enabledPlugin.trim()); -				} -			} else { -				enabledPluginsSet = null; -			} -  			int godotPluginV1NamePrefixLength = GODOT_PLUGIN_V1_NAME_PREFIX.length();  			for (String metaDataName : metaData.keySet()) {  				// Parse the meta-data looking for entry with the Godot plugin name prefix.  				if (metaDataName.startsWith(GODOT_PLUGIN_V1_NAME_PREFIX)) {  					String pluginName = metaDataName.substring(godotPluginV1NamePrefixLength).trim(); -					if (enabledPluginsSet != null && !enabledPluginsSet.contains(pluginName)) { -						Log.w(TAG, "Plugin " + pluginName + " is listed in the dependencies but is not enabled."); -						continue; -					} -  					Log.i(TAG, "Initializing Godot plugin " + pluginName);  					// Retrieve the plugin class full name. @@ -177,8 +142,7 @@ public final class GodotPluginRegistry {  																				 .getConstructor(Godot.class);  							GodotPlugin pluginHandle = pluginConstructor.newInstance(godot); -							// Load the plugin initializer into the registry using the plugin name -							// as key. +							// Load the plugin initializer into the registry using the plugin name as key.  							if (!pluginName.equals(pluginHandle.getPluginName())) {  								Log.w(TAG,  										"Meta-data plugin name does not match the value returned by the plugin handle: " + pluginName + " =/= " + pluginHandle.getPluginName()); diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/SignalInfo.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/SignalInfo.java index f82c4d3fa0..6428422641 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/plugin/SignalInfo.java +++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/SignalInfo.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/UsedByGodot.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/UsedByGodot.java new file mode 100644 index 0000000000..04c091d944 --- /dev/null +++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/UsedByGodot.java @@ -0,0 +1,45 @@ +/*************************************************************************/ +/*  UsedByGodot.java                                                     */ +/*************************************************************************/ +/*                       This file is part of:                           */ +/*                           GODOT ENGINE                                */ +/*                      https://godotengine.org                          */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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.plugin; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to indicate a method is being invoked from the Godot game logic. + * + * At runtime, annotated plugin methods are detected and automatically registered. + */ +@Target({ ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface UsedByGodot {} diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java b/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java index acc9c4981b..d6e49bb635 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java +++ b/platform/android/java/lib/src/org/godotengine/godot/utils/Crypt.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java b/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java index 82420eda79..19588f8465 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java +++ b/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/GodotNetUtils.java b/platform/android/java/lib/src/org/godotengine/godot/utils/GodotNetUtils.java index c89118ad55..721d7c65c6 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/utils/GodotNetUtils.java +++ b/platform/android/java/lib/src/org/godotengine/godot/utils/GodotNetUtils.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/PermissionsUtil.java b/platform/android/java/lib/src/org/godotengine/godot/utils/PermissionsUtil.java index 7104baf86e..b0ca96271e 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/utils/PermissionsUtil.java +++ b/platform/android/java/lib/src/org/godotengine/godot/utils/PermissionsUtil.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkRenderer.kt b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkRenderer.kt index 7fa8e3b4e5..a35f6ec5a7 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkRenderer.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkRenderer.kt @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -52,7 +52,6 @@ import org.godotengine.godot.plugin.GodotPluginRegistry   * @see [VkSurfaceView.startRenderer]   */  internal class VkRenderer { -  	private val pluginRegistry: GodotPluginRegistry = GodotPluginRegistry.getPluginRegistry()  	/** diff --git a/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkSurfaceView.kt b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkSurfaceView.kt index 6b0e12b21a..f0e37d80b8 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkSurfaceView.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkSurfaceView.kt @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -50,7 +50,6 @@ import android.view.SurfaceView   * </ul>   */  open internal class VkSurfaceView(context: Context) : SurfaceView(context), SurfaceHolder.Callback { -  	companion object {  		fun checkState(expression: Boolean, errorMessage: Any) {  			check(expression) { errorMessage.toString() } diff --git a/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkThread.kt b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkThread.kt index 7557c8aa22..b967fd5f24 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkThread.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkThread.kt @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ @@ -41,7 +41,6 @@ import kotlin.concurrent.withLock   * The implementation is modeled after [android.opengl.GLSurfaceView]'s GLThread.   */  internal class VkThread(private val vkSurfaceView: VkSurfaceView, private val vkRenderer: VkRenderer) : Thread(TAG) { -  	companion object {  		private val TAG = VkThread::class.java.simpleName  	} @@ -226,5 +225,4 @@ internal class VkThread(private val vkSurfaceView: VkSurfaceView, private val vk  			threadExiting()  		}  	} -  } diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/XRMode.java b/platform/android/java/lib/src/org/godotengine/godot/xr/XRMode.java index 982e43f9d1..0995477baf 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/xr/XRMode.java +++ b/platform/android/java/lib/src/org/godotengine/godot/xr/XRMode.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrConfigChooser.java b/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrConfigChooser.java index 819bcccdf1..245d573bfc 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrConfigChooser.java +++ b/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrConfigChooser.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrContextFactory.java b/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrContextFactory.java index 2d9b921466..d3aca267ef 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrContextFactory.java +++ b/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrContextFactory.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrWindowSurfaceFactory.java b/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrWindowSurfaceFactory.java index 43c7f0f966..83aa458064 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrWindowSurfaceFactory.java +++ b/platform/android/java/lib/src/org/godotengine/godot/xr/ovr/OvrWindowSurfaceFactory.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java index 54672db282..341427209b 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java +++ b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java index 126f3ad5f5..71610d2d00 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java +++ b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */ diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularFallbackConfigChooser.java b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularFallbackConfigChooser.java index c83c47bed7..e690c5b695 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularFallbackConfigChooser.java +++ b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularFallbackConfigChooser.java @@ -5,8 +5,8 @@  /*                           GODOT ENGINE                                */  /*                      https://godotengine.org                          */  /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ +/* Copyright (c) 2014-2021 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       */  |