11package jme3test .ios ;
22
33import com .jme3 .app .Application ;
4+ import com .jme3 .app .IosApplicationLauncher ;
45import com .jme3 .system .AppSettings ;
5- import com .jme3 .system .JmeContext ;
6- import com .jme3 .system .SystemListener ;
7- import com .jme3 .system .ios .IGLESContext ;
86import java .io .BufferedReader ;
97import java .io .IOException ;
108import java .io .InputStream ;
119import java .io .InputStreamReader ;
1210import java .lang .reflect .InvocationTargetException ;
11+ import java .lang .reflect .Modifier ;
1312import java .nio .charset .StandardCharsets ;
1413import java .util .ArrayList ;
1514import java .util .Collections ;
1615import java .util .List ;
1716
18- public final class IosTestChooserLauncher {
17+ public final class IosTestChooserLauncher extends IosApplicationLauncher {
1918 private static final String CLASS_LIST_RESOURCE = "/jme3test/test-classes.txt" ;
2019 private static final String IOS_INITIAL_EXAMPLE_CLASS = "jme3test.ios.IosInitialExample" ;
2120 private static List <String > testClasses ;
2221 private static IosTestChooserLauncher activeLauncher ;
2322
24- private Application delegate ;
2523 private String pendingClass ;
2624
25+ @ Override
2726 public void start () {
2827 activeLauncher = this ;
29- delegate = new IosTestChooser ();
3028 pendingClass = initialExampleClass ();
31- startDelegate ( delegate );
29+ super . start ( );
3230 }
3331
34- public JmeContext getContext () {
35- return null ;
32+ @ Override
33+ protected Application createApplication () {
34+ return new IosTestChooser ();
3635 }
3736
37+ @ Override
3838 public void update () {
3939 if (startPendingClass ()) {
4040 return ;
4141 }
42- runDelegateFrame ();
43- }
44-
45- public void reshape (int width , int height ) {
46- if (delegate == null ) {
47- return ;
48- }
49- JmeContext context = delegate .getContext ();
50- if (context instanceof IGLESContext ) {
51- ((IGLESContext ) context ).resizeFramebuffer (width , height );
52- return ;
53- }
54- if (delegate instanceof SystemListener ) {
55- ((SystemListener ) delegate ).reshape (width , height );
56- return ;
57- }
58- invokeIfPresent (delegate , "reshape" , new Class <?>[]{int .class , int .class }, width , height );
42+ super .update ();
5943 }
6044
45+ @ Override
6146 public void stop (boolean waitFor ) {
62- if (delegate != null ) {
63- delegate .stop (waitFor );
64- delegate = null ;
65- }
47+ super .stop (waitFor );
6648 if (activeLauncher == this ) {
6749 activeLauncher = null ;
6850 }
@@ -129,12 +111,6 @@ private static Application instantiate(String className) {
129111 }
130112 }
131113
132- private void startDelegate (Application application ) {
133- invokeSetShowSettings (application );
134- configureIosSettings (application );
135- application .start ();
136- }
137-
138114 private void selectForCurrentRun (String className ) {
139115 pendingClass = className ;
140116 }
@@ -145,9 +121,18 @@ private boolean startPendingClass() {
145121 return false ;
146122 }
147123 pendingClass = null ;
148- stopDelegateForHandoff ();
149- delegate = instantiate (className );
150- startDelegate (delegate );
124+ stopApplicationForHandoff ();
125+ Application selected = instantiate (className );
126+ AppSettings settings = new AppSettings (true );
127+ settings .setUseJoysticks (true );
128+ settings .setOnDeviceJoystickRumble (true );
129+ invokeConfigureSettings (selected , settings );
130+ selected .setSettings (settings );
131+ try {
132+ startApplication (selected );
133+ } catch (Exception exception ) {
134+ throw new IllegalStateException ("Failed to start selected iOS test: " + className , exception );
135+ }
151136 return true ;
152137 }
153138
@@ -176,25 +161,9 @@ private static String generatedInitialExampleClassName() {
176161 }
177162 }
178163
179- private void runDelegateFrame () {
180- if (delegate == null ) {
181- return ;
182- }
183- JmeContext context = delegate .getContext ();
184- if (context instanceof IGLESContext ) {
185- ((IGLESContext ) context ).runFrame ();
186- return ;
187- }
188- if (delegate instanceof SystemListener ) {
189- ((SystemListener ) delegate ).update ();
190- return ;
191- }
192- invokeIfPresent (delegate , "update" , new Class <?>[0 ]);
193- }
194-
195- private void stopDelegateForHandoff () {
196- Application previous = delegate ;
197- delegate = null ;
164+ private void stopApplicationForHandoff () {
165+ Application previous = app ;
166+ app = null ;
198167 if (previous == null ) {
199168 return ;
200169 }
@@ -204,47 +173,16 @@ private void stopDelegateForHandoff() {
204173 previous .stop (false );
205174 }
206175
207- private static void invokeSetShowSettings (Application application ) {
208- try {
209- application .getClass ().getMethod ("setShowSettings" , boolean .class ).invoke (application , false );
210- } catch (NoSuchMethodException ignored ) {
211- // Some Application subclasses do not expose settings dialogs.
212- } catch (IllegalAccessException | InvocationTargetException exception ) {
213- throw new IllegalStateException ("Could not disable settings dialog" , exception );
214- }
215- }
216-
217- private static void configureIosSettings (Application application ) {
218- AppSettings settings = new AppSettings (true );
219- settings .setUseJoysticks (true );
220- settings .setOnDeviceJoystickRumble (true );
176+ private static void invokeConfigureSettings (Application application , AppSettings settings ) {
221177 try {
222178 java .lang .reflect .Method method = application .getClass ().getMethod ("configureSettings" , AppSettings .class );
223- Object target = java . lang . reflect . Modifier .isStatic (method .getModifiers ()) ? null : application ;
179+ Object target = Modifier .isStatic (method .getModifiers ()) ? null : application ;
224180 method .invoke (target , settings );
225181 } catch (NoSuchMethodException ignored ) {
226182 // Most examples rely on default settings.
227183 } catch (IllegalAccessException | InvocationTargetException exception ) {
228184 throw new IllegalStateException ("Could not configure iOS settings for "
229185 + application .getClass ().getName (), exception );
230186 }
231- application .setSettings (settings );
232- }
233-
234- private static Object invokeIfPresent (Object target , String name , Class <?>[] parameterTypes , Object ... args ) {
235- if (target == null ) {
236- return MissingMethod .INSTANCE ;
237- }
238- try {
239- return target .getClass ().getMethod (name , parameterTypes ).invoke (target , args );
240- } catch (NoSuchMethodException ignored ) {
241- return MissingMethod .INSTANCE ;
242- } catch (IllegalAccessException | InvocationTargetException exception ) {
243- throw new IllegalStateException ("Could not invoke " + name , exception );
244- }
245- }
246-
247- private enum MissingMethod {
248- INSTANCE
249187 }
250188}
0 commit comments