Initial replay recording support.

- Added listener and events in Game state to record replay frames.
- Send more accurate keys.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-03-10 22:37:23 -04:00
parent 7536056a59
commit 790a66ec1e
6 changed files with 123 additions and 30 deletions

View File

@@ -237,9 +237,9 @@ public class Replay {
// life data
StringBuilder sb = new StringBuilder();
if (lifeFrames != null) {
NumberFormat nf = new DecimalFormat("##.##");
NumberFormat nf = new DecimalFormat("##.##");
for (int i = 0; i < lifeFrames.length; i++) {
LifeFrame frame = lifeFrames[i];
LifeFrame frame = lifeFrames[i];
sb.append(String.format("%d|%s,",
frame.getTime(), nf.format(frame.getPercentage())));
}

View File

@@ -44,8 +44,16 @@ public class ReplayFrame {
private float x, y;
/** Keys pressed (bitmask). */
private int keys;
private int keys;
/**
* Returns the start frame.
* @param t the value for the {@code time} and {@code timeDiff} fields
*/
public static ReplayFrame getStartFrame(int t) {
return new ReplayFrame(t, t, 256, -500, 0);
}
/**
* Constructor.
* @param timeDiff time since the previous action (in ms)
@@ -72,6 +80,11 @@ public class ReplayFrame {
*/
public int getTimeDiff() { return timeDiff; }
/**
* Sets the time since the previous action, in milliseconds.
*/
public void setTimeDiff(int diff) { this.timeDiff = diff; }
/**
* Returns the scaled cursor x coordinate.
*/