make dancer code more resilient to storyboard changes
This commit is contained in:
parent
cdd88d9a8d
commit
e18eba17de
|
@ -328,6 +328,7 @@ public class Game extends BasicGameState {
|
||||||
objectIndex++;
|
objectIndex++;
|
||||||
}
|
}
|
||||||
objectIndex--;
|
objectIndex--;
|
||||||
|
Dancer.instance.setObjectIndex(objectIndex);
|
||||||
sbOverlay.updateIndex(objectIndex);
|
sbOverlay.updateIndex(objectIndex);
|
||||||
lastReplayTime = beatmap.objects[objectIndex].getTime();
|
lastReplayTime = beatmap.objects[objectIndex].getTime();
|
||||||
} catch (SlickException e) {
|
} catch (SlickException e) {
|
||||||
|
@ -1450,13 +1451,13 @@ public class Game extends BasicGameState {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Dancer.instance.setGameObjects(gameObjects);
|
||||||
sbOverlay.setGameObjects(gameObjects);
|
sbOverlay.setGameObjects(gameObjects);
|
||||||
if (!checkpointLoaded) {
|
if (!checkpointLoaded) {
|
||||||
sbOverlay.enter();
|
sbOverlay.enter();
|
||||||
sbOverlay.updateIndex(0);
|
sbOverlay.updateIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dancer.instance.setGameObjects(gameObjects);
|
|
||||||
Pippi.reset();
|
Pippi.reset();
|
||||||
mirrorFrom = 0;
|
mirrorFrom = 0;
|
||||||
mirrorTo = gameObjects.length;
|
mirrorTo = gameObjects.length;
|
||||||
|
@ -1473,6 +1474,7 @@ public class Game extends BasicGameState {
|
||||||
// container.setMouseGrabbed(false);
|
// container.setMouseGrabbed(false);
|
||||||
|
|
||||||
sbOverlay.leave();
|
sbOverlay.leave();
|
||||||
|
Dancer.instance.setGameObjects(null);
|
||||||
|
|
||||||
Cursor.lastObjColor = Color.white;
|
Cursor.lastObjColor = Color.white;
|
||||||
Cursor.lastMirroredObjColor = Color.white;
|
Cursor.lastMirroredObjColor = Color.white;
|
||||||
|
|
|
@ -97,9 +97,9 @@ public class Dancer {
|
||||||
|
|
||||||
private int dir;
|
private int dir;
|
||||||
public static final GameObject d = new DummyObject();
|
public static final GameObject d = new DummyObject();
|
||||||
private GameObject p;
|
|
||||||
|
|
||||||
private GameObject[] gameObjects;
|
private GameObject[] gameObjects;
|
||||||
|
private int objectIndex;
|
||||||
|
|
||||||
private MoverFactory moverFactory;
|
private MoverFactory moverFactory;
|
||||||
private Mover mover;
|
private Mover mover;
|
||||||
|
@ -124,7 +124,7 @@ public class Dancer {
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
isCurrentLazySlider = false;
|
isCurrentLazySlider = false;
|
||||||
p = null;
|
objectIndex = -1;
|
||||||
dir = 1;
|
dir = 1;
|
||||||
for (Spinner s : spinners) {
|
for (Spinner s : spinners) {
|
||||||
s.init();
|
s.init();
|
||||||
|
@ -154,6 +154,8 @@ public class Dancer {
|
||||||
this.moverFactoryIndex = moverFactoryIndex;
|
this.moverFactoryIndex = moverFactoryIndex;
|
||||||
moverFactory = moverFactories[moverFactoryIndex];
|
moverFactory = moverFactories[moverFactoryIndex];
|
||||||
multipoint = moverFactory.isMultiPoint();
|
multipoint = moverFactory.isMultiPoint();
|
||||||
|
// to prevent crashes when changing mover in storyboard, create mover now
|
||||||
|
createNewMover();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPolyMoverFactoryMinBufferSize() {
|
public int getPolyMoverFactoryMinBufferSize() {
|
||||||
|
@ -167,6 +169,12 @@ public class Dancer {
|
||||||
this.gameObjects = objs;
|
this.gameObjects = objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setObjectIndex(int objectIndex) {
|
||||||
|
this.objectIndex = objectIndex;
|
||||||
|
// storyboard
|
||||||
|
createNewMover();
|
||||||
|
}
|
||||||
|
|
||||||
public void update(int time, int objectIndex) {
|
public void update(int time, int objectIndex) {
|
||||||
GameObject p;
|
GameObject p;
|
||||||
if (objectIndex == 0) {
|
if (objectIndex == 0) {
|
||||||
|
@ -180,9 +188,9 @@ public class Dancer {
|
||||||
p = e[0];
|
p = e[0];
|
||||||
c = e[1];
|
c = e[1];
|
||||||
}
|
}
|
||||||
if (this.p != p) {
|
if (this.objectIndex != objectIndex) {
|
||||||
this.p = p;
|
this.objectIndex = objectIndex;
|
||||||
if (this.p == d) {
|
if (objectIndex == 0) {
|
||||||
if (c.isSpinner()) {
|
if (c.isSpinner()) {
|
||||||
double[] spinnerStartPoint = spinner.getPoint();
|
double[] spinnerStartPoint = spinner.getPoint();
|
||||||
c.start.set((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
|
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]);
|
c.start = new Vec2f((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (multipoint) {
|
createNewMover();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time < c.getTime()) {
|
if (time < c.getTime()) {
|
||||||
|
@ -254,4 +249,30 @@ public class Dancer {
|
||||||
y = Utils.clamp(y, 10, Options.height - 10);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user