OSDN Git Service

Merge pull request #48 from psiegel/master
authorNathan Sweet <nathan.sweet@gmail.com>
Thu, 4 Oct 2012 05:47:23 +0000 (22:47 -0700)
committerNathan Sweet <nathan.sweet@gmail.com>
Thu, 4 Oct 2012 05:47:23 +0000 (22:47 -0700)
Added support for right/bottom edge fill lines in .9.png files.

12 files changed:
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplication.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglNet.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglServerSocket.java [new file with mode: 0644]
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglSocket.java [new file with mode: 0644]
backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/lang/System.java
gdx/src/com/badlogic/gdx/Net.java
gdx/src/com/badlogic/gdx/net/ServerSocket.java
gdx/src/com/badlogic/gdx/net/ServerSocketHints.java
gdx/src/com/badlogic/gdx/net/SocketHints.java
gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java
gdx/src/com/badlogic/gdx/scenes/scene2d/InputEvent.java
gdx/src/com/badlogic/gdx/utils/BinaryHeap.java

index a5c0240..2ad327b 100644 (file)
@@ -151,6 +151,11 @@ public class LwjglApplication implements Application {
                                        }\r
                                }\r
                        }\r
+                       \r
+                       // if one of the runnables set running in false, for example after an exit().\r
+                       if (!running)\r
+                               break;\r
+                       \r
                        input.update();\r
                        shouldRender |= graphics.shouldRender();\r
 \r
