Added support for right/bottom edge fill lines in .9.png files.
}\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
* 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
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
\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
--- /dev/null
+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);
+ }
+ }
+ }
+}
--- /dev/null
+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);
+ }
+ }
+ }
+}
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
* 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
* 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
* \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
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
* 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
* 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
\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
* 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
\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
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
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
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
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
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
}\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