Browse code

Provide optional emulation of iOS activation.

This will speed up the test cycle for activation. Of course, full device testing is still needed
once the java version is debugged.

Jamie Doornbos authored on 28/04/2014 23:59:53
Showing 1 changed files
... ...
@@ -70,6 +70,10 @@ public class JavaPlatform extends AbstractPlatform {
70 70
     /** If {link #emulateTouch} is set, sets the pivot for a two-finger touch when pressed. */
71 71
     public Key pivotKey = Key.F11;
72 72
 
73
+    /** If set, toggles the activation mode when pressed. This is for emulating the active
74
+     * state found in {@code IOSGameView}. */
75
+    public Key activationKey;
76
+
73 77
     /** If set, converts images into a format for fast GPU uploads when initially loaded versus
74 78
      * doing it on demand when displayed. Assuming asynchronous image loads, this keeps that effort
75 79
      * off the main thread so it doesn't cause slow frames.
... ...
@@ -132,6 +136,7 @@ public class JavaPlatform extends AbstractPlatform {
132 136
   private final JavaMouse mouse;
133 137
   private final JavaAssets assets = new JavaAssets(this);
134 138
   private final Keyboard.Listener keyListener;
139
+  private boolean active = true;
135 140
 
136 141
   private final ExecutorService _exec = Executors.newFixedThreadPool(4);
137 142
   private final long start = System.nanoTime();
... ...
@@ -152,12 +157,15 @@ public class JavaPlatform extends AbstractPlatform {
152 157
       mouse = createMouse();
153 158
     }
154 159
 
155
-    if (touch instanceof JavaEmulatedTouch) {
160
+    if (touch instanceof JavaEmulatedTouch || config.activationKey != null) {
156 161
       final Key pivotKey = (touch instanceof JavaEmulatedTouch) ? config.pivotKey : null;
162
+      final Key activationKey = config.activationKey;
157 163
       keyListener = new Keyboard.Adapter() {
158 164
         @Override public void onKeyUp (playn.core.Keyboard.Event event) {
159 165
           if (event.key() == pivotKey)
160 166
             ((JavaEmulatedTouch)touch).updatePivot();
167
+          else if (event.key() == activationKey)
168
+            toggleActivation();
161 169
         }
162 170
       };
163 171
     } else {
... ...
@@ -352,7 +360,12 @@ public class JavaPlatform extends AbstractPlatform {
352 360
 
353 361
     // Run the game loop, render the scene graph, and update the display.
354 362
     game.tick(tick());
355
-    graphics.paint();
363
+    if (active)
364
+      graphics.paint();
365
+  }
366
+
367
+  protected void toggleActivation () {
368
+    active = !active;
356 369
   }
357 370
 
358 371
   protected void unpackNatives() {