From b1a9d5f8f4316fbca64f3122e1ecfedb0702ebc1 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Fri, 15 May 2026 17:09:43 +0200 Subject: [PATCH 1/5] cleanup android backend and normalize settings --- .../jme3androidexamples/JmeFragment.java | 14 - .../com/jme3/app/AndroidHarnessFragment.java | 24 - .../jme3/system/android/JmeAndroidSystem.java | 6 +- .../main/java/com/jme3/view/package-info.java | 36 - .../jme3/view/surfaceview/JmeSurfaceView.java | 1029 ----------------- .../view/surfaceview/OnExceptionThrown.java | 47 - .../jme3/view/surfaceview/OnLayoutDrawn.java | 51 - .../view/surfaceview/OnRendererCompleted.java | 53 - .../view/surfaceview/OnRendererStarted.java | 55 - .../jme3/view/surfaceview/package-info.java | 44 - .../java/com/jme3/system/AppSettings.java | 10 +- .../com/jme3/system/JmeDesktopSystem.java | 2 +- 12 files changed, 13 insertions(+), 1358 deletions(-) delete mode 100644 jme3-android/src/main/java/com/jme3/view/package-info.java delete mode 100644 jme3-android/src/main/java/com/jme3/view/surfaceview/JmeSurfaceView.java delete mode 100644 jme3-android/src/main/java/com/jme3/view/surfaceview/OnExceptionThrown.java delete mode 100644 jme3-android/src/main/java/com/jme3/view/surfaceview/OnLayoutDrawn.java delete mode 100644 jme3-android/src/main/java/com/jme3/view/surfaceview/OnRendererCompleted.java delete mode 100644 jme3-android/src/main/java/com/jme3/view/surfaceview/OnRendererStarted.java delete mode 100644 jme3-android/src/main/java/com/jme3/view/surfaceview/package-info.java diff --git a/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/JmeFragment.java b/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/JmeFragment.java index 3a3e399930..8b6eb89b40 100644 --- a/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/JmeFragment.java +++ b/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/JmeFragment.java @@ -52,18 +52,4 @@ protected LegacyApplication createApplication() throws Exception { return (LegacyApplication) clazz.getDeclaredConstructor().newInstance(); } - @Override - protected void configureSettings(AppSettings settings) { - settings.setEmulateMouse(mouseEventsEnabled); - settings.setUseJoysticks(joystickEventsEnabled); - settings.setEmulateKeyboard(keyEventsEnabled); - - settings.setBitsPerPixel(24); - settings.setAlphaBits(0); - settings.setGammaCorrection(true); - settings.setDepthBits(16); - settings.setSamples(4); - settings.setStencilBits(0); - settings.setFrameRate(-1); - } } diff --git a/jme3-android/src/main/java/com/jme3/app/AndroidHarnessFragment.java b/jme3-android/src/main/java/com/jme3/app/AndroidHarnessFragment.java index d3ddab8d2f..7e61c51fa7 100644 --- a/jme3-android/src/main/java/com/jme3/app/AndroidHarnessFragment.java +++ b/jme3-android/src/main/java/com/jme3/app/AndroidHarnessFragment.java @@ -96,12 +96,7 @@ public void onCreate(Bundle savedInstanceState) { try { app = createApplication(); - - AppSettings settings = createSettings(); - configureSettings(settings); - app.setSettings(settings); app.start(); - OGLESContext context = (OGLESContext) app.getContext(); context.setSystemListener(this); } catch (Exception exception) { @@ -117,25 +112,6 @@ public void onCreate(Bundle savedInstanceState) { */ protected abstract LegacyApplication createApplication() throws Exception; - /** - * Creates the default Android settings. Subclasses can override this when - * they need to replace the settings object rather than adjust it. - * - * @return default settings for Android - */ - protected AppSettings createSettings() { - AppSettings settings = new AppSettings(true); - settings.setAudioRenderer(AppSettings.ANDROID_OPENAL_SOFT); - return settings; - } - - /** - * Customizes the settings before the application starts. - * - * @param settings the settings to customize - */ - protected void configureSettings(AppSettings settings) { - } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { diff --git a/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java b/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java index 0ba2d85e0c..7d54c81b9e 100644 --- a/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java +++ b/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java @@ -32,7 +32,7 @@ public class JmeAndroidSystem extends JmeSystemDelegate { private static View view; - private static String audioRendererType = AppSettings.ANDROID_OPENAL_SOFT; + private static String audioRendererType = AppSettings.OPENAL; static { try { @@ -83,11 +83,11 @@ public JmeContext newContext(AppSettings settings, Type contextType) { audioRendererType = null; } else if (settings.getAudioRenderer().equals(AppSettings.ANDROID_MEDIAPLAYER)) { audioRendererType = AppSettings.ANDROID_MEDIAPLAYER; - } else if (settings.getAudioRenderer().equals(AppSettings.ANDROID_OPENAL_SOFT)) { + } else if (settings.getAudioRenderer().equals(AppSettings.ANDROID_OPENAL_SOFT)||settings.getAudioRenderer().equals(AppSettings.OPENAL)) { audioRendererType = AppSettings.ANDROID_OPENAL_SOFT; } else { logger.log(Level.INFO, "AudioRenderer not set. Defaulting to OpenAL Soft"); - audioRendererType = AppSettings.ANDROID_OPENAL_SOFT; + audioRendererType = AppSettings.OPENAL; } initialize(settings); JmeContext ctx = new OGLESContext(); diff --git a/jme3-android/src/main/java/com/jme3/view/package-info.java b/jme3-android/src/main/java/com/jme3/view/package-info.java deleted file mode 100644 index 5b820343d2..0000000000 --- a/jme3-android/src/main/java/com/jme3/view/package-info.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2009-2022 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/** - * Provides classes that expose custom android-native ui that can handle screen layout and interactions with the user - * for a jMonkeyEngine game. - */ -package com.jme3.view; \ No newline at end of file diff --git a/jme3-android/src/main/java/com/jme3/view/surfaceview/JmeSurfaceView.java b/jme3-android/src/main/java/com/jme3/view/surfaceview/JmeSurfaceView.java deleted file mode 100644 index 67d73f4b5c..0000000000 --- a/jme3-android/src/main/java/com/jme3/view/surfaceview/JmeSurfaceView.java +++ /dev/null @@ -1,1029 +0,0 @@ -/* - * Copyright (c) 2009-2025 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.view.surfaceview; - -import android.app.Activity; -import android.app.ActivityManager; -import android.app.AlertDialog; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.DialogInterface; -import android.content.pm.ConfigurationInfo; -import android.opengl.GLSurfaceView; -import android.os.Handler; -import android.util.AttributeSet; -import android.widget.RelativeLayout; -import android.widget.Toast; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.lifecycle.Lifecycle; -import androidx.lifecycle.LifecycleEventObserver; -import androidx.lifecycle.LifecycleOwner; -import com.jme3.app.LegacyApplication; -import com.jme3.asset.AssetLoader; -import com.jme3.audio.AudioNode; -import com.jme3.audio.AudioRenderer; -import com.jme3.input.JoyInput; -import com.jme3.input.android.AndroidSensorJoyInput; -import com.jme3.scene.Spatial; -import com.jme3.system.AppSettings; -import com.jme3.system.SystemListener; -import com.jme3.system.android.JmeAndroidSystem; -import com.jme3.system.android.OGLESContext; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A RelativeLayout class holder that wraps a {@link GLSurfaceView} as a renderer UI component and uses {@link OGLESContext} as a renderer context to render - * a jme game on an android view for custom xml designs. - * The main idea of {@link JmeSurfaceView} class is to start a jMonkeyEngine application in a {@link SystemListener} context on a GL_ES thread, - * then the game is rendered and updated through a {@link GLSurfaceView} component with a delay of user's choice using a {@link Handler}, during the delay, - * the user has the ability to handle a couple of actions asynchronously as displaying a progress bar on a SplashScreen or an image or even play a preface game music of choice. - * - * @author pavl_g. - */ -public class JmeSurfaceView extends RelativeLayout implements SystemListener, DialogInterface.OnClickListener, LifecycleEventObserver { - - private static final Logger jmeSurfaceViewLogger = Logger.getLogger(JmeSurfaceView.class.getName()); - /*AppSettings attributes*/ - protected String audioRendererType = AppSettings.ANDROID_OPENAL_SOFT; - /*using {@link LegacyApplication} instead of {@link SimpleApplication} to include all classes extends LegacyApplication*/ - private LegacyApplication legacyApplication; - private AppSettings appSettings; - private int eglBitsPerPixel = 24; - private int eglAlphaBits = 0; - private int eglDepthBits = 16; - private int eglSamples = 0; - private int eglStencilBits = 0; - private int frameRate = -1; - private boolean emulateKeyBoard = true; - private boolean emulateMouse = true; - private boolean useJoyStickEvents = true; - private boolean isGLThreadPaused; - /*Late-init instances -- nullable objects*/ - private GLSurfaceView glSurfaceView; - private OGLESContext oglesContext; - private ConfigurationInfo configurationInfo; - private OnRendererCompleted onRendererCompleted; - private OnRendererStarted onRendererStarted; - private OnExceptionThrown onExceptionThrown; - private OnLayoutDrawn onLayoutDrawn; - /*Global Objects*/ - private Handler handler = new Handler(); - private RendererThread rendererThread = new RendererThread(); - private StringWriter crashLogWriter = new StringWriter(150); - /*Global flags*/ - private boolean showErrorDialog = true; - private boolean bindAppState = true; - private boolean showEscExitPrompt = true; - private boolean exitOnEscPressed = true; - /*Destruction policy flag*/ - private DestructionPolicy destructionPolicy = DestructionPolicy.DESTROY_WHEN_FINISH; - /*extra messages/data*/ - private String crashLog = ""; - private String glEsVersion = ""; - - /** - * Instantiates a default surface view holder without XML attributes. - * On instantiating this surface view, the holder is bound directly to the - * parent context life cycle. - * - * @param context the parent context. - */ - public JmeSurfaceView(@NonNull Context context) { - super(context); - //binds the view component to the holder activity life cycle - bindAppStateToActivityLifeCycle(bindAppState); - } - - /** - * Instantiates a surface view holder with XML attributes from an XML document. - * On instantiating this surface view, the holder is bound directly to the - * parent context life cycle. - * - * @param context the parent context. - * @param attrs a collection of attributes describes the tags in an XML document. - * @see android.content.res.Resources.Theme#obtainAttributes(AttributeSet, int[]) - */ - public JmeSurfaceView(@NonNull Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - //binds the view component to the holder activity life cycle - bindAppStateToActivityLifeCycle(bindAppState); - } - - /** - * Instantiates a surface view holder with XML attributes and a default style attribute. - * On instantiating this surface view, the holder is bound directly to the - * parent context life cycle. - * - * @param context the parent context. - * @param attrs a collection of attributes describes the tags in an XML document. - * @param defStyleAttr an attribute in the current theme that contains a - * reference to a style resource that supplies - * defaults values. Can be 0 to not look for defaults. - * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) - */ - public JmeSurfaceView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - //binds the view component to the holder activity life cycle - bindAppStateToActivityLifeCycle(bindAppState); - } - - /** - * Instantiates a surface view holder with XML attributes, default style attribute and a default style resource. - * On instantiating this surface view, the holder is bound directly to the - * parent context life cycle. - * - * @param context the parent context. - * @param attrs a collection of attributes describes the tags in an XML document. - * @param defStyleAttr an attribute in the current theme that contains defaults. Can be 0 to not look for defaults. - * @param defStyleRes a resource identifier of a style resource that - * supplies default values, used only if defStyleAttr is 0 or can not be found in the theme. - * Can be 0 to not look for defaults. - * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) - */ - public JmeSurfaceView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - //binds the view component to the holder activity life cycle - bindAppStateToActivityLifeCycle(bindAppState); - } - - /** - * Starts the jmeRenderer on a GlSurfaceView attached to a RelativeLayout. - * - * @param delayMillis delays the attachment of the surface view to the UI (RelativeLayout). - */ - public void startRenderer(int delayMillis) { - delayMillis = Math.max(0, delayMillis); - /*gets the device configuration attributes from the activity manager*/ - configurationInfo = ((ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE)).getDeviceConfigurationInfo(); - glEsVersion = "GL_ES Version : " + configurationInfo.getGlEsVersion(); - /*sanity check the app instance*/ - if (legacyApplication == null) { - throw new IllegalStateException("Cannot build a SurfaceView for a null app, make sure to use setLegacyApplication() to pass in your app !"); - } - /*initialize App Settings and start the Game*/ - appSettings = new AppSettings(true); - appSettings.setAudioRenderer(audioRendererType); - appSettings.setResolution(JmeSurfaceView.this.getLayoutParams().width, JmeSurfaceView.this.getLayoutParams().height); - appSettings.setAlphaBits(eglAlphaBits); - appSettings.setDepthBits(eglDepthBits); - appSettings.setSamples(eglSamples); - appSettings.setStencilBits(eglStencilBits); - appSettings.setBitsPerPixel(eglBitsPerPixel); - appSettings.setEmulateKeyboard(emulateKeyBoard); - appSettings.setEmulateMouse(emulateMouse); - appSettings.setUseJoysticks(useJoyStickEvents); - /*fetch and sanity check the static memory*/ - if (GameState.getLegacyApplication() != null) { - this.legacyApplication = GameState.getLegacyApplication(); - jmeSurfaceViewLogger.log(Level.INFO, "Old game state has been assigned as the current game state, skipping the first update"); - } else { - legacyApplication.setSettings(appSettings); - jmeSurfaceViewLogger.log(Level.INFO, "Starting a new Game State"); - /*start jme game context*/ - legacyApplication.start(); - /*fire the onStart() listener*/ - if (onRendererStarted != null) { - onRendererStarted.onRenderStart(legacyApplication, this); - } - } - /*attach the game to JmE OpenGL.Renderer context*/ - oglesContext = (OGLESContext) legacyApplication.getContext(); - /*create a glSurfaceView that will hold the renderer thread*/ - glSurfaceView = oglesContext.createView(JmeSurfaceView.this.getContext()); - /*set the current view as the system engine thread view for future uses*/ - JmeAndroidSystem.setView(JmeSurfaceView.this); - /*set JME system Listener to initialize game, update, requestClose and destroy on closure*/ - oglesContext.setSystemListener(JmeSurfaceView.this); - /*set the glSurfaceView to fit the widget*/ - glSurfaceView.setLayoutParams(new LayoutParams(JmeSurfaceView.this.getLayoutParams().width, JmeSurfaceView.this.getLayoutParams().height)); - if (GameState.getLegacyApplication() != null) { - addGlSurfaceView(); - } else { - /*post delay the attachment of the surface view on the UI*/ - handler.postDelayed(rendererThread, delayMillis); - } - } - - private void removeGLSurfaceView() { - ((Activity) getContext()).runOnUiThread(() -> JmeSurfaceView.this.removeView(glSurfaceView)); - } - - @Override - public void handleError(String errorMsg, Throwable throwable) { - throwable.printStackTrace(); - showErrorDialog(throwable, throwable.getClass().getName()); - if (onExceptionThrown != null) { - onExceptionThrown.onExceptionThrown(throwable); - } - } - - /** - * A state change observer to the holder Activity life cycle, used to keep this android view up-to-date with the holder activity life cycle. - * - * @param source the life cycle source, aka the observable object. - * @param event the fired event by the observable object, which is dispatched and sent to the observers. - */ - @Override - public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) { - switch (event) { - case ON_DESTROY: - // activity is off the foreground stack - // activity is being destructed completely as a result of Activity#finish() - // this is a killable automata state! - jmeSurfaceViewLogger.log(Level.INFO, "Hosting Activity has been destructed."); - break; - case ON_PAUSE: - // activity is still on the foreground stack but not - // on the topmost level or before transition to stopped/hidden or destroyed state - // as a result of dispatch to Activity#finish() - // activity is no longer visible and is out of foreground - if (((Activity) getContext()).isFinishing()) { - if (destructionPolicy == DestructionPolicy.DESTROY_WHEN_FINISH) { - legacyApplication.stop(!isGLThreadPaused()); - } else if (destructionPolicy == DestructionPolicy.KEEP_WHEN_FINISH) { - jmeSurfaceViewLogger.log(Level.INFO, "Context stops, but game is still running."); - } - } else { - loseFocus(); - } - break; - case ON_RESUME: - // activity is back to the topmost of the - // foreground stack - gainFocus(); - break; - case ON_STOP: - // activity is out off the foreground stack or being destructed by a finishing dispatch - // this is a killable automata state! - break; - } - } - - @Override - public void initialize() { - /*Invoking can be delayed by delaying the draw of GlSurfaceView component on the screen*/ - if (legacyApplication == null) { - return; - } - legacyApplication.initialize(); - /*log for display*/ - jmeSurfaceViewLogger.log(Level.INFO, "JmeGame started in GLThread Asynchronously......."); - } - - @Override - public void reshape(int width, int height) { - if (legacyApplication == null) { - return; - } - legacyApplication.reshape(width, height); - jmeSurfaceViewLogger.log(Level.INFO, "Requested reshaping from the system listener"); - } - - @Override - public void rescale(float x, float y) { - if (legacyApplication == null) { - return; - } - legacyApplication.rescale(x, y); - jmeSurfaceViewLogger.log(Level.INFO, "Requested rescaling from the system listener"); - } - - @Override - public void update() { - /*Invoking can be delayed by delaying the draw of GlSurfaceView component on the screen*/ - if (legacyApplication == null || glSurfaceView == null) { - return; - } - legacyApplication.update(); - if (!GameState.isFirstUpdatePassed()) { - ((Activity) getContext()).runOnUiThread(() -> { - jmeSurfaceViewLogger.log(Level.INFO, "User delay finishes with 0 errors"); - if (onRendererCompleted != null) { - onRendererCompleted.onRenderCompletion(legacyApplication, legacyApplication.getContext().getSettings()); - } - }); - GameState.setFirstUpdatePassed(true); - } - } - - @Override - public void requestClose(boolean esc) { - /*skip if it's not enabled or the input is null*/ - if (legacyApplication == null || (!isExitOnEscPressed())) { - return; - } - if (isShowEscExitPrompt()) { - final AlertDialog alertDialog = new AlertDialog.Builder(getContext()).create(); - alertDialog.setTitle("Exit Prompt"); - alertDialog.setMessage("Are you sure you want to quit ?"); - alertDialog.setCancelable(false); - alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "No", (dialogInterface, i) -> alertDialog.dismiss()); - alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Yes", (dialogInterface, i) -> legacyApplication.requestClose(esc)); - alertDialog.show(); - } else { - legacyApplication.requestClose(esc); - } - } - - @Override - public void gainFocus() { - /*skip the block if the instances are nullptr*/ - if (legacyApplication == null || glSurfaceView == null) { - return; - } - glSurfaceView.onResume(); - /*resume the audio*/ - final AudioRenderer audioRenderer = legacyApplication.getAudioRenderer(); - if (audioRenderer != null) { - audioRenderer.resumeAll(); - } - /*resume the sensors (aka joysticks)*/ - if (legacyApplication.getContext() != null) { - final JoyInput joyInput = legacyApplication.getContext().getJoyInput(); - if (joyInput != null) { - if (joyInput instanceof AndroidSensorJoyInput) { - final AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput; - androidJoyInput.resumeSensors(); - } - } - legacyApplication.gainFocus(); - } - setGLThreadPaused(false); - jmeSurfaceViewLogger.log(Level.INFO, "Game returns from the idle mode"); - } - - @Override - public void loseFocus() { - /*skip the block if the invoking instances are nullptr*/ - if (legacyApplication == null || glSurfaceView == null) { - return; - } - glSurfaceView.onPause(); - /*pause the audio*/ - legacyApplication.loseFocus(); - final AudioRenderer audioRenderer = legacyApplication.getAudioRenderer(); - if (audioRenderer != null) { - audioRenderer.pauseAll(); - } - /*pause the sensors (aka joysticks)*/ - if (legacyApplication.getContext() != null) { - final JoyInput joyInput = legacyApplication.getContext().getJoyInput(); - if (joyInput != null) { - if (joyInput instanceof AndroidSensorJoyInput) { - final AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput; - androidJoyInput.pauseSensors(); - } - } - } - setGLThreadPaused(true); - jmeSurfaceViewLogger.log(Level.INFO, "Game goes idle"); - } - - @Override - public void destroy() { - if (glSurfaceView != null) { - removeGLSurfaceView(); - } - if (legacyApplication != null) { - legacyApplication.destroy(); - } - /*help the Dalvik Garbage collector to destruct the objects, by releasing their references*/ - /*context instances*/ - legacyApplication = null; - appSettings = null; - oglesContext = null; - configurationInfo = null; - /*extra data instances*/ - crashLogWriter = null; - crashLog = null; - /*nullifying helper instances and flags*/ - rendererThread = null; - destructionPolicy = null; - audioRendererType = null; - handler = null; - glEsVersion = null; - /*nullifying the event handlers*/ - onRendererStarted = null; - onRendererCompleted = null; - onExceptionThrown = null; - onLayoutDrawn = null; - GameState.setLegacyApplication(null); - GameState.setFirstUpdatePassed(false); - JmeAndroidSystem.setView(null); - jmeSurfaceViewLogger.log(Level.INFO, "Context and Game have been destructed."); - } - - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which) { - case DialogInterface.BUTTON_NEGATIVE: - dialog.dismiss(); - ((Activity) getContext()).finish(); - break; - case DialogInterface.BUTTON_POSITIVE: - dialog.dismiss(); - break; - case DialogInterface.BUTTON_NEUTRAL: - /*copy crash log button*/ - final ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); - final ClipData clipData = ClipData.newPlainText("Crash Log", crashLog); - clipboardManager.setPrimaryClip(clipData); - Toast.makeText(getContext(), "Crash Log copied to clipboard", Toast.LENGTH_SHORT).show(); - break; - } - } - - /** - * Adds the glSurfaceView to the screen immediately, saving the current app instance. - */ - protected void addGlSurfaceView() { - /*jme Renderer joins the UIThread at that point*/ - JmeSurfaceView.this.addView(glSurfaceView); - /*dispatch the layout drawn event*/ - if (onLayoutDrawn != null) { - onLayoutDrawn.onLayoutDrawn(legacyApplication, this); - } - /*set the static memory to hold the game state, only if the destruction policy uses KEEP_WHEN_FINISHED policy*/ - if (destructionPolicy == DestructionPolicy.KEEP_WHEN_FINISH) { - GameState.setLegacyApplication(legacyApplication); - } else { - GameState.setLegacyApplication(null); - } - } - - /** - * Displays an error dialog with a throwable title(error/exception), message and 3 buttons. - * 1st button is : EXIT to exit the activity and terminates the app. - * 2nd button is : DISMISS to dismiss the dialog and ignore the exception. - * 3rd button is : CopyCrashLog to copy the crash log to the clipboard. - * - * @param throwable the throwable stack. - * @param title the message title. - */ - protected void showErrorDialog(Throwable throwable, String title) { - if (!isShowErrorDialog()) { - return; - } - ((Activity) getContext()).runOnUiThread(() -> { - throwable.printStackTrace(new PrintWriter(crashLogWriter)); - crashLog = glEsVersion + "\n" + crashLogWriter.toString(); - - final AlertDialog alertDialog = new AlertDialog.Builder(getContext()).create(); - alertDialog.setTitle(glEsVersion + ", " + title); - alertDialog.setMessage(crashLog); - alertDialog.setCancelable(false); - alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Exit", this); - alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Dismiss", this); - alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, "Copy crash log", this); - alertDialog.show(); - }); - } - - /** - * Binds/Unbinds the game life cycle to the holder activity life cycle. - * Unbinding the game life cycle, would disable {@link JmeSurfaceView#gainFocus()}, {@link JmeSurfaceView#loseFocus()} - * and {@link JmeSurfaceView#destroy()} from being invoked by the System Listener. - * The Default value is : true, and the view component is pre-bounded to its activity lifeCycle when initialized. - * - * @param condition true if you want to bind them, false otherwise. - */ - public void bindAppStateToActivityLifeCycle(final boolean condition) { - this.bindAppState = condition; - if (condition) { - /*register this Ui Component as an observer to the context of jmeSurfaceView only if this context is a LifeCycleOwner*/ - if (getContext() instanceof LifecycleOwner) { - ((LifecycleOwner) getContext()).getLifecycle().addObserver(JmeSurfaceView.this); - jmeSurfaceViewLogger.log(Level.INFO, "Command binding SurfaceView to the Activity Lifecycle."); - } - } else { - /*un-register this Ui Component as an observer to the context of jmeSurfaceView only if this context is a LifeCycleOwner*/ - if (getContext() instanceof LifecycleOwner) { - ((LifecycleOwner) getContext()).getLifecycle().removeObserver(JmeSurfaceView.this); - jmeSurfaceViewLogger.log(Level.INFO, "Command removing SurfaceView from the Activity Lifecycle."); - } - } - } - - /** - * Gets the current destruction policy. - * Default value is : {@link DestructionPolicy#DESTROY_WHEN_FINISH}. - * - * @return the destruction policy, either {@link DestructionPolicy#DESTROY_WHEN_FINISH} or {@link DestructionPolicy#KEEP_WHEN_FINISH}. - * @see DestructionPolicy - * @see GameState - */ - public DestructionPolicy getDestructionPolicy() { - return destructionPolicy; - } - - /** - * Sets the current destruction policy, destruction policy {@link DestructionPolicy#KEEP_WHEN_FINISH} ensures that we protect the app state - * using {@link GameState#legacyApplication} static memory when the activity finishes, while - * {@link DestructionPolicy#DESTROY_WHEN_FINISH} destroys the game context with the activity onDestroy(). - * Default value is : {@link DestructionPolicy#DESTROY_WHEN_FINISH}. - * - * @param destructionPolicy a destruction policy to set. - * @see DestructionPolicy - * @see GameState - */ - public void setDestructionPolicy(DestructionPolicy destructionPolicy) { - this.destructionPolicy = destructionPolicy; - } - - /** - * Checks whether the current game application life cycle is bound to the activity life cycle. - * - * @return true it matches the condition, false otherwise. - */ - public boolean isAppStateBoundToActivityLifeCycle() { - return bindAppState; - } - - /** - * Checks whether the system would show an exit prompt dialog when the esc keyboard input is invoked. - * - * @return ture if the exit prompt dialog is activated on exit, false otherwise. - */ - public boolean isShowEscExitPrompt() { - return showEscExitPrompt; - } - - /** - * Determines whether to show an exit prompt dialog when the esc keyboard button is invoked. - * - * @param showEscExitPrompt true to show the exit prompt dialog before exiting, false otherwise. - */ - public void setShowEscExitPrompt(boolean showEscExitPrompt) { - this.showEscExitPrompt = showEscExitPrompt; - } - - /** - * Checks whether the exit on esc press is activated. - * - * @return true if the exit on escape is activated, false otherwise. - */ - public boolean isExitOnEscPressed() { - return exitOnEscPressed; - } - - /** - * Determines whether the system would exit on pressing the keyboard esc button. - * - * @param exitOnEscPressed true to activate exiting on Esc button press, false otherwise. - */ - public void setExitOnEscPressed(boolean exitOnEscPressed) { - this.exitOnEscPressed = exitOnEscPressed; - } - - /** - * Gets the jme app instance. - * - * @return legacyApplication instance representing your game enclosure. - */ - public LegacyApplication getLegacyApplication() { - return legacyApplication; - } - - /** - * Sets the jme game instance that will be engaged into the {@link SystemListener}. - * - * @param legacyApplication your jme game instance. - */ - public void setLegacyApplication(@NonNull LegacyApplication legacyApplication) { - this.legacyApplication = legacyApplication; - } - - /** - * Gets the game window settings. - * - * @return app settings instance. - */ - public AppSettings getAppSettings() { - return appSettings; - } - - /** - * Sets the appSettings instance. - * - * @param appSettings the custom appSettings instance - */ - public void setAppSettings(@NonNull AppSettings appSettings) { - this.appSettings = appSettings; - } - - /** - * Gets the bits/pixel for Embedded gL - * - * @return integer representing it. - */ - public int getEglBitsPerPixel() { - return eglBitsPerPixel; - } - - /** - * Sets the memory representing each pixel in bits. - * - * @param eglBitsPerPixel the bits for each pixel. - */ - public void setEglBitsPerPixel(int eglBitsPerPixel) { - this.eglBitsPerPixel = eglBitsPerPixel; - } - - /** - * Gets the Embedded gL alpha(opacity) bits. - * - * @return integer representing it. - */ - public int getEglAlphaBits() { - return eglAlphaBits; - } - - /** - * Sets the memory representing the alpha of embedded gl in bits. - * - * @param eglAlphaBits the alpha bits. - */ - public void setEglAlphaBits(int eglAlphaBits) { - this.eglAlphaBits = eglAlphaBits; - } - - /** - * Gets the memory representing the EGL depth in bits. - * - * @return the depth bits. - */ - public int getEglDepthBits() { - return eglDepthBits; - } - - /** - * Sets the EGL depth in bits. - * The depth buffer or Z-buffer is basically coupled with stencil buffer, - * usually 8bits stencilBuffer + 24bits depthBuffer = 32bits shared memory. - * - * @param eglDepthBits the depth bits. - * @see JmeSurfaceView#setEglStencilBits(int) - */ - public void setEglDepthBits(int eglDepthBits) { - this.eglDepthBits = eglDepthBits; - } - - /** - * Gets the number of samples to use for multi-sampling. - * - * @return number of samples to use for multi-sampling. - */ - public int getEglSamples() { - return eglSamples; - } - - /** - * Sets the number of samples to use for multi-sampling. - * Leave 0 (default) to disable multi-sampling. - * Set to 2 or 4 to enable multi-sampling. - * - * @param eglSamples embedded gl samples bits to set. - */ - public void setEglSamples(int eglSamples) { - this.eglSamples = eglSamples; - } - - /** - * Gets the number of stencil buffer bits. - * Default is : 0. - * - * @return the stencil buffer bits. - */ - public int getEglStencilBits() { - return eglStencilBits; - } - - /** - * Sets the number of stencil buffer bits. - * Stencil buffer is used in depth-based shadow maps and shadow rendering as it limits rendering, - * it's coupled with Z-buffer or depth buffer, usually 8bits stencilBuffer + 24bits depthBuffer = 32bits shared memory. - * (default = 0) - * - * @param eglStencilBits the desired number of stencil bits. - * @see JmeSurfaceView#setEglDepthBits(int) - */ - public void setEglStencilBits(int eglStencilBits) { - this.eglStencilBits = eglStencilBits; - } - - /** - * Gets the limited FrameRate level for egl INFO. - * Default is : -1, for a device based limited value (determined by hardware). - * - * @return the limit frameRate in integers. - */ - public int getFrameRate() { - return frameRate; - } - - /** - * Limits the frame rate (fps) in the second. - * Default is : -1, for a device based limited value (determined by hardware). - * - * @param frameRate the limitation in integers. - */ - public void setFrameRate(int frameRate) { - this.frameRate = frameRate; - } - - /** - * Gets the audio renderer in String. - * Default is : {@link AppSettings#ANDROID_OPENAL_SOFT}. - * - * @return string representing audio renderer framework. - */ - public String getAudioRendererType() { - return audioRendererType; - } - - /** - * Sets the audioRenderer type. - * Default is : {@link AppSettings#ANDROID_OPENAL_SOFT}. - * - * @param audioRendererType string representing audioRenderer type. - */ - public void setAudioRendererType(String audioRendererType) { - this.audioRendererType = audioRendererType; - } - - /** - * Checks if the keyboard interfacing is enabled. - * Default is : true. - * - * @return true if the keyboard interfacing is enabled. - */ - public boolean isEmulateKeyBoard() { - return emulateKeyBoard; - } - - /** - * Enables keyboard interfacing. - * Default is : true. - * - * @param emulateKeyBoard true to enable keyboard interfacing. - */ - public void setEmulateKeyBoard(boolean emulateKeyBoard) { - this.emulateKeyBoard = emulateKeyBoard; - } - - /** - * Checks whether the mouse interfacing is enabled or not. - * Default is : true. - * - * @return true if the mouse interfacing is enabled. - */ - public boolean isEmulateMouse() { - return emulateMouse; - } - - /** - * Enables mouse interfacing. - * Default is : true. - * - * @param emulateMouse true to enable the mouse interfacing. - */ - public void setEmulateMouse(boolean emulateMouse) { - this.emulateMouse = emulateMouse; - } - - /** - * Checks whether joystick interfacing is enabled or not. - * Default is : true. - * - * @return true if the joystick interfacing is enabled. - */ - public boolean isUseJoyStickEvents() { - return useJoyStickEvents; - } - - /** - * Enables joystick interfacing for a jme-game - * - * @param useJoyStickEvents true to enable the joystick interfacing. - */ - public void setUseJoyStickEvents(boolean useJoyStickEvents) { - this.useJoyStickEvents = useJoyStickEvents; - } - - /** - * Checks whether the GLThread is paused or not. - * - * @return true/false - */ - public boolean isGLThreadPaused() { - return isGLThreadPaused; - } - - /** - * Sets GL Thread paused. - * - * @param GLThreadPaused true if you want to pause the GLThread. - */ - protected void setGLThreadPaused(boolean GLThreadPaused) { - isGLThreadPaused = GLThreadPaused; - } - - /** - * Sets the listener for the completion of rendering, ie : when the GL thread holding the {@link JmeSurfaceView} - * joins the UI thread, after asynchronous rendering. - * - * @param onRendererCompleted an instance of the interface {@link OnRendererCompleted}. - */ - public void setOnRendererCompleted(OnRendererCompleted onRendererCompleted) { - this.onRendererCompleted = onRendererCompleted; - } - - /** - * Sets the listener that will fire when an exception is thrown. - * - * @param onExceptionThrown an instance of the interface {@link OnExceptionThrown}. - */ - public void setOnExceptionThrown(OnExceptionThrown onExceptionThrown) { - this.onExceptionThrown = onExceptionThrown; - } - - /** - * Sets the listener that will fire after initializing the game. - * - * @param onRendererStarted an instance of the interface {@link OnRendererStarted}. - */ - public void setOnRendererStarted(OnRendererStarted onRendererStarted) { - this.onRendererStarted = onRendererStarted; - } - - /** - * Sets the listener that will dispatch an event when the layout is drawn by {@link JmeSurfaceView#addGlSurfaceView()}. - * - * @param onLayoutDrawn the event to be dispatched. - * @see JmeSurfaceView#addGlSurfaceView() - */ - public void setOnLayoutDrawn(OnLayoutDrawn onLayoutDrawn) { - this.onLayoutDrawn = onLayoutDrawn; - } - - /** - * Gets the current device GL_ES version. - * - * @return the current gl_es version in a string format. - */ - public String getGlEsVersion() { - return configurationInfo.getGlEsVersion(); - } - - /** - * Checks whether the error dialog is enabled upon encountering exceptions/errors. - * Default is : true. - * - * @return true if the error dialog is activated, false otherwise. - */ - public boolean isShowErrorDialog() { - return showErrorDialog; - } - - /** - * Determines whether the error dialog would be shown on encountering exceptions. - * Default is : true. - * - * @param showErrorDialog true to activate the error dialog, false otherwise. - */ - public void setShowErrorDialog(boolean showErrorDialog) { - this.showErrorDialog = showErrorDialog; - } - - /** - * Determines whether the app context would be destructed as a result of dispatching {@link Activity#finish()} - * with the holder activity context in case of {@link DestructionPolicy#DESTROY_WHEN_FINISH} or be - * spared for a second use in case of {@link DestructionPolicy#KEEP_WHEN_FINISH}. - * Default value is : {@link DestructionPolicy#DESTROY_WHEN_FINISH}. - * - * @see JmeSurfaceView#setDestructionPolicy(DestructionPolicy) - */ - public enum DestructionPolicy { - /** - * Finishes the game context with the activity context (ignores the static memory {@link GameState#legacyApplication}) - * as a result of dispatching {@link Activity#finish()}. - */ - DESTROY_WHEN_FINISH, - /** - * Spares the game context inside a static memory {@link GameState#legacyApplication} - * when the activity context is destroyed dispatching {@link Activity#finish()}, but the {@link android.app.Application} - * stills in the background. - */ - KEEP_WHEN_FINISH - } - - /** - * Used as a static memory to protect the game context from destruction by Activity#onDestroy(). - * - * @see DestructionPolicy - * @see JmeSurfaceView#setDestructionPolicy(DestructionPolicy) - */ - protected static final class GameState { - - private static LegacyApplication legacyApplication; - private static boolean firstUpdatePassed = false; - - /** - * Private constructor to inhibit instantiation of this class. - */ - private GameState() { - } - - /** - * Returns the current application state. - * - * @return game state instance, holding jME3 states (JmeContext, AssetManager, StateManager, Graphics, Sound, Input, Spatial/Nodes in place, etcetera). - */ - protected static LegacyApplication getLegacyApplication() { - return legacyApplication; - } - - /** - * Replaces the current application state. - * - * @param legacyApplication the new app instance holding the game state (including {@link AssetLoader}s, {@link AudioNode}s, {@link Spatial}s, etcetera). - */ - protected static void setLegacyApplication(LegacyApplication legacyApplication) { - GameState.legacyApplication = legacyApplication; - } - - /** - * Tests the first update flag. - * - * @return true if the firstUpdate has passed, false otherwise. - */ - protected static boolean isFirstUpdatePassed() { - return firstUpdatePassed; - } - - /** - * Adjusts the first update flag. - * - * @param firstUpdatePassed set to true to determine whether the firstUpdate has passed, false otherwise. - */ - protected static void setFirstUpdatePassed(boolean firstUpdatePassed) { - GameState.firstUpdatePassed = firstUpdatePassed; - } - } - - /** - * Delays the attachment surface view on the UI for the sake of initial frame pacing and splash screens, - * delaying the display of the game (GlSurfaceView) would lead to a substantial delay in the - * {@link android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.microedition.khronos.opengles.GL10)} which would - * delay invoking both {@link LegacyApplication#initialize()} and {@link LegacyApplication#update()}. - * - * @see JmeSurfaceView#startRenderer(int) - * @see com.jme3.system.android.OGLESContext#onDrawFrame(javax.microedition.khronos.opengles.GL10) - */ - private class RendererThread implements Runnable { - /** - * Delays the {@link GLSurfaceView} attachment on the UI thread. - * - * @see JmeSurfaceView#startRenderer(int) - */ - @Override - public void run() { - addGlSurfaceView(); - jmeSurfaceViewLogger.log(Level.INFO, "JmeSurfaceView's joined the UI thread"); - } - } -} diff --git a/jme3-android/src/main/java/com/jme3/view/surfaceview/OnExceptionThrown.java b/jme3-android/src/main/java/com/jme3/view/surfaceview/OnExceptionThrown.java deleted file mode 100644 index a0174b074a..0000000000 --- a/jme3-android/src/main/java/com/jme3/view/surfaceview/OnExceptionThrown.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2009-2022 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.view.surfaceview; - -/** - * An interface designed to listen for exceptions and fire an event when an exception is thrown. - * - * @author pavl_g. - * @see JmeSurfaceView#setOnExceptionThrown(OnExceptionThrown) - */ -public interface OnExceptionThrown { - /** - * Listens for a thrown exception or a thrown error. - * - * @param e the exception or the error that is throwable. - */ - void onExceptionThrown(Throwable e); -} diff --git a/jme3-android/src/main/java/com/jme3/view/surfaceview/OnLayoutDrawn.java b/jme3-android/src/main/java/com/jme3/view/surfaceview/OnLayoutDrawn.java deleted file mode 100644 index 14a7d9ca58..0000000000 --- a/jme3-android/src/main/java/com/jme3/view/surfaceview/OnLayoutDrawn.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2009-2022 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.view.surfaceview; - -import android.view.View; -import com.jme3.app.LegacyApplication; - -/** - * An interface used for dispatching an event when the layout holding the {@link android.opengl.GLSurfaceView} is drawn, - * the event is dispatched on the user activity context thread. - * - * @author pavl_g. - */ -public interface OnLayoutDrawn { - /** - * Dispatched when the layout is drawn on the screen. - * - * @param legacyApplication the application instance. - * @param layout the current layout. - */ - void onLayoutDrawn(LegacyApplication legacyApplication, View layout); -} diff --git a/jme3-android/src/main/java/com/jme3/view/surfaceview/OnRendererCompleted.java b/jme3-android/src/main/java/com/jme3/view/surfaceview/OnRendererCompleted.java deleted file mode 100644 index 284b8e97e5..0000000000 --- a/jme3-android/src/main/java/com/jme3/view/surfaceview/OnRendererCompleted.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2009-2022 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.view.surfaceview; - -import com.jme3.app.LegacyApplication; -import com.jme3.system.AppSettings; - -/** - * An interface used for invoking an event when the user delay finishes, on the first update of the game. - * - * @author pavl_g. - * @see JmeSurfaceView#setOnRendererCompleted(OnRendererCompleted) - */ -public interface OnRendererCompleted { - /** - * Invoked when the user delay finishes, on the first update of the game, the event is dispatched on the - * enclosing Activity context thread. - * - * @param application the current jme game instance. - * @param appSettings the current window settings of the running jme game. - * @see JmeSurfaceView#update() - */ - void onRenderCompletion(LegacyApplication application, AppSettings appSettings); -} diff --git a/jme3-android/src/main/java/com/jme3/view/surfaceview/OnRendererStarted.java b/jme3-android/src/main/java/com/jme3/view/surfaceview/OnRendererStarted.java deleted file mode 100644 index d92fd19479..0000000000 --- a/jme3-android/src/main/java/com/jme3/view/surfaceview/OnRendererStarted.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2009-2022 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.view.surfaceview; - -import android.view.View; -import com.jme3.app.LegacyApplication; - -/** - * An interface used for invoking an event when the application is started explicitly from {@link JmeSurfaceView#startRenderer(int)}. - * NB : This listener must be utilized before using {@link JmeSurfaceView#startRenderer(int)}, ie : it would be ignored if you try to use {@link JmeSurfaceView#setOnRendererStarted(OnRendererStarted)} after - * {@link JmeSurfaceView#startRenderer(int)}. - * - * @author pavl_g. - * @see JmeSurfaceView#setOnRendererStarted(OnRendererStarted) - */ -public interface OnRendererStarted { - /** - * Invoked when the game application is started by the {@link LegacyApplication#start()}, the event is dispatched on the - * holder Activity context thread. - * - * @param application the game instance. - * @param layout the enclosing layout. - * @see JmeSurfaceView#startRenderer(int) - */ - void onRenderStart(LegacyApplication application, View layout); -} diff --git a/jme3-android/src/main/java/com/jme3/view/surfaceview/package-info.java b/jme3-android/src/main/java/com/jme3/view/surfaceview/package-info.java deleted file mode 100644 index 38d15448bf..0000000000 --- a/jme3-android/src/main/java/com/jme3/view/surfaceview/package-info.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2009-2022 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Holds {@link com.jme3.view.surfaceview.JmeSurfaceView} with some lifecycle interfaces. - *

- * This package provides the following : - *

- * {@link com.jme3.view.surfaceview.JmeSurfaceView} : An OpenGL android view wrapper for rendering, updating and destroying a jMonkeyEngine game. - * {@link com.jme3.view.surfaceview.OnRendererStarted} : Provides a method to be invoked when a jMonkeyEngine application starts. - * {@link com.jme3.view.surfaceview.OnLayoutDrawn} : Provides a method to be invoked when the GLSurfaceView draws the content, before OnRendererCompleted. - * {@link com.jme3.view.surfaceview.OnRendererCompleted} : Provides a method to be invoked on the first update of the game. - * {@link com.jme3.view.surfaceview.OnExceptionThrown} : Provides a method to be invoked when an exception is thrown. - */ -package com.jme3.view.surfaceview; \ No newline at end of file diff --git a/jme3-core/src/main/java/com/jme3/system/AppSettings.java b/jme3-core/src/main/java/com/jme3/system/AppSettings.java index 7e5fe0d9aa..612533c408 100644 --- a/jme3-core/src/main/java/com/jme3/system/AppSettings.java +++ b/jme3-core/src/main/java/com/jme3/system/AppSettings.java @@ -218,10 +218,14 @@ public final class AppSettings extends HashMap { * * @see AppSettings#setAudioRenderer(java.lang.String) */ + @Deprecated public static final String LWJGL_OPENAL = "LWJGL"; public static final String ANGLE_GLES3 = "ANGLE_GLES3"; + public static final String OPENAL = "OPENAL"; + + /** * Use the Android MediaPlayer / SoundPool based renderer for Android audio capabilities. *

@@ -242,6 +246,7 @@ public final class AppSettings extends HashMap { * * @see AppSettings#setAudioRenderer(java.lang.String) */ + @Deprecated public static final String ANDROID_OPENAL_SOFT = "OpenAL_SOFT"; /** @@ -251,6 +256,7 @@ public final class AppSettings extends HashMap { * * @see AppSettings#setRenderer(java.lang.String) */ + @Deprecated public static final String JOGL_OPENGL_FORWARD_COMPATIBLE = "JOGL_OPENGL_FORWARD_COMPATIBLE"; /** @@ -260,6 +266,7 @@ public final class AppSettings extends HashMap { * * @see AppSettings#setRenderer(java.lang.String) */ + @Deprecated public static final String JOGL_OPENGL_BACKWARD_COMPATIBLE = "JOGL_OPENGL_BACKWARD_COMPATIBLE"; /** @@ -269,6 +276,7 @@ public final class AppSettings extends HashMap { * * @see AppSettings#setAudioRenderer(java.lang.String) */ + @Deprecated public static final String JOAL = "JOAL"; /** @@ -311,7 +319,7 @@ public final class AppSettings extends HashMap { defaults.put("Fullscreen", false); defaults.put("Title", JmeVersion.FULL_NAME); defaults.put("Renderer", ANGLE_GLES3); - defaults.put("AudioRenderer", LWJGL_OPENAL); + defaults.put("AudioRenderer", OPENAL); defaults.put("DisableJoysticks", true); defaults.put("UseInput", true); defaults.put("VSync", true); diff --git a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java index 042e8ccf48..d07fa3cd4f 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java +++ b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java @@ -257,7 +257,7 @@ public AudioRenderer newAudioRenderer(AppSettings settings) { AL al; ALC alc; EFX efx; - if (settings.getAudioRenderer().startsWith("LWJGL")) { + if (settings.getAudioRenderer().startsWith("LWJGL") || settings.getAudioRenderer().equals(AppSettings.OPENAL)) { al = newObject("com.jme3.audio.lwjgl.LwjglAL"); alc = newObject("com.jme3.audio.lwjgl.LwjglALC"); efx = newObject("com.jme3.audio.lwjgl.LwjglEFX"); From 65869d3c69abf72e9864a3b949a526a35a53c445 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Fri, 15 May 2026 17:50:37 +0200 Subject: [PATCH 2/5] set emulated input in every android example --- jme3-android-examples/build.gradle | 7 +- .../jme3androidexamples/JmeFragment.java | 19 ++-- .../jme3androidexamples/MainActivity.java | 89 +------------------ .../jme3androidexamples/TestActivity.java | 15 +--- .../src/main/res/menu/menu_items.xml | 16 ---- .../src/main/res/values/strings.xml | 6 -- 6 files changed, 17 insertions(+), 135 deletions(-) diff --git a/jme3-android-examples/build.gradle b/jme3-android-examples/build.gradle index a795b54e2d..dcc1c1ab8f 100644 --- a/jme3-android-examples/build.gradle +++ b/jme3-android-examples/build.gradle @@ -123,13 +123,12 @@ tasks.register('runAndroidExamples', Exec) { def exampleClass = project.findProperty('example')?.toString()?.trim() if (exampleClass) { + def verboseLogging = project.findProperty('verboseLogging')?.toString()?.trim() ?: 'false' + args 'shell', 'am', 'start', '-n', 'org.jmonkeyengine.jme3androidexamples/.TestActivity', '--es', 'Selected_App_Class', exampleClass, - '--ez', 'Enable_Mouse_Events', 'true', - '--ez', 'Enable_Joystick_Events', 'false', - '--ez', 'Enable_Key_Events', 'true', - '--ez', 'Verbose_Logging', 'false' + '--ez', 'Verbose_Logging', verboseLogging } else { args 'shell', 'am', 'start', '-n', 'org.jmonkeyengine.jme3androidexamples/.MainActivity' diff --git a/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/JmeFragment.java b/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/JmeFragment.java index 8b6eb89b40..85528b4eed 100644 --- a/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/JmeFragment.java +++ b/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/JmeFragment.java @@ -12,9 +12,6 @@ */ public class JmeFragment extends AndroidHarnessFragment { private String appClass; - private boolean joystickEventsEnabled; - private boolean keyEventsEnabled = true; - private boolean mouseEventsEnabled = true; public JmeFragment() { finishOnAppStop = true; @@ -27,13 +24,8 @@ public void onCreate(Bundle savedInstanceState) { appClass = bundle.getString(MainActivity.SELECTED_APP_CLASS); // Log.d(this.getClass().getSimpleName(), "AppClass: " + appClass); - joystickEventsEnabled = bundle.getBoolean(MainActivity.ENABLE_JOYSTICK_EVENTS); -// Log.d(this.getClass().getSimpleName(), "JoystickEventsEnabled: " + joystickEventsEnabled); - keyEventsEnabled = bundle.getBoolean(MainActivity.ENABLE_KEY_EVENTS); -// Log.d(this.getClass().getSimpleName(), "KeyEventsEnabled: " + keyEventsEnabled); - mouseEventsEnabled = bundle.getBoolean(MainActivity.ENABLE_MOUSE_EVENTS); -// Log.d(this.getClass().getSimpleName(), "MouseEventsEnabled: " + mouseEventsEnabled); - boolean verboseLogging = bundle.getBoolean(MainActivity.VERBOSE_LOGGING); + boolean verboseLogging = bundle.getBoolean(MainActivity.VERBOSE_LOGGING, + MainActivity.DEFAULT_VERBOSE_LOGGING); // Log.d(this.getClass().getSimpleName(), "VerboseLogging: " + verboseLogging); if (verboseLogging) { // Set the default logging level (default=Level.INFO, Level.ALL=All Debug Info) @@ -49,7 +41,12 @@ public void onCreate(Bundle savedInstanceState) { @Override protected LegacyApplication createApplication() throws Exception { Class clazz = Class.forName(appClass); - return (LegacyApplication) clazz.getDeclaredConstructor().newInstance(); + LegacyApplication application = (LegacyApplication) clazz.getDeclaredConstructor().newInstance(); + AppSettings settings = new AppSettings(true); + settings.setEmulateMouse(true); + settings.setEmulateKeyboard(true); + application.setSettings(settings); + return application; } } diff --git a/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/MainActivity.java b/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/MainActivity.java index 960e53bc43..acfe4a89d4 100644 --- a/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/MainActivity.java +++ b/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/MainActivity.java @@ -48,29 +48,12 @@ public class MainActivity extends Activity implements OnItemClickListener, View. */ public static final String SELECTED_LIST_POSITION = "Selected_List_Position"; - /** - * Static String to pass the key for the setting for enabling mouse events to the - * savedInstanceState Bundle. - */ - public static final String ENABLE_MOUSE_EVENTS = "Enable_Mouse_Events"; - - /** - * Static String to pass the key for the setting for enabling joystick events to the - * savedInstanceState Bundle. - */ - public static final String ENABLE_JOYSTICK_EVENTS = "Enable_Joystick_Events"; - - /** - * Static String to pass the key for the setting for enabling key events to the - * savedInstanceState Bundle. - */ - public static final String ENABLE_KEY_EVENTS = "Enable_Key_Events"; - /** * Static String to pass the key for the setting for verbose logging to the * savedInstanceState Bundle. */ public static final String VERBOSE_LOGGING = "Verbose_Logging"; + public static final boolean DEFAULT_VERBOSE_LOGGING = false; /* Fields to contain the current position and display contents of the spinner */ private int currentPosition = 0; @@ -93,10 +76,7 @@ public class MainActivity extends Activity implements OnItemClickListener, View. EditText editFilterText; /* Custom settings for the test app */ - private boolean enableMouseEvents = true; - private boolean enableJoystickEvents = false; - private boolean enableKeyEvents = true; - private boolean verboseLogging = false; + private boolean verboseLogging = DEFAULT_VERBOSE_LOGGING; /** @@ -113,10 +93,7 @@ public void onCreate(Bundle savedInstanceState) { ); currentPosition = savedInstanceState.getInt(SELECTED_LIST_POSITION, 0); currentSelection = savedInstanceState.getString(SELECTED_APP_CLASS); - enableMouseEvents = savedInstanceState.getBoolean(ENABLE_MOUSE_EVENTS, true); - enableJoystickEvents = savedInstanceState.getBoolean(ENABLE_JOYSTICK_EVENTS, false); - enableKeyEvents = savedInstanceState.getBoolean(ENABLE_KEY_EVENTS, true); - verboseLogging = savedInstanceState.getBoolean(VERBOSE_LOGGING, true); + verboseLogging = savedInstanceState.getBoolean(VERBOSE_LOGGING, DEFAULT_VERBOSE_LOGGING); } @@ -224,25 +201,12 @@ public void onClick(View view) { /* Get selected class, pack it in the intent and start the test app */ Log.d(TAG, "User selected OK for class: " + currentSelection); Intent intent = new Intent(this, TestActivity.class); -// intent.putExtra(SELECTED_APP_CLASS, currentSelection); -// intent.putExtra(ENABLE_MOUSE_EVENTS, enableMouseEvents); -// intent.putExtra(ENABLE_JOYSTICK_EVENTS, enableJoystickEvents); -// intent.putExtra(ENABLE_KEY_EVENTS, enableKeyEvents); Bundle args = new Bundle(); args.putString(MainActivity.SELECTED_APP_CLASS, currentSelection); // Log.d(this.getClass().getSimpleName(), "AppClass="+currentSelection); - args.putBoolean(MainActivity.ENABLE_MOUSE_EVENTS, enableMouseEvents); -// Log.d(TestActivity.class.getSimpleName(), "MouseEnabled="+enableMouseEvents); - - args.putBoolean(MainActivity.ENABLE_JOYSTICK_EVENTS, enableJoystickEvents); -// Log.d(TestActivity.class.getSimpleName(), "JoystickEnabled="+enableJoystickEvents); - - args.putBoolean(MainActivity.ENABLE_KEY_EVENTS, enableKeyEvents); -// Log.d(TestActivity.class.getSimpleName(), "KeyEnabled="+enableKeyEvents); - args.putBoolean(MainActivity.VERBOSE_LOGGING, verboseLogging); // Log.d(TestActivity.class.getSimpleName(), "VerboseLogging="+verboseLogging); @@ -329,9 +293,6 @@ public void onSaveInstanceState(Bundle savedInstanceState) { Log.d(TAG, "Saving selections in onSaveInstanceState: " + "position: " + currentPosition + ", " + "class: " + currentSelection + ", " - + "mouseEvents: " + enableMouseEvents + ", " - + "joystickEvents: " + enableJoystickEvents + ", " - + "keyEvents: " + enableKeyEvents + ", " + "VerboseLogging: " + verboseLogging + ", " ); // Save current selections to the savedInstanceState. @@ -339,9 +300,6 @@ public void onSaveInstanceState(Bundle savedInstanceState) { // killed and restarted. savedInstanceState.putString(SELECTED_APP_CLASS, currentSelection); savedInstanceState.putInt(SELECTED_LIST_POSITION, currentPosition); - savedInstanceState.putBoolean(ENABLE_MOUSE_EVENTS, enableMouseEvents); - savedInstanceState.putBoolean(ENABLE_JOYSTICK_EVENTS, enableJoystickEvents); - savedInstanceState.putBoolean(ENABLE_KEY_EVENTS, enableKeyEvents); savedInstanceState.putBoolean(VERBOSE_LOGGING, verboseLogging); } @@ -388,36 +346,6 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu (Menu menu) { MenuItem item; - item = menu.findItem(R.id.optionMouseEvents); - if (item != null) { - Log.d(TAG, "Found EnableMouseEvents menu item"); - if (enableMouseEvents) { - item.setTitle(R.string.strOptionDisableMouseEventsTitle); - } else { - item.setTitle(R.string.strOptionEnableMouseEventsTitle); - } - } - - item = menu.findItem(R.id.optionJoystickEvents); - if (item != null) { - Log.d(TAG, "Found EnableJoystickEvents menu item"); - if (enableJoystickEvents) { - item.setTitle(R.string.strOptionDisableJoystickEventsTitle); - } else { - item.setTitle(R.string.strOptionEnableJoystickEventsTitle); - } - } - - item = menu.findItem(R.id.optionKeyEvents); - if (item != null) { - Log.d(TAG, "Found EnableKeyEvents menu item"); - if (enableKeyEvents) { - item.setTitle(R.string.strOptionDisableKeyEventsTitle); - } else { - item.setTitle(R.string.strOptionEnableKeyEventsTitle); - } - } - item = menu.findItem(R.id.optionVerboseLogging); if (item != null) { Log.d(TAG, "Found EnableVerboseLogging menu item"); @@ -434,16 +362,7 @@ public boolean onPrepareOptionsMenu (Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); - if (itemId == R.id.optionMouseEvents) { - enableMouseEvents = !enableMouseEvents; - Log.d(TAG, "enableMouseEvents set to: " + enableMouseEvents); - } else if (itemId == R.id.optionJoystickEvents) { - enableJoystickEvents = !enableJoystickEvents; - Log.d(TAG, "enableJoystickEvents set to: " + enableJoystickEvents); - } else if (itemId == R.id.optionKeyEvents) { - enableKeyEvents = !enableKeyEvents; - Log.d(TAG, "enableKeyEvents set to: " + enableKeyEvents); - } else if (itemId == R.id.optionVerboseLogging) { + if (itemId == R.id.optionVerboseLogging) { verboseLogging = !verboseLogging; Log.d(TAG, "verboseLogging set to: " + verboseLogging); } else { diff --git a/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/TestActivity.java b/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/TestActivity.java index 1251c94118..7473e1403b 100644 --- a/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/TestActivity.java +++ b/jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/TestActivity.java @@ -30,19 +30,8 @@ protected void onCreate(Bundle savedInstanceState) { args.putString(MainActivity.SELECTED_APP_CLASS, appClass); // Log.d(TestActivity.class.getSimpleName(), "AppClass="+appClass); - boolean mouseEnabled = bundle.getBoolean(MainActivity.ENABLE_MOUSE_EVENTS, true); - args.putBoolean(MainActivity.ENABLE_MOUSE_EVENTS, mouseEnabled); -// Log.d(TestActivity.class.getSimpleName(), "MouseEnabled="+mouseEnabled); - - boolean joystickEnabled = bundle.getBoolean(MainActivity.ENABLE_JOYSTICK_EVENTS, true); - args.putBoolean(MainActivity.ENABLE_JOYSTICK_EVENTS, joystickEnabled); -// Log.d(TestActivity.class.getSimpleName(), "JoystickEnabled="+joystickEnabled); - - boolean keyEnabled = bundle.getBoolean(MainActivity.ENABLE_KEY_EVENTS, true); - args.putBoolean(MainActivity.ENABLE_KEY_EVENTS, keyEnabled); -// Log.d(TestActivity.class.getSimpleName(), "KeyEnabled="+keyEnabled); - - boolean verboseLogging = bundle.getBoolean(MainActivity.VERBOSE_LOGGING, true); + boolean verboseLogging = bundle.getBoolean(MainActivity.VERBOSE_LOGGING, + MainActivity.DEFAULT_VERBOSE_LOGGING); args.putBoolean(MainActivity.VERBOSE_LOGGING, verboseLogging); // Log.d(TestActivity.class.getSimpleName(), "VerboseLogging="+verboseLogging); diff --git a/jme3-android-examples/src/main/res/menu/menu_items.xml b/jme3-android-examples/src/main/res/menu/menu_items.xml index 87c8cc6111..be951960bd 100644 --- a/jme3-android-examples/src/main/res/menu/menu_items.xml +++ b/jme3-android-examples/src/main/res/menu/menu_items.xml @@ -2,22 +2,6 @@ xmlns:tools="http://schemas.android.com/tools" tools:context="org.jmonkeyengine.jme3androidexamples.MainActivity"> - - - - Cancel - Enable Mouse Events - Disable Mouse Events - Enable Joystick Events - Disable Joystick Events - Enable Key Events - Disable Key Events Enable Verbose Logging Disable Verbose Logging From 723161e2f2c9d1d32a0e5088c93d3b6061b1f8f1 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Fri, 15 May 2026 18:01:09 +0200 Subject: [PATCH 3/5] remove legacy audio backend handling in android backend --- .../com/jme3/system/android/JmeAndroidSystem.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java b/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java index 7d54c81b9e..e7351dc467 100644 --- a/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java +++ b/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java @@ -32,7 +32,6 @@ public class JmeAndroidSystem extends JmeSystemDelegate { private static View view; - private static String audioRendererType = AppSettings.OPENAL; static { try { @@ -79,16 +78,6 @@ public void writeImageFile(OutputStream outStream, String format, ByteBuffer ima @Override public JmeContext newContext(AppSettings settings, Type contextType) { - if (settings.getAudioRenderer() == null) { - audioRendererType = null; - } else if (settings.getAudioRenderer().equals(AppSettings.ANDROID_MEDIAPLAYER)) { - audioRendererType = AppSettings.ANDROID_MEDIAPLAYER; - } else if (settings.getAudioRenderer().equals(AppSettings.ANDROID_OPENAL_SOFT)||settings.getAudioRenderer().equals(AppSettings.OPENAL)) { - audioRendererType = AppSettings.ANDROID_OPENAL_SOFT; - } else { - logger.log(Level.INFO, "AudioRenderer not set. Defaulting to OpenAL Soft"); - audioRendererType = AppSettings.OPENAL; - } initialize(settings); JmeContext ctx = new OGLESContext(); ctx.setSettings(settings); @@ -206,10 +195,6 @@ public static View getView() { return view; } - public static String getAudioRendererType() { - return audioRendererType; - } - @Override public void showSoftKeyboard(final boolean show) { view.getHandler().post(new Runnable() { From 7cf87460240f04e0709a8aa288899a81918d3144 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Fri, 15 May 2026 18:01:15 +0200 Subject: [PATCH 4/5] add deprecation notices --- jme3-core/src/main/java/com/jme3/system/AppSettings.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/system/AppSettings.java b/jme3-core/src/main/java/com/jme3/system/AppSettings.java index 612533c408..1d7883df0f 100644 --- a/jme3-core/src/main/java/com/jme3/system/AppSettings.java +++ b/jme3-core/src/main/java/com/jme3/system/AppSettings.java @@ -217,6 +217,7 @@ public final class AppSettings extends HashMap { * Use the LWJGL OpenAL based renderer for audio capabilities. * * @see AppSettings#setAudioRenderer(java.lang.String) + * @deprecated Use {@link #OPENAL} instead. */ @Deprecated public static final String LWJGL_OPENAL = "LWJGL"; @@ -232,8 +233,7 @@ public final class AppSettings extends HashMap { * NOTE: Supports Android 2.2+ platforms. * * @see AppSettings#setAudioRenderer(java.lang.String) - * @deprecated This audio renderer has too many limitations. - * use {@link #ANDROID_OPENAL_SOFT} instead. + * @deprecated This audio renderer has too many limitations. Use {@link #OPENAL} instead.. */ @Deprecated public static final String ANDROID_MEDIAPLAYER = "MediaPlayer"; @@ -245,6 +245,7 @@ public final class AppSettings extends HashMap { * NOTE: Only to be used on Android 2.3+ platforms due to using OpenSL. * * @see AppSettings#setAudioRenderer(java.lang.String) + * @deprecated Use {@link #OPENAL} instead. */ @Deprecated public static final String ANDROID_OPENAL_SOFT = "OpenAL_SOFT"; @@ -255,6 +256,7 @@ public final class AppSettings extends HashMap { * N.B: This backend is EXPERIMENTAL * * @see AppSettings#setRenderer(java.lang.String) + * @deprecated Use LWJGL */ @Deprecated public static final String JOGL_OPENGL_FORWARD_COMPATIBLE = "JOGL_OPENGL_FORWARD_COMPATIBLE"; @@ -265,6 +267,7 @@ public final class AppSettings extends HashMap { * N.B: This backend is EXPERIMENTAL * * @see AppSettings#setRenderer(java.lang.String) + * @deprecated Use LWJGL */ @Deprecated public static final String JOGL_OPENGL_BACKWARD_COMPATIBLE = "JOGL_OPENGL_BACKWARD_COMPATIBLE"; @@ -275,6 +278,7 @@ public final class AppSettings extends HashMap { * N.B: This backend is EXPERIMENTAL * * @see AppSettings#setAudioRenderer(java.lang.String) + * @deprecated Use {@link #OPENAL} instead. */ @Deprecated public static final String JOAL = "JOAL"; From 7e2d345291136ee4d339f14822f549f9a4af8968 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Sun, 17 May 2026 16:36:53 +0200 Subject: [PATCH 5/5] refactor audio renderer handling and deprecate legacy methods --- .../com/jme3/system/android/JmeAndroidSystem.java | 12 ++++++++++++ .../main/java/com/jme3/system/AppSettings.java | 15 ++++++++++----- .../java/com/jme3/system/JmeDesktopSystem.java | 10 +++++++--- .../java/com/jme3/system/lwjgl/LwjglContext.java | 3 ++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java b/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java index e7351dc467..28c845d11e 100644 --- a/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java +++ b/jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java @@ -51,6 +51,18 @@ public JmeAndroidSystem(){ }); }); } + + /** + * Returns the default Android audio renderer type. + * + * @return the default Android audio renderer type + * @deprecated Use {@link AppSettings#getAudioRenderer()} and + * {@link AppSettings#OPENAL} instead. + */ + @Deprecated + public String getAudioRendererType() { + return AppSettings.OPENAL; + } @Override public URL getPlatformAssetConfigURL() { diff --git a/jme3-core/src/main/java/com/jme3/system/AppSettings.java b/jme3-core/src/main/java/com/jme3/system/AppSettings.java index 1d7883df0f..46a18ca333 100644 --- a/jme3-core/src/main/java/com/jme3/system/AppSettings.java +++ b/jme3-core/src/main/java/com/jme3/system/AppSettings.java @@ -224,6 +224,11 @@ public final class AppSettings extends HashMap { public static final String ANGLE_GLES3 = "ANGLE_GLES3"; + /** + * Use the default OpenAL renderer for the current platform. + * + * @see AppSettings#setAudioRenderer(java.lang.String) + */ public static final String OPENAL = "OPENAL"; @@ -233,7 +238,7 @@ public final class AppSettings extends HashMap { * NOTE: Supports Android 2.2+ platforms. * * @see AppSettings#setAudioRenderer(java.lang.String) - * @deprecated This audio renderer has too many limitations. Use {@link #OPENAL} instead.. + * @deprecated This audio renderer has too many limitations. Use {@link #OPENAL} instead. */ @Deprecated public static final String ANDROID_MEDIAPLAYER = "MediaPlayer"; @@ -241,7 +246,6 @@ public final class AppSettings extends HashMap { /** * Use the OpenAL Soft based renderer for Android audio capabilities. *

- * This is the current default for Android platforms. * NOTE: Only to be used on Android 2.3+ platforms due to using OpenSL. * * @see AppSettings#setAudioRenderer(java.lang.String) @@ -826,12 +830,13 @@ public void setCustomRenderer(Class clazz) { /** * Set the audio renderer to use. One of:
*

* @param audioRenderer - * (Default: LWJGL) + * (Default: AppSettings.OPENAL) */ public void setAudioRenderer(String audioRenderer) { putString("AudioRenderer", audioRenderer); @@ -1266,7 +1271,7 @@ public boolean useJoysticks() { /** * Get the audio renderer * - * @return the audio renderer's name, for example "LWJGL" + * @return the audio renderer's name, for example "OPENAL" * @see #setAudioRenderer(java.lang.String) */ public String getAudioRenderer() { diff --git a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java index d07fa3cd4f..a8002c075c 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java +++ b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java @@ -257,18 +257,22 @@ public AudioRenderer newAudioRenderer(AppSettings settings) { AL al; ALC alc; EFX efx; - if (settings.getAudioRenderer().startsWith("LWJGL") || settings.getAudioRenderer().equals(AppSettings.OPENAL)) { + String audioRenderer = settings.getAudioRenderer(); + if (audioRenderer == null) { + return null; + } + if (audioRenderer.startsWith("LWJGL") || AppSettings.OPENAL.equals(audioRenderer)) { al = newObject("com.jme3.audio.lwjgl.LwjglAL"); alc = newObject("com.jme3.audio.lwjgl.LwjglALC"); efx = newObject("com.jme3.audio.lwjgl.LwjglEFX"); - } else if (settings.getAudioRenderer().startsWith("JOAL")) { + } else if (audioRenderer.startsWith("JOAL")) { al = newObject("com.jme3.audio.joal.JoalAL"); alc = newObject("com.jme3.audio.joal.JoalALC"); efx = newObject("com.jme3.audio.joal.JoalEFX"); } else { throw new UnsupportedOperationException( "Unrecognizable audio renderer specified: " - + settings.getAudioRenderer()); + + audioRenderer); } if (al == null || alc == null || efx == null) { diff --git a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java index bb6655ae1e..ae1ef0ecb9 100644 --- a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java +++ b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java @@ -224,7 +224,8 @@ protected void loadNatives() { if (JmeSystem.isLowPermissions()) { return; } - if (AppSettings.LWJGL_OPENAL.equals(settings.getAudioRenderer())) { + String audioRenderer = settings.getAudioRenderer(); + if (AppSettings.LWJGL_OPENAL.equals(audioRenderer) || AppSettings.OPENAL.equals(audioRenderer)) { NativeLibraryLoader.loadNativeLibrary(NativeLibraries.OpenAL.getName(), true); } if (settings.useJoysticks()) {