From 408c1627419c158d11228c909eb9a36e1bb2111c Mon Sep 17 00:00:00 2001 From: yugecin Date: Thu, 21 Dec 2017 23:55:16 +0100 Subject: [PATCH] fix replay hit results --- src/itdelatrisu/opsu/objects/Circle.java | 7 +++- src/itdelatrisu/opsu/objects/Slider.java | 7 +++- src/itdelatrisu/opsu/states/Game.java | 14 +++---- src/yugecin/opsudance/ReplayPlayback.java | 46 +++++++++-------------- 4 files changed, 33 insertions(+), 41 deletions(-) diff --git a/src/itdelatrisu/opsu/objects/Circle.java b/src/itdelatrisu/opsu/objects/Circle.java index 57333094..e8718f5e 100644 --- a/src/itdelatrisu/opsu/objects/Circle.java +++ b/src/itdelatrisu/opsu/objects/Circle.java @@ -85,7 +85,9 @@ public class Circle extends GameObject { @Override public GameObject clone(GameData data) { - return new Circle(hitObject, game, data, comboColorIndex, comboEnd); + Circle c = new Circle(hitObject, game, data, comboColorIndex, comboEnd); + c.isreplay = true; + return c; } @Override @@ -170,12 +172,13 @@ public class Circle extends GameObject { return false; } + private boolean isreplay; @Override public boolean update(boolean overlap, int delta, int mouseX, int mouseY, boolean keyPressed, int trackPosition) { int time = hitObject.getTime(); int[] hitResultOffset = game.getHitResultOffsets(); - boolean isAutoMod = GameMod.AUTO.isActive(); + boolean isAutoMod = !isreplay && GameMod.AUTO.isActive(); if (trackPosition > time + hitResultOffset[GameData.HIT_50]) { if (isAutoMod) {// "auto" mod: catch any missed notes due to lag diff --git a/src/itdelatrisu/opsu/objects/Slider.java b/src/itdelatrisu/opsu/objects/Slider.java index 3b08298f..c2c5f6d3 100644 --- a/src/itdelatrisu/opsu/objects/Slider.java +++ b/src/itdelatrisu/opsu/objects/Slider.java @@ -191,7 +191,9 @@ public class Slider extends GameObject { @Override public GameObject clone(GameData data) { - return new Slider(hitObject, game, data, comboColorIndex, comboEnd); + Slider s = new Slider(hitObject, game, data, comboColorIndex, comboEnd); + s.isreplay = true; + return s; } @Override @@ -627,11 +629,12 @@ public class Slider extends GameObject { return false; } + boolean isreplay; @Override public boolean update(boolean overlap, int delta, int mouseX, int mouseY, boolean keyPressed, int trackPosition) { int repeatCount = hitObject.getRepeatCount(); int[] hitResultOffset = game.getHitResultOffsets(); - boolean isAutoMod = GameMod.AUTO.isActive(); + boolean isAutoMod = !isreplay && GameMod.AUTO.isActive(); if (!sliderClickedInitial) { int time = hitObject.getTime(); diff --git a/src/itdelatrisu/opsu/states/Game.java b/src/itdelatrisu/opsu/states/Game.java index 64ad2a2a..b37d535e 100644 --- a/src/itdelatrisu/opsu/states/Game.java +++ b/src/itdelatrisu/opsu/states/Game.java @@ -1558,6 +1558,9 @@ public class Game extends ComplexOpsuState { } gameObjects = new GameObject[beatmap.objects.length]; + for (ReplayPlayback replayPlayback : replays) { + replayPlayback.gameObjects = new GameObject[gameObjects.length]; + } playbackSpeed = PlaybackSpeed.NORMAL; // reset game data @@ -1604,6 +1607,9 @@ public class Game extends ComplexOpsuState { } else if (hitObject.isSpinner()) { gameObjects[i] = new Spinner(hitObject, this, data); } + for (ReplayPlayback replayPlayback : replays) { + replayPlayback.gameObjects[i] = gameObjects[i].clone(replayPlayback.gdata); + } } catch (Exception e) { String message = String.format("Failed to create %s at index %d:\n%s", hitObject.getTypeName(), i, hitObject.toString()); Log.error(message, e); @@ -1718,14 +1724,6 @@ public class Game extends ComplexOpsuState { } } - for (ReplayPlayback replayPlayback : replays) { - GameObject[] objs = new GameObject[gameObjects.length]; - for (int i = 0; i < objs.length; i++) { - objs[i] = gameObjects[i].clone(replayPlayback.new GData()); - } - replayPlayback.setGameObjects(objs); - } - Dancer.instance.setGameObjects(gameObjects); storyboardOverlay.setGameObjects(gameObjects); if (!skippedToCheckpoint) { diff --git a/src/yugecin/opsudance/ReplayPlayback.java b/src/yugecin/opsudance/ReplayPlayback.java index 86ac9d7f..d1c7cc12 100644 --- a/src/yugecin/opsudance/ReplayPlayback.java +++ b/src/yugecin/opsudance/ReplayPlayback.java @@ -45,11 +45,12 @@ public class ReplayPlayback { private boolean hr; private String player; - private GameObject[] gameObjects; + public GameObject[] gameObjects; private int objectIndex = 0; private int lastkeys = 0; private Image hitImage; private int hitImageTimer = 0; + public GData gdata = new GData(); public ReplayPlayback(DisplayContainer container, Replay replay, Color color) { this.container = container; @@ -101,10 +102,6 @@ public class ReplayPlayback { this.player = replay.playerName + this.player; } - public void setGameObjects(GameObject[] gameObjects) { - this.gameObjects = gameObjects; - } - public void resetFrameIndex() { frameIndex = 0; currentFrame = replay.frames[frameIndex++]; @@ -115,12 +112,6 @@ public class ReplayPlayback { if (objectIndex >= gameObjects.length) // nothing to do here return; - int deltakeys = (currentFrame.getKeys() & ~this.lastkeys); - if (deltakeys == ReplayFrame.KEY_NONE) { - return; - } - this.lastkeys = currentFrame.getKeys(); - HitObject hitObject = beatmap.objects[objectIndex]; // circles @@ -154,8 +145,17 @@ public class ReplayPlayback { while (nextFrame != null && nextFrame.getTime() < time) { currentFrame = nextFrame; + + int keys = currentFrame.getKeys(); + int deltaKeys = (keys & ~lastkeys); // keys that turned on + if (deltaKeys != ReplayFrame.KEY_NONE) { // send a key press + sendKeys(beatmap, currentFrame.getTime()); + } else if (keys == lastkeys) { + update(time, beatmap, hitResultOffset, currentFrame.getTimeDiff()); + } + lastkeys = keys; + processKeys(); - sendKeys(beatmap, time); frameIndex++; if (frameIndex >= replay.frames.length) { nextFrame = null; @@ -163,9 +163,6 @@ public class ReplayPlayback { } nextFrame = replay.frames[frameIndex]; } - processKeys(); - sendKeys(beatmap, time); - update(time, beatmap, hitResultOffset, renderdelta); g.setColor(color); ypos *= (SQSIZE + 5); for (int i = 0; i < 4; i++) { @@ -177,7 +174,7 @@ public class ReplayPlayback { Fonts.SMALLBOLD.drawString(SQSIZE * 5, ypos, this.player + " " + this.objectIndex, color); int namewidth = Fonts.SMALLBOLD.getWidth(this.player); if (hitImage != null) { - hitImage.draw(SQSIZE * 5 + namewidth + SQSIZE * 2, ypos + SQSIZE / 2); + hitImage.draw(SQSIZE * 5 + namewidth + SQSIZE * 2, ypos); } int y = currentFrame.getScaledY(); if (hr) { @@ -204,13 +201,11 @@ public class ReplayPlayback { } } - private GData _data; public class GData extends GameData { public GData() { super(); this.loadImages(); - _data = this; } @Override @@ -237,20 +232,13 @@ public class ReplayPlayback { @Override public void sendHitResult(int time, int result, float x, float y, Color color, boolean end, HitObject hitObject, HitObjectType hitResultType, boolean expand, int repeat, Curve curve, boolean sliderHeldToEnd, boolean handleResult) { - int hitResult = HIT_300; - - if (handleResult) { - hitResult = handleHitResult(time, result, x, y, color, end, hitObject, - hitResultType, repeat, (curve != null && !sliderHeldToEnd)); + if ((result == HIT_300)) { + //return; } - if ((hitResult == HIT_300 || hitResult == HIT_300G || hitResult == HIT_300K)) { - return; - } - - if (hitResult < hitResults.length) { + if (result < hitResults.length) { hitImageTimer = 0; - hitImage = hitResults[hitResult].getScaledCopy(SQSIZE, SQSIZE); + hitImage = hitResults[result].getScaledCopy(SQSIZE, SQSIZE); } }