Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,68 +1,50 @@
package jme3test.ios;

import com.jme3.app.Application;
import com.jme3.app.IosApplicationLauncher;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeContext;
import com.jme3.system.SystemListener;
import com.jme3.system.ios.IGLESContext;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public final class IosTestChooserLauncher {
public final class IosTestChooserLauncher extends IosApplicationLauncher {
private static final String CLASS_LIST_RESOURCE = "/jme3test/test-classes.txt";
private static final String IOS_INITIAL_EXAMPLE_CLASS = "jme3test.ios.IosInitialExample";
private static List<String> testClasses;
private static IosTestChooserLauncher activeLauncher;

private Application delegate;
private String pendingClass;

@Override
public void start() {
activeLauncher = this;
delegate = new IosTestChooser();
pendingClass = initialExampleClass();
startDelegate(delegate);
super.start();
}

public JmeContext getContext() {
return null;
@Override
protected Application createApplication() {
return new IosTestChooser();
}

@Override
public void update() {
if (startPendingClass()) {
return;
}
runDelegateFrame();
}

public void reshape(int width, int height) {
if (delegate == null) {
return;
}
JmeContext context = delegate.getContext();
if (context instanceof IGLESContext) {
((IGLESContext) context).resizeFramebuffer(width, height);
return;
}
if (delegate instanceof SystemListener) {
((SystemListener) delegate).reshape(width, height);
return;
}
invokeIfPresent(delegate, "reshape", new Class<?>[]{int.class, int.class}, width, height);
super.update();
}

@Override
public void stop(boolean waitFor) {
if (delegate != null) {
delegate.stop(waitFor);
delegate = null;
}
super.stop(waitFor);
if (activeLauncher == this) {
activeLauncher = null;
}
Expand Down Expand Up @@ -129,12 +111,6 @@ private static Application instantiate(String className) {
}
}

private void startDelegate(Application application) {
invokeSetShowSettings(application);
configureIosSettings(application);
application.start();
}

private void selectForCurrentRun(String className) {
pendingClass = className;
}
Expand All @@ -145,9 +121,18 @@ private boolean startPendingClass() {
return false;
}
pendingClass = null;
stopDelegateForHandoff();
delegate = instantiate(className);
startDelegate(delegate);
stopApplicationForHandoff();
Application selected = instantiate(className);
AppSettings settings = new AppSettings(true);
settings.setUseJoysticks(true);
settings.setOnDeviceJoystickRumble(true);
invokeConfigureSettings(selected, settings);
selected.setSettings(settings);
try{
startApplication(selected);
} catch (Exception exception) {
throw new IllegalStateException("Failed to start selected iOS test: " + className, exception);
}
return true;
}

Expand Down Expand Up @@ -176,25 +161,9 @@ private static String generatedInitialExampleClassName() {
}
}

private void runDelegateFrame() {
if (delegate == null) {
return;
}
JmeContext context = delegate.getContext();
if (context instanceof IGLESContext) {
((IGLESContext) context).runFrame();
return;
}
if (delegate instanceof SystemListener) {
((SystemListener) delegate).update();
return;
}
invokeIfPresent(delegate, "update", new Class<?>[0]);
}

private void stopDelegateForHandoff() {
Application previous = delegate;
delegate = null;
private void stopApplicationForHandoff() {
Application previous = app;
app = null;
if (previous == null) {
return;
}
Expand All @@ -204,47 +173,16 @@ private void stopDelegateForHandoff() {
previous.stop(false);
}

private static void invokeSetShowSettings(Application application) {
try {
application.getClass().getMethod("setShowSettings", boolean.class).invoke(application, false);
} catch (NoSuchMethodException ignored) {
// Some Application subclasses do not expose settings dialogs.
} catch (IllegalAccessException | InvocationTargetException exception) {
throw new IllegalStateException("Could not disable settings dialog", exception);
}
}

private static void configureIosSettings(Application application) {
AppSettings settings = new AppSettings(true);
settings.setUseJoysticks(true);
settings.setOnDeviceJoystickRumble(true);
private static void invokeConfigureSettings(Application application, AppSettings settings) {
try {
java.lang.reflect.Method method = application.getClass().getMethod("configureSettings", AppSettings.class);
Object target = java.lang.reflect.Modifier.isStatic(method.getModifiers()) ? null : application;
Object target = Modifier.isStatic(method.getModifiers()) ? null : application;
method.invoke(target, settings);
} catch (NoSuchMethodException ignored) {
// Most examples rely on default settings.
} catch (IllegalAccessException | InvocationTargetException exception) {
throw new IllegalStateException("Could not configure iOS settings for "
+ application.getClass().getName(), exception);
}
application.setSettings(settings);
}

private static Object invokeIfPresent(Object target, String name, Class<?>[] parameterTypes, Object... args) {
if (target == null) {
return MissingMethod.INSTANCE;
}
try {
return target.getClass().getMethod(name, parameterTypes).invoke(target, args);
} catch (NoSuchMethodException ignored) {
return MissingMethod.INSTANCE;
} catch (IllegalAccessException | InvocationTargetException exception) {
throw new IllegalStateException("Could not invoke " + name, exception);
}
}

private enum MissingMethod {
INSTANCE
}
}
98 changes: 98 additions & 0 deletions jme3-ios/src/main/java/com/jme3/app/IosApplicationLauncher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2009-2026 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.app;

import com.jme3.system.JmeContext;
import com.jme3.system.ios.IGLESContext;

/**
* Base iOS launcher for jME
* Extend this class and implement {@link #createApplication()} to return the jME application to run.
*
*/
public abstract class IosApplicationLauncher {

protected Application app;

This comment was marked as low quality.


public void start() {
try {
startApplication(createApplication());
} catch (Exception exception) {
throw new IllegalStateException("jME application initialization failed", exception);
}
}

protected void startApplication(Application application) throws Exception {
app = application;
if (app instanceof SimpleApplication) {
((SimpleApplication) app).setShowSettings(false);
}
app.start();
}

/**
* Creates the jME application hosted by this launcher.
*
* @return the application instance
* @throws Exception if the application cannot be created
*/
protected abstract Application createApplication() throws Exception;

public void update() {
if (app == null) return;
JmeContext context = app.getContext();
if (context == null) return;
if (context instanceof IGLESContext) {
((IGLESContext) context).runFrame();
} else {
throw new IllegalStateException("Application context is not an IGLESContext");
}
}
Comment thread
riccardobl marked this conversation as resolved.
Comment on lines +70 to +79

This comment was marked as low quality.


public void resize(int width, int height) {
if (app == null) return;
JmeContext context = app.getContext();
if (context == null) return;
if (context instanceof IGLESContext) {
((IGLESContext) context).resizeFramebuffer(width, height);
} else {
throw new IllegalStateException("Application context is not an IGLESContext");
}
}
Comment thread
riccardobl marked this conversation as resolved.
Comment on lines +81 to +90

This comment was marked as low quality.


public void stop(boolean waitFor) {
if (app != null) {
app.stop(waitFor);
app = null;
}
}
}
Loading