make dancer code more resilient to storyboard changes

This commit is contained in:
yugecin 2016-11-20 18:35:20 +01:00
parent cdd88d9a8d
commit e18eba17de
2 changed files with 43 additions and 20 deletions

View File

@ -328,6 +328,7 @@ public class Game extends BasicGameState {
objectIndex++;
}
objectIndex--;
Dancer.instance.setObjectIndex(objectIndex);
sbOverlay.updateIndex(objectIndex);
lastReplayTime = beatmap.objects[objectIndex].getTime();
} catch (SlickException e) {
@ -1450,13 +1451,13 @@ public class Game extends BasicGameState {
}
Dancer.instance.setGameObjects(gameObjects);
sbOverlay.setGameObjects(gameObjects);
if (!checkpointLoaded) {
sbOverlay.enter();
sbOverlay.updateIndex(0);
}
Dancer.instance.setGameObjects(gameObjects);
Pippi.reset();
mirrorFrom = 0;
mirrorTo = gameObjects.length;
@ -1473,6 +1474,7 @@ public class Game extends BasicGameState {
// container.setMouseGrabbed(false);
sbOverlay.leave();
Dancer.instance.setGameObjects(null);
Cursor.lastObjColor = Color.white;
Cursor.lastMirroredObjColor = Color.white;

View File

@ -97,9 +97,9 @@ public class Dancer {
private int dir;
public static final GameObject d = new DummyObject();
private GameObject p;
private GameObject[] gameObjects;
private int objectIndex;
private MoverFactory moverFactory;
private Mover mover;
@ -124,7 +124,7 @@ public class Dancer {
public void reset() {
isCurrentLazySlider = false;
p = null;
objectIndex = -1;
dir = 1;
for (Spinner s : spinners) {
s.init();
@ -154,6 +154,8 @@ public class Dancer {
this.moverFactoryIndex = moverFactoryIndex;
moverFactory = moverFactories[moverFactoryIndex];
multipoint = moverFactory.isMultiPoint();
// to prevent crashes when changing mover in storyboard, create mover now
createNewMover();
}
public int getPolyMoverFactoryMinBufferSize() {
@ -167,6 +169,12 @@ public class Dancer {
this.gameObjects = objs;
}
public void setObjectIndex(int objectIndex) {
this.objectIndex = objectIndex;
// storyboard
createNewMover();
}
public void update(int time, int objectIndex) {
GameObject p;
if (objectIndex == 0) {
@ -180,9 +188,9 @@ public class Dancer {
p = e[0];
c = e[1];
}
if (this.p != p) {
this.p = p;
if (this.p == d) {
if (this.objectIndex != objectIndex) {
this.objectIndex = objectIndex;
if (objectIndex == 0) {
if (c.isSpinner()) {
double[] spinnerStartPoint = spinner.getPoint();
c.start.set((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
@ -206,20 +214,7 @@ public class Dancer {
c.start = new Vec2f((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
}
if (multipoint) {
PolyMoverFactory pmf = (PolyMoverFactory) moverFactory;
if (pmf.isInitialized() && pmf.getLatestIndex() < objectIndex + pmf.getLatestIndex() - 1) {
pmf.update(gameObjects[objectIndex + pmf.getMaxBufferSize() - 1]);
} else {
pmf.create(gameObjects, objectIndex - 1);
}
} else if (mover == null || mover.getEnd() != c) {
if (p == d) {
mover = new LinearMover(p, c, dir);
} else {
mover = moverFactory.create(p, c, dir);
}
}
createNewMover();
}
if (time < c.getTime()) {
@ -254,4 +249,30 @@ public class Dancer {
y = Utils.clamp(y, 10, Options.height - 10);
}
private void createNewMover() {
if (gameObjects == null) {
return;
}
if (objectIndex < 0) {
objectIndex = 0;
}
GameObject c = gameObjects[objectIndex];
if (multipoint) {
PolyMoverFactory pmf = (PolyMoverFactory) moverFactory;
if (pmf.isInitialized() && pmf.getLatestIndex() < objectIndex + pmf.getLatestIndex() - 1) {
pmf.update(gameObjects[objectIndex + pmf.getMaxBufferSize() - 1]);
} else {
pmf.create(gameObjects, objectIndex - 1);
}
return;
}
if (mover == null || mover.getEnd() != c) {
if (objectIndex == 0) {
mover = new LinearMover(d, c, dir);
} else {
mover = moverFactory.create(gameObjects[objectIndex - 1], c, dir);
}
}
}
}