Class AnimationBinary

java.lang.Object
dev.kosmx.playerAnim.core.data.AnimationBinary

public final class AnimationBinary extends Object
Utility class to convert animation data to a binary format. Includes a size predictor, using ByteBuffer Does not pack extraData, that must be done manually
  • Constructor Details

    • AnimationBinary

      public AnimationBinary()
  • Method Details

    • write

      public static <T extends ByteBuffer> T write(KeyframeAnimation animation, T buf, int version) throws BufferOverflowException
      Write the animation into the ByteBuffer. Versioning: 1. Emotecraft 2.1 features 2. New animation format for Animation library - including enable states, dynamic parts format type 1 takes fewer data, but only works for standard models and unable to send data for disabled states
      Type Parameters:
      T - ByteBuffer
      Parameters:
      animation - animation
      buf - target byteBuf
      version - Binary version
      Returns:
      target byteBuf for chaining
      Throws:
      BufferOverflowException - if can't write into ByteBuf
    • write

      public static <T extends ByteBuffer> T write(KeyframeAnimation animation, T buf) throws BufferOverflowException
      Write the animation into the ByteBuffer using the latest format version
      Type Parameters:
      T - ByteBuffer
      Parameters:
      animation - animation
      buf - target byteBuf
      Returns:
      target byteBuf for chaining
      Throws:
      BufferOverflowException - if can't write into byteBuf
    • read

      public static KeyframeAnimation read(ByteBuffer buf, int version) throws IOException
      Read keyframe animation from binary data. creates a Bool extra property with validation data with name valid
      Parameters:
      buf - byteBuf
      version - format version (not stored in binary)
      Returns:
      KeyframeAnimation
      Throws:
      BufferUnderflowException - if there is not enough data in ByteBuffer
      IOException - if encounters invalid data
    • getCurrentVersion

      public static int getCurrentVersion()
      Current animation binary version
      Returns:
      version
    • calculateSize

      public static int calculateSize(KeyframeAnimation animation, int version)
    • putBoolean

      public static void putBoolean(ByteBuffer byteBuffer, boolean bl)
      Writes a bool value into byteBuffer, using 1 byte per bool
      Parameters:
      byteBuffer - buf
      bl - bool
    • getBoolean

      public static boolean getBoolean(ByteBuffer buf)
      Reads a bool value from byteBuffer
      Parameters:
      buf - buf
      Returns:
      bool
    • putString

      public static void putString(ByteBuffer buf, String str)
      Writes a binary string into byteBuf first 4 bytes for size, then string data
      Parameters:
      buf - buf
      str - str
    • getString

      public static String getString(ByteBuffer buf)
      Reads string from buf, see putString(ByteBuffer, String)
      Parameters:
      buf - buf
      Returns:
      str