Ejemplo n.º 1
0
  public PolledDeviceDIData read() {
    delay();
    // long t1 = HiresClock.getTimeNanos();
    long time = HiresClock.getTimeNanos();
    diDevice.update();
    // System.out.println("DIDevice.read() takes time: " + (time-t1));

    if (useAxisDeltas) {
      for (int i = 0; i < diAxis.length; i++) {
        if (diAxis[i] != null) {
          axisValue[i] = axisTransform.valueOf(diAxis[i].getValue());
          axisDelta[i] = (axisValue[i] - lastAxisValue[i]) / axisLimit;
          lastAxisValue[i] = axisValue[i];
        }
      }
    } else {
      for (int i = 0; i < diAxis.length; i++) {
        axisValue[i] = axisTransform.valueOf(diAxis[i].getValue()) / axisLimit;
      }
    }

    changedButtonIndex = -1;
    for (int i = diButton.length - 1; i >= 0; i--) {
      boolean s = diButton[i].getState();
      if (s != buttonState[i]) {
        changedButtonIndex = i;
      }
      buttonState[i] = s;
    }

    changedDirectionalIndex = -1;
    for (int i = diDirectional.length - 1; i >= 0; i--) {
      boolean s = diDirectional[i].isCentered();
      if (s != directionalState[i]) {
        changedDirectionalIndex = i;
      }
      directionalState[i] = s;
      directionalValue[i] = diDirectional[i].getDirection() / 100;
    }

    return new PolledDeviceDIData(
        this,
        changedButtonIndex,
        buttonState,
        changedDirectionalIndex,
        directionalState,
        directionalValue,
        useAxisDeltas ? axisDelta : axisValue,
        time);
  }
Ejemplo n.º 2
0
 /** Reset the DirectInput connection. */
 public void reset() {
   diDevice.reset();
   diDevice.update();
   for (int i = 0; i < diAxis.length; i++) {
     if (diAxis[i] != null) {
       lastAxisValue[i] = axisTransform.valueOf(diAxis[i].getValue());
     }
   }
   for (int i = 0; i < diButton.length; i++) {
     buttonState[i] = diButton[i].getState();
   }
   for (int i = 0; i < diDirectional.length; i++) {
     directionalState[i] = diDirectional[i].isCentered();
   }
 }