예제 #1
0
  private void onJoyAxisEventQueued(JoyAxisEvent evt) {
    //        for (int i = 0; i < rawListeners.size(); i++){
    //            rawListeners.get(i).onJoyAxisEvent(evt);
    //        }

    int joyId = evt.getJoyIndex();
    int axis = evt.getAxisIndex();
    float value = evt.getValue();
    if (value < axisDeadZone && value > -axisDeadZone) {
      int hash1 = JoyAxisTrigger.joyAxisHash(joyId, axis, true);
      int hash2 = JoyAxisTrigger.joyAxisHash(joyId, axis, false);

      Float val1 = axisValues.get(hash1);
      Float val2 = axisValues.get(hash2);

      if (val1 != null && val1.floatValue() > axisDeadZone) {
        invokeActions(hash1, false);
      }
      if (val2 != null && val2.floatValue() > axisDeadZone) {
        invokeActions(hash2, false);
      }

      axisValues.remove(hash1);
      axisValues.remove(hash2);

    } else if (value < 0) {
      int hash = JoyAxisTrigger.joyAxisHash(joyId, axis, true);
      int otherHash = JoyAxisTrigger.joyAxisHash(joyId, axis, false);

      // Clear the reverse direction's actions in case we
      // crossed center too quickly
      Float otherVal = axisValues.get(otherHash);
      if (otherVal != null && otherVal.floatValue() > axisDeadZone) {
        invokeActions(otherHash, false);
      }

      invokeAnalogsAndActions(hash, -value, true);
      axisValues.put(hash, -value);
      axisValues.remove(otherHash);
    } else {
      int hash = JoyAxisTrigger.joyAxisHash(joyId, axis, false);
      int otherHash = JoyAxisTrigger.joyAxisHash(joyId, axis, true);

      // Clear the reverse direction's actions in case we
      // crossed center too quickly
      Float otherVal = axisValues.get(otherHash);
      if (otherVal != null && otherVal.floatValue() > axisDeadZone) {
        invokeActions(otherHash, false);
      }

      invokeAnalogsAndActions(hash, value, true);
      axisValues.put(hash, value);
      axisValues.remove(otherHash);
    }
  }
예제 #2
0
  Object invokeRemoteMethod(RemoteObject remoteObj, Method method, Object[] args) {
    Integer methodIdInt = remoteObj.methodMap.get(method);
    if (methodIdInt == null)
      throw new RuntimeException("Method not implemented by remote object owner: " + method);

    boolean needReturn = method.getReturnType() != void.class;
    short objectId = remoteObj.objectId;
    short methodId = methodIdInt.shortValue();
    RemoteMethodCallMessage call = new RemoteMethodCallMessage();
    call.methodId = methodId;
    call.objectId = objectId;
    call.args = args;

    Invocation invoke = null;
    if (needReturn) {
      call.invocationId = invocationIdCounter++;
      invoke = new Invocation();
      // Note: could cause threading issues if used from multiple threads
      pendingInvocations.put(call.invocationId, invoke);
    }

    if (server != null) {
      remoteObj.client.send(call);
      logger.log(Level.FINE, "Server: Sending {0}", call);
    } else {
      client.send(call);
      logger.log(Level.FINE, "Client: Sending {0}", call);
    }

    if (invoke != null) {
      synchronized (invoke) {
        while (!invoke.available) {
          try {
            invoke.wait();
          } catch (InterruptedException ex) {
            ex.printStackTrace();
          }
        }
      }
      // Note: could cause threading issues if used from multiple threads
      pendingInvocations.remove(call.invocationId);
      return invoke.retVal;
    } else {
      return null;
    }
  }
예제 #3
0
  private void invokeTimedActions(int hash, long time, boolean pressed) {
    if (!bindings.containsKey(hash)) {
      return;
    }

    if (pressed) {
      pressedButtons.put(hash, time);
    } else {
      Long pressTimeObj = pressedButtons.remove(hash);
      if (pressTimeObj == null) {
        return; // under certain circumstances it can be null, ignore
      } // the event then.

      long pressTime = pressTimeObj;
      long lastUpdate = lastLastUpdateTime;
      long releaseTime = time;
      long timeDelta = releaseTime - Math.max(pressTime, lastUpdate);

      if (timeDelta > 0) {
        invokeAnalogs(hash, computeAnalogValue(timeDelta), false);
      }
    }
  }