Class InputLog

java.lang.Object
com.codename1.gaming.platformer.InputLog

public final class InputLog extends Object

A recorded run: one Input value per tick, run-length encoded.

A player rarely changes buttons, so a minute of play (3600 ticks) is typically a few hundred bytes of text. The text form, bits*count pairs in hexadecimal separated by commas ("2*3c,12*8,2*40"), is what the app uploads and the server replays with Replay.

  • Constructor Details

    • InputLog

      public InputLog()
  • Method Details

    • add

      public void add(int bits)

      Appends one tick.

      Parameters
      • bits: the tick's Input bits
    • length

      public int length()

      The number of ticks recorded.

      Returns

      the tick count

    • get

      public int get(int tick)

      The input at a tick.

      Parameters
      • tick: a tick in [0, length())
      Returns

      the Input bits

    • toArray

      public int[] toArray()

      Expands the log into one value per tick.

      Returns

      a new array of length() values

    • encode

      public String encode()

      The compact text form.

      Returns

      the encoded log

    • decode

      public static InputLog decode(String text, int maxTicks)

      Reads the text form.

      Parameters
      • text: an encoded log
      • maxTicks: the longest log accepted, so a hostile upload cannot claim billions of ticks
      Returns

      the log

      Throws
      • IllegalArgumentException: on malformed text or a log over maxTicks