コード例 #1
0
 public KeyboardInstant() {
   kbdInstant = new EnumMap<KeysConfiguration, Boolean>(KeysConfiguration.class);
   // Default : all keys are unpressed
   for (KeysConfiguration key : KeysConfiguration.values()) {
     kbdInstant.put(key, false);
   }
 }
コード例 #2
0
 /**
  * Serialize this object into a ByteBuffer
  *
  * @return EasyBuffering
  */
 @Override
 public void serialize(EasyBuffering p_buffer) {
   p_buffer.clear();
   int index = 0;
   for (KeysConfiguration key : KeysConfiguration.values()) {
     bools[index++] = kbdInstant.get(key);
   }
   p_buffer.putBooleans(bools);
 }
コード例 #3
0
 /** Update keyboard state */
 public void update() {
   if (kbHandler == null) {
     kbHandler = Zildo.pdPlugin.kbHandler;
   }
   for (KeysConfiguration key : KeysConfiguration.values()) {
     kbdInstant.put(key, kbHandler.isKeyDown(key.code));
   }
   currentDirection = kbHandler.getDirection();
 }
コード例 #4
0
 /**
  * Deserialize a ByteBuffer into a KeyboardInstant object.
  *
  * @param p_buffer
  * @return
  */
 public static KeyboardInstant deserialize(EasyBuffering p_buffer) {
   EnumMap<KeysConfiguration, Boolean> instant =
       new EnumMap<KeysConfiguration, Boolean>(KeysConfiguration.class);
   boolean[] bools = p_buffer.readBooleans(KEYS_LENGTH);
   int index = 0;
   for (KeysConfiguration key : KeysConfiguration.values()) {
     instant.put(key, bools[index++]);
   }
   return new KeyboardInstant(instant);
 }
コード例 #5
0
public class KeyboardInstant implements EasySerializable {

  KeyboardHandler kbHandler = Zildo.pdPlugin.kbHandler;

  EnumMap<KeysConfiguration, Boolean> kbdInstant;
  Vector2f currentDirection;
  boolean[] bools = new boolean[KEYS_LENGTH];

  static int KEYS_LENGTH = KeysConfiguration.values().length;

  static EasyBuffering buf = new EasyBuffering(KEYS_LENGTH * 4);

  public KeyboardInstant() {
    kbdInstant = new EnumMap<KeysConfiguration, Boolean>(KeysConfiguration.class);
    // Default : all keys are unpressed
    for (KeysConfiguration key : KeysConfiguration.values()) {
      kbdInstant.put(key, false);
    }
  }

  public KeyboardInstant(EnumMap<KeysConfiguration, Boolean> p_keys) {
    kbdInstant = p_keys;
  }

  public boolean isKeyDown(KeysConfiguration key) {
    return kbdInstant.get(key);
  }

  public void setKey(KeysConfiguration key, boolean value) {
    kbdInstant.put(key, value);
  }

  public Vector2f getDirection() {
    return currentDirection;
  }

  /** Update keyboard state */
  public void update() {
    if (kbHandler == null) {
      kbHandler = Zildo.pdPlugin.kbHandler;
    }
    for (KeysConfiguration key : KeysConfiguration.values()) {
      kbdInstant.put(key, kbHandler.isKeyDown(key.code));
    }
    currentDirection = kbHandler.getDirection();
  }

  public EasyBuffering serialize() {
    serialize(buf);
    return buf;
  }

  /**
   * Serialize this object into a ByteBuffer
   *
   * @return EasyBuffering
   */
  @Override
  public void serialize(EasyBuffering p_buffer) {
    p_buffer.clear();
    int index = 0;
    for (KeysConfiguration key : KeysConfiguration.values()) {
      bools[index++] = kbdInstant.get(key);
    }
    p_buffer.putBooleans(bools);
  }

  /**
   * Deserialize a ByteBuffer into a KeyboardInstant object.
   *
   * @param p_buffer
   * @return
   */
  public static KeyboardInstant deserialize(EasyBuffering p_buffer) {
    EnumMap<KeysConfiguration, Boolean> instant =
        new EnumMap<KeysConfiguration, Boolean>(KeysConfiguration.class);
    boolean[] bools = p_buffer.readBooleans(KEYS_LENGTH);
    int index = 0;
    for (KeysConfiguration key : KeysConfiguration.values()) {
      instant.put(key, bools[index++]);
    }
    return new KeyboardInstant(instant);
  }
}