OSDN Git Service

Timer, better error messages.
authorNathanSweet <nathan.sweet@gmail.com>
Tue, 19 Feb 2013 14:50:24 +0000 (15:50 +0100)
committerNathanSweet <nathan.sweet@gmail.com>
Tue, 19 Feb 2013 14:50:24 +0000 (15:50 +0100)
MathUtils, PI2.
Slider, clamp, don't throw, when setValue is out of range.
LwjglGraphics, pause between create display tries.

backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGraphics.java
gdx/src/com/badlogic/gdx/math/MathUtils.java
gdx/src/com/badlogic/gdx/scenes/scene2d/InputListener.java
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Slider.java
gdx/src/com/badlogic/gdx/utils/Timer.java

index 706db4f..ee4f57a 100644 (file)
@@ -192,6 +192,10 @@ public class LwjglGraphics implements Graphics {
                } catch (Exception ex) {\r
                        Display.destroy();\r
                        try {\r
+                               Thread.sleep(200);\r
+                       } catch (InterruptedException ignored) {\r
+                       }\r
+                       try {\r
                                Display.create(new PixelFormat(0, 16, 8));\r
                                if (getDesktopDisplayMode().bitsPerPixel == 16) {\r
                                        bufferFormat = new BufferFormat(5, 6, 5, 0, 16, 8, 0, false);\r
@@ -205,6 +209,10 @@ public class LwjglGraphics implements Graphics {
                        } catch (Exception ex2) {\r
                                Display.destroy();\r
                                try {\r
+                                       Thread.sleep(200);\r
+                               } catch (InterruptedException ignored) {\r
+                               }\r
+                               try {\r
                                        Display.create(new PixelFormat());\r
                                } catch (Exception ex3) {\r
                                        if (ex3.getMessage().contains("Pixel format not accelerated"))\r
index 11056e3..800b249 100644 (file)
@@ -30,6 +30,7 @@ public class MathUtils {
        // ---\r
 \r
        static public final float PI = 3.1415927f;\r
+       public static final float PI2 = PI * 2;\r
 \r
        static private final int SIN_BITS = 13; // Adjust for accuracy.\r
        static private final int SIN_MASK = ~(-1 << SIN_BITS);\r
index 3ecbf5b..7893ffb 100644 (file)
@@ -22,7 +22,6 @@ import com.badlogic.gdx.math.Vector2;
  * the methods here do nothing with the event.  Users are expected to override the methods they are interested in, like this:\r
  * \r
  * <pre>\r
- * {@code\r
  * actor.addListener(new InputListener() {\r
  *    public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {\r
  *       Gdx.app.log("Example", "touch started at (" +x+ ", " +y+ ")");\r
@@ -31,7 +30,6 @@ import com.badlogic.gdx.math.Vector2;
  *       Gdx.app.log("Example", "touch done at (" +x+ ", " +y+ ")");\r
  *    }\r
  * });\r
- * }\r
  * </pre>\r
  */\r
 public class InputListener implements EventListener {\r
index bd7005c..f3455b8 100644 (file)
@@ -219,7 +219,6 @@ public class Slider extends Widget {
 \r
        /** Sets the slider position, rounded to the nearest step size and clamped to the minumum and maximim values. */\r
        public void setValue (float value) {\r
-               if (value < min || value > max) throw new IllegalArgumentException("value must be >= min and <= max: " + value);\r
                value = MathUtils.clamp(Math.round(value / stepSize) * stepSize, min, max);\r
                float oldValue = this.value;\r
                if (value == oldValue) return;\r
index 7fccd77..4b7228e 100644 (file)
@@ -30,8 +30,13 @@ public class Timer {
                                        synchronized (instances) {\r
                                                float time = System.nanoTime() * MathUtils.nanoToSec;\r
                                                float wait = Float.MAX_VALUE;\r
-                                               for (int i = 0, n = instances.size; i < n; i++)\r
-                                                       wait = Math.min(wait, instances.get(i).update(time));\r
+                                               for (int i = 0, n = instances.size; i < n; i++) {\r
+                                                       try {\r
+                                                               wait = instances.get(i).update(time, wait);\r
+                                                       } catch (Throwable ex) {\r
+                                                               throw new GdxRuntimeException("Task failed: " + instances.get(i).getClass().getName(), ex);\r
+                                                       }\r
+                                               }\r
                                                long waitMillis = (long)(wait * 1000);\r
                                                try {\r
                                                        if (waitMillis > 0) instances.wait(waitMillis);\r
@@ -78,7 +83,7 @@ public class Timer {
                task.executeTime = System.nanoTime() * MathUtils.nanoToSec + delaySeconds;\r
                task.intervalSeconds = intervalSeconds;\r
                task.repeatCount = repeatCount;\r
-               synchronized(tasks) {\r
+               synchronized (tasks) {\r
                        tasks.add(task);\r
                }\r
                wake();\r
@@ -102,16 +107,15 @@ public class Timer {
 \r
        /** Cancels all tasks. */\r
        public void clear () {\r
-               synchronized(tasks) {\r
+               synchronized (tasks) {\r
                        for (int i = 0, n = tasks.size; i < n; i++)\r
                                tasks.get(i).cancel();\r
                        tasks.clear();\r
                }\r
        }\r
 \r
-       float update (float time) {\r
-               float wait = Float.MAX_VALUE;\r
-               synchronized(tasks) {\r
+       float update (float time, float wait) {\r
+               synchronized (tasks) {\r
                        for (int i = 0, n = tasks.size; i < n; i++) {\r
                                Task task = tasks.get(i);\r
                                if (task.executeTime > time) {\r
@@ -119,7 +123,10 @@ public class Timer {
                                        continue;\r
                                }\r
                                if (task.repeatCount != CANCELLED) {\r
-                                       if (task.repeatCount == 0) task.repeatCount = CANCELLED; // Set cancelled before run so it may be rescheduled in run.\r
+                                       if (task.repeatCount == 0) {\r
+                                               // Set cancelled before run so it may be rescheduled in run.\r
+                                               task.repeatCount = CANCELLED;\r
+                                       }\r
                                        Gdx.app.postRunnable(task);\r
                                }\r
                                if (task.repeatCount == CANCELLED) {\r