Beispiel #1
0
 public float getState() {
   if (button > 0) return instance.isPressed(button) ? 1 : 0;
   if ("x".equals(axis)) return instance.currentDeltaX;
   if ("y".equals(axis)) return instance.currentDeltaY;
   if (mouseWheel) {
     if (mouseWheelTime > 0) {
       if (System.currentTimeMillis() < mouseWheelTime) return lastMoustWheel;
       mouseWheelTime = 0;
     }
     lastMoustWheel = instance.currentMouseWheel;
     if (lastMoustWheel != 0)
       mouseWheelTime = System.currentTimeMillis() + MOUSEWHEEL_CHANGE_TIME;
     return lastMoustWheel;
   }
   return 0;
 }
Beispiel #2
0
 /** If the listener already exists, it is not added again. */
 public void addListener(Listener listener) {
   if (listener == null) throw new IllegalArgumentException("listener cannot be null.");
   synchronized (listenerLock) {
     Listener[] listeners = this.listeners;
     int n = listeners.length;
     for (int i = 0; i < n; i++) if (listener == listeners[i]) return;
     Listener[] newListeners = new Listener[n + 1];
     newListeners[0] = listener;
     System.arraycopy(listeners, 0, newListeners, 1, n);
     this.listeners = newListeners;
   }
   if (TRACE) trace("kryonet", "Connection listener added: " + listener.getClass().getName());
 }
Beispiel #3
0
 void notifyReceived(Object object) {
   if (object instanceof Ping) {
     Ping ping = (Ping) object;
     if (ping.isReply) {
       if (ping.id == lastPingID - 1) {
         returnTripTime = (int) (System.currentTimeMillis() - lastPingSendTime);
         if (TRACE) trace("kryonet", this + " return trip time: " + returnTripTime);
       }
     } else {
       ping.isReply = true;
       sendTCP(ping);
     }
   }
   Listener[] listeners = this.listeners;
   for (int i = 0, n = listeners.length; i < n; i++) listeners[i].received(this, object);
 }
Beispiel #4
0
 /**
  * Requests the connection to communicate with the remote computer to determine a new value for
  * the {@link #getReturnTripTime() return trip time}. When the connection receives a {@link
  * FrameworkMessage.Ping} object with {@link Ping#isReply isReply} set to true, the new return
  * trip time is available.
  */
 public void updateReturnTripTime() {
   Ping ping = new Ping();
   ping.id = lastPingID++;
   lastPingSendTime = System.currentTimeMillis();
   sendTCP(ping);
 }