index bd1fbc7..e2355d1 100755 (executable)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  * \r
- *   http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  * \r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -23,6 +23,7 @@ import com.badlogic.gdx.net.Socket;
 import com.badlogic.gdx.net.SocketHints;\r
 \r
 public class LwjglNet implements Net {\r
+       \r
        @Override\r
        public HttpResult httpGet (String url, String... parameters) {\r
                throw new UnsupportedOperationException("Not implemented");\r
@@ -35,11 +36,11 @@ public class LwjglNet implements Net {
 \r
        @Override\r
        public ServerSocket newServerSocket (Protocol protocol, int port, ServerSocketHints hints) {\r
-               throw new UnsupportedOperationException("Not implemented");\r
+               return new LwjglServerSocket(protocol, port, hints);\r
        }\r
-\r
+       \r
        @Override\r
        public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {\r
-               throw new UnsupportedOperationException("Not implemented");\r
+               return new LwjglSocket(protocol, host, port, hints);\r
        }\r
 }\r
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglServerSocket.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglServerSocket.java
new file mode 100644 (file)
index 0000000..ee2ff91
--- /dev/null
@@ -0,0 +1,84 @@
+package com.badlogic.gdx.backends.lwjgl;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+
+import com.badlogic.gdx.Net.Protocol;
+import com.badlogic.gdx.net.ServerSocket;
+import com.badlogic.gdx.net.ServerSocketHints;
+import com.badlogic.gdx.net.Socket;
+import com.badlogic.gdx.net.SocketHints;
+import com.badlogic.gdx.utils.GdxRuntimeException;
+
+/**
+ * Server socket implementation using java.net.ServerSocket.
+ * 
+ * @author noblemaster
+ */
+public class LwjglServerSocket implements ServerSocket {
+
+       private Protocol protocol;
+       
+       /** Our server or null for disposed, aka closed. */
+       private java.net.ServerSocket server;
+       
+       
+       public LwjglServerSocket(Protocol protocol, int port, ServerSocketHints hints) {
+               this.protocol = protocol;
+               
+               // create the server socket
+               try {
+                       // initialize
+                       server = new java.net.ServerSocket();
+                       if (hints != null) {
+                               server.setPerformancePreferences(hints.performancePrefConnectionTime, 
+                                                                                                                       hints.performancePrefLatency, 
+                                                                                                                       hints.performancePrefBandwidth);
+                               server.setReuseAddress(hints.reuseAddress);
+                               server.setSoTimeout(hints.acceptTimeout);
+                               server.setReceiveBufferSize(hints.receiveBufferSize);
+                       }
+                       
+                       // and bind the server...
+                       InetSocketAddress address = new InetSocketAddress(port);
+                       if (hints != null) {
+                               server.bind(address, hints.backlog);
+                       }
+                       else {
+                               server.bind(address);
+                       }
+               }
+               catch (Exception e) {
+                       throw new GdxRuntimeException("Cannot create a server socket at port " + port + ".", e);
+               }
+       }
+
+       @Override
+       public Protocol getProtocol () {
+               return protocol;
+       }
+
+       @Override
+       public Socket accept(SocketHints hints) {
+               try {
+                       return new LwjglSocket(server.accept(), hints);
+               }
+               catch (Exception e) {
+                       throw new GdxRuntimeException("Error accepting socket.", e);
+               }
+       }
+
+       @Override
+       public void dispose() {
+               if (server != null) {
+                       try {
+                               server.close();
+                               server = null;
+                       }
+                       catch (Exception e) {
+                               throw new GdxRuntimeException("Error closing server.", e);
+                       }
+               }
+       }
+}
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglSocket.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglSocket.java
new file mode 100644 (file)
index 0000000..295ef5c
--- /dev/null
@@ -0,0 +1,110 @@
+package com.badlogic.gdx.backends.lwjgl;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+
+import com.badlogic.gdx.Net.Protocol;
+import com.badlogic.gdx.net.ServerSocketHints;
+import com.badlogic.gdx.net.Socket;
+import com.badlogic.gdx.net.SocketHints;
+import com.badlogic.gdx.utils.GdxRuntimeException;
+
+/**
+ * Socket implementation using java.net.Socket.
+ * 
+ * @author noblemaster
+ */
+public class LwjglSocket implements Socket {
+
+       /** Our socket or null for disposed, aka closed. */
+       private java.net.Socket socket;
+       
+       
+       public LwjglSocket(Protocol protocol, String host, int port, SocketHints hints) {
+               try {
+                       // create the socket
+                       socket = new java.net.Socket();
+                       applyHints(hints);  // better to call BEFORE socket is connected!
+                       
+                       // and connect...
+                       InetSocketAddress address = new InetSocketAddress(host, port);
+                       if (hints != null) {
+                               socket.connect(address, hints.connectTimeout);
+                       }
+                       else {
+                               socket.connect(address);
+                       }
+               }
+               catch (Exception e) {
+                       throw new GdxRuntimeException("Error making a socket connection to " + host + ":" + port, e);
+               }
+       }
+       
+       public LwjglSocket(java.net.Socket socket, SocketHints hints) {
+               this.socket = socket;
+               applyHints(hints);
+       }
+       
+       private void applyHints(SocketHints hints) {
+               if (hints != null) {
+                       try {   
+                               socket.setPerformancePreferences(hints.performancePrefConnectionTime, 
+                                                                                                                       hints.performancePrefLatency, 
+                                                                                                                       hints.performancePrefBandwidth);
+                               socket.setTrafficClass(hints.trafficClass);
+                               socket.setTcpNoDelay(hints.tcpNoDelay);
+                               socket.setKeepAlive(hints.keepAlive);
+                               socket.setSendBufferSize(hints.sendBufferSize);
+                               socket.setReceiveBufferSize(hints.receiveBufferSize);
+                               socket.setSoLinger(hints.linger, hints.lingerDuration);
+                       }
+                       catch (Exception e) {
+                               throw new GdxRuntimeException("Error setting socket hints." , e);
+                       }
+               }
+       }
+       
+       @Override
+       public boolean isConnected () {
+               if (socket != null) {
+                       return socket.isConnected();
+               }
+               else {
+                       return false;
+               }
+       }
+
+       @Override
+       public InputStream getInputStream () {
+               try {
+                       return socket.getInputStream();
+               }
+               catch (Exception e) {
+                       throw new GdxRuntimeException("Error getting input stream from socket.", e);
+               }
+       }
+
+       @Override
+       public OutputStream getOutputStream () {
+               try {
+                       return socket.getOutputStream();
+               }
+               catch (Exception e) {
+                       throw new GdxRuntimeException("Error getting output stream from socket.", e);
+               }
+       }
+
+       @Override
+       public void dispose() {
+               if (socket != null) {
+                       try {
+                               socket.close();
+                               socket = null;
+                       }
+                       catch (Exception e) {
+                               throw new GdxRuntimeException("Error closing socket.", e);
+                       }
+               }
+       }
+}
index 5b311ad..75c6b39 100644 (file)
@@ -143,7 +143,7 @@ public final class System {
     if (src == dest && srcOfs < destOfs) {\r
       srcOfs += len;\r
       for (var destEnd = destOfs + len; destEnd-- > destOfs;) {\r
-        dst[destEnd] = src[--srcOfs];\r
+        dest[destEnd] = src[--srcOfs];\r
       }\r
     } else {\r
       for (var destEnd = destOfs + len; destOfs < destEnd;) {\r
index 8f2e352..d0f8df1 100755 (executable)
@@ -44,9 +44,10 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
  * that waits for an incoming connection.\r
  * \r
  * @author mzechner\r
- *\r
+ * @author noblemaster\r
  */\r
 public interface Net {\r
+       \r
        /**\r
         * {@link Future} like interface used with the HTTP get\r
         * and post methods. Allows to cancel the operation, \r
@@ -130,7 +131,8 @@ public interface Net {
         * waiting for incoming connections.\r
         * \r
         * @param port the port to listen on\r
-        * @param hints additional {@link ServerSocketHints} used to create the socket\r
+        * @param hints additional {@link ServerSocketHints} used to create the socket. Input null to\r
+        *        use the default setting provided by the system.\r
         * @return the {@link ServerSocket}\r
         * @throws GdxRuntimeException in case the socket couldn't be opened\r
         */\r
@@ -141,7 +143,8 @@ public interface Net {
         * \r
         * @param host the host address\r
         * @param port the port\r
-        * @param hints additional {@link SocketHints} used to create the socket\r
+        * @param hints additional {@link SocketHints} used to create the socket. Input null to\r
+        *        use the default setting provided by the system.\r
         * @return GdxRuntimeException in case the socket couldn't be opened\r
         */\r
        public Socket newClientSocket(Protocol protocol, String host, int port, SocketHints hints);\r
index 47dba2c..4179e73 100755 (executable)
@@ -16,6 +16,7 @@
 package com.badlogic.gdx.net;\r
 \r
 import com.badlogic.gdx.Net.Protocol;\r
+import com.badlogic.gdx.utils.Disposable;\r
 import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
@@ -24,9 +25,10 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
  * should preferably be called in a separate thread as it is blocking.\r
  * \r
  * @author mzechner\r
- *\r
+ * @author noblemaster\r
  */\r
-public interface ServerSocket {\r
+public interface ServerSocket extends Disposable {\r
+       \r
        /**\r
         * @return the Protocol used by this socket\r
         */\r
@@ -37,7 +39,8 @@ public interface ServerSocket {
         * given hints will be applied to the accepted socket. Blocking, call\r
         * on a separate thread.\r
         * \r
-        * @param hints additional {@link SocketHints} applied to the accepted {@link Socket}\r
+        * @param hints additional {@link SocketHints} applied to the accepted {@link Socket}. Input null to\r
+        *        use the default setting provided by the system.\r
         * @return the accepted {@link Socket}\r
         * @throws GdxRuntimeException in case an error ocurred\r
         */\r
index 58abab6..b979321 100755 (executable)
@@ -17,9 +17,33 @@ package com.badlogic.gdx.net;
 \r
 /**\r
  * Options for {@link ServerSocket} instances.\r
+ * \r
  * @author mzechner\r
- *\r
+ * @author noblemaster \r
  */\r
 public class ServerSocketHints {\r
 \r
+       /** The listen backlog length. Needs to be greater than 0, otherwise the default is used. */\r
+       public int backlog = 16;\r
+       \r
+       /**\r
+        * Performance preferences are described by three integers whose values indicate the relative \r
+        * importance of short connection time, low latency, and high bandwidth. The absolute \r
+        * values of the integers are irrelevant; in order to choose a protocol the values are \r
+        * simply compared, with larger values indicating stronger preferences. \r
+        * Negative values represent a lower priority than positive values. If the application \r
+        * prefers short connection time over both low latency and high bandwidth, for example, \r
+        * then it could invoke this method with the values (1, 0, 0). If the application \r
+        * prefers high bandwidth above low latency, and low latency above short connection \r
+        * time, then it could invoke this method with the values (0, 1, 2).\r
+        */\r
+       public int performancePrefConnectionTime = 0;\r
+       public int performancePrefLatency = 1;   // low latency\r
+       public int performancePrefBandwidth = 0;\r
+       /** Enable/disable the SO_REUSEADDR socket option. */\r
+       public boolean reuseAddress = true;\r
+       /** The SO_TIMEOUT in milliseconds for how long to wait during server.accept(). Enter 0 for infinite wait. */\r
+       public int acceptTimeout = 5000;\r
+       /** The SO_RCVBUF (receive buffer) size in bytes for server.accept(). */\r
+       public int receiveBufferSize = 4096;\r
 }\r
index 07b09d9..f2c092e 100755 (executable)
@@ -5,7 +5,7 @@
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
  * \r
- *   http://www.apache.org/licenses/LICENSE-2.0\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
  * \r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
@@ -17,9 +17,52 @@ package com.badlogic.gdx.net;
 \r
 /**\r
  * Options for {@link Socket} instances.\r
+ * \r
  * @author mzechner\r
- *\r
+ * @author noblemaster\r
  */\r
 public class SocketHints {\r
 \r
+       /** The connection timeout in milliseconds. Not used for sockets created via server.accept(). */\r
+       public int connectTimeout = 5000;\r
+       \r
+       /**\r
+        * Performance preferences are described by three integers whose values indicate the relative \r
+        * importance of short connection time, low latency, and high bandwidth. The absolute \r
+        * values of the integers are irrelevant; in order to choose a protocol the values are \r
+        * simply compared, with larger values indicating stronger preferences. \r
+        * Negative values represent a lower priority than positive values. If the application \r
+        * prefers short connection time over both low latency and high bandwidth, for example, \r
+        * then it could invoke this method with the values (1, 0, 0). If the application \r
+        * prefers high bandwidth above low latency, and low latency above short connection \r
+        * time, then it could invoke this method with the values (0, 1, 2).\r
+        */\r
+       public int performancePrefConnectionTime = 0;\r
+       public int performancePrefLatency = 1;   // low latency\r
+       public int performancePrefBandwidth = 0;\r
+       /**\r
+        * The traffic class describes the type of connection that shall be established.  \r
+        * The traffic class must be in the range 0 <= trafficClass <= 255.\r
+        * <p>\r
+        * The traffic class is bitset created by bitwise-or'ing values such the following :\r
+        *  <ul>\r
+        *    <li>IPTOS_LOWCOST (0x02) - cheap!\r
+        *    <li>IPTOS_RELIABILITY (0x04) - reliable connection with little package loss.\r
+        *    <li>IPTOS_THROUGHPUT (0x08) - lots of data being sent.\r
+        *    <li>IPTOS_LOWDELAY (0x10) - low delay.\r
+        *  </ul>\r
+        */\r
+       public int trafficClass = 0x14;   // low delay + reliable\r
+       /** True to enable  SO_KEEPALIVE. */\r
+       public boolean keepAlive = true;\r
+       /** True to enable TCP_NODELAY (disable/enable Nagle's algorithm). */ \r
+       public boolean tcpNoDelay = true;\r
+       /** The SO_SNDBUF (send buffer) size in bytes. */\r
+       public int sendBufferSize = 4096;\r
+       /** The SO_RCVBUF (receive buffer) size in bytes. */\r
+       public int receiveBufferSize = 4096;\r
+       /** Enable/disable SO_LINGER with the specified linger time in seconds. Only affects socket close. */\r
+       public boolean linger = false;\r
+       /** The linger duration in seconds (NOT milliseconds!). Only used if linger is true! */\r
+       public int lingerDuration = 0;\r
 }\r
index 7b75f79..d0873ea 100644 (file)
@@ -511,6 +511,13 @@ public class Actor {
                return parent.getChildren().indexOf(this, true);\r
        }\r
 \r
+       /** Transforms the specified point in screen coordinates to the actor's local coordinate system. */\r
+       public Vector2 screenToLocalCoordinates (Vector2 screenCoords) {\r
+               Stage stage = getStage();\r
+               if (stage == null) return screenCoords;\r
+               return stageToLocalCoordinates(stage.screenToStageCoordinates(screenCoords));\r
+       }\r
+\r
        /** Transforms the specified point in the stage's coordinates to the actor's local coordinate system. */\r
        public Vector2 stageToLocalCoordinates (Vector2 stageCoords) {\r
                if (parent == null) return stageCoords;\r
index 3954030..f05ae72 100644 (file)
@@ -30,6 +30,7 @@ public class InputEvent extends Event {
        public void reset () {\r
                super.reset();\r
                relatedActor = null;\r
+               button = -1;\r
        }\r
 \r
        /** The stage x coordinate where the event occured. Valid for: touchDown, touchDragged, touchUp, mouseMoved, enter, and exit. */\r
index 673f559..9e79929 100644 (file)
 package com.badlogic.gdx.utils;\r
 \r
 /** @author Nathan Sweet */\r
-public class BinaryHeap<T> {\r
+public class BinaryHeap<T extends BinaryHeap.Node> {\r
        public int size = 0;\r
 \r
-       private Node<T>[] nodes;\r
+       private Node[] nodes;\r
        private final boolean isMaxHeap;\r
 \r
        public BinaryHeap () {\r
@@ -32,7 +32,7 @@ public class BinaryHeap<T> {
                nodes = new Node[capacity];\r
        }\r
 \r
-       public Node add (Node node) {\r
+       public T add (T node) {\r
                // Expand if necessary.\r
                if (size == nodes.length) {\r
                        Node[] newNodes = new Node[size << 1];\r
@@ -46,16 +46,16 @@ public class BinaryHeap<T> {
                return node;\r
        }\r
 \r
-       public Node pop () {\r
+       public T pop () {\r
                Node[] nodes = this.nodes;\r
                Node popped = nodes[0];\r
                nodes[0] = nodes[--size];\r
                nodes[size] = null;\r
                if (size > 0) down(0);\r
-               return popped;\r
+               return (T)popped;\r
        }\r
 \r
-       public void setValue (Node node, float value) {\r
+       public void setValue (T node, float value) {\r
                float oldValue = node.value;\r
                node.value = value;\r
                if (value < oldValue ^ isMaxHeap)\r
@@ -142,12 +142,16 @@ public class BinaryHeap<T> {
        }\r
 \r
        /** @author Nathan Sweet */\r
-       static public class Node<T> {\r
+       static public class Node {\r
                float value;\r
                int index;\r
 \r
                public Node (float value) {\r
                        this.value = value;\r
                }\r
+\r
+               public float getValue () {\r
+                       return value;\r
+               }\r
        }\r
 }\r