Merge branch 'pullreqs'
This commit is contained in:
commit
3cbc02c253
9
pom.xml
9
pom.xml
|
@ -36,8 +36,8 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.2</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -209,5 +209,10 @@
|
|||
<artifactId>lzma-java</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gov.nist.math</groupId>
|
||||
<artifactId>jama</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
38
src/awlex/ospu/movers/SinusMover.java
Normal file
38
src/awlex/ospu/movers/SinusMover.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package awlex.ospu.movers;
|
||||
|
||||
import itdelatrisu.opsu.Utils;
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
import yugecin.opsudance.movers.Mover;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 27.10.2016.
|
||||
*/
|
||||
public class SinusMover extends Mover {
|
||||
|
||||
private double angle;
|
||||
private double radius;
|
||||
private double amplitude;
|
||||
|
||||
public SinusMover(GameObject start, GameObject end, int dir) {
|
||||
super(start, end, dir);
|
||||
angle = Math.atan2(endY - startY, endX - startX);
|
||||
radius = Utils.distance(startX, startY, endX, endY);
|
||||
amplitude = radius / 4;
|
||||
this.dir = angle < 180 ? dir : -dir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getPointAt(int time) {
|
||||
double x = radius * getT(time);
|
||||
double y = amplitude * Math.sin(2d * Math.PI * getT(time)) * dir;
|
||||
return new double[]{
|
||||
startX + x * Math.cos(angle) - y * Math.sin(angle),
|
||||
startY + x * Math.sin(angle) + y * Math.cos(angle)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Sinustic";
|
||||
}
|
||||
}
|
106
src/awlex/ospu/polymover/ArcMover.java
Normal file
106
src/awlex/ospu/polymover/ArcMover.java
Normal file
|
@ -0,0 +1,106 @@
|
|||
package awlex.ospu.polymover;
|
||||
|
||||
import Jama.Matrix;
|
||||
import itdelatrisu.opsu.objects.Circle;
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
import itdelatrisu.opsu.objects.Slider;
|
||||
|
||||
import static java.lang.Math.*;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 13.11.2016.
|
||||
*/
|
||||
public class ArcMover implements PolyMover {
|
||||
|
||||
public static final int ITEMS_NEEDED = 3;
|
||||
private GameObject p1, middle, p2;
|
||||
private double xm, ym, r, alpha, beta, gamma;
|
||||
|
||||
public ArcMover(GameObject p1, GameObject middle, GameObject p2) {
|
||||
this.p1 = p1;
|
||||
this.middle = middle;
|
||||
this.p2 = p2;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
Matrix m = prepareMatrix(p1, middle, p2);
|
||||
xm = m.get(1, 0) * 0.5;
|
||||
ym = m.get(2, 0) * 0.5;
|
||||
r = sqrt(pow(xm, 2) + pow(ym, 2) - m.get(0, 0));
|
||||
alpha = atan2(p1.end.y - ym, p1.end.x - xm);
|
||||
beta = atan2(middle.start.y - ym, middle.start.x - xm);
|
||||
gamma = atan2(p2.start.y - ym, p2.start.x - xm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getPointAt(int time) {
|
||||
double angle;
|
||||
if (time < middle.getTime()) {
|
||||
double percent = ((double) time - p1.getEndTime()) / ((middle.getTime() - p1.getEndTime()));
|
||||
angle = alpha + (beta - alpha) * percent;
|
||||
}
|
||||
else {
|
||||
angle = beta + (gamma - beta) * ((double) time - middle.getTime()) / (p2.getTime() - middle.getTime());
|
||||
}
|
||||
return new double[]{
|
||||
xm + r * cos(angle),
|
||||
ym + r * sin(angle)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameObject[] getItems() {
|
||||
return new GameObject[]{
|
||||
p1,
|
||||
middle,
|
||||
p2
|
||||
};
|
||||
}
|
||||
|
||||
private static Matrix prepareMatrix(GameObject p1, GameObject middle, GameObject p2) {
|
||||
Matrix a, b;
|
||||
|
||||
//if (!p2.isSlider()) {
|
||||
a = new Matrix(new double[][]{
|
||||
{1, -p1.end.x, -p1.end.y},
|
||||
{1, -middle.start.x, -middle.start.y},
|
||||
{1, -p2.start.x, -p2.start.y}
|
||||
});
|
||||
b = new Matrix(new double[][]{
|
||||
{-(pow(p1.end.x, 2) + pow(p1.end.y, 2))},
|
||||
{-(pow(middle.start.x, 2) + pow(middle.start.y, 2))},
|
||||
{-(pow(p2.start.x, 2) + pow(p2.start.y, 2))},
|
||||
});
|
||||
/*
|
||||
} else {
|
||||
Circle c = ((Slider) p2).getTickPositionCircles()[0];
|
||||
a = new Matrix(new double[][]{
|
||||
{1, -p1.end.x, -p1.end.y},
|
||||
{1, -middle.start.x, -middle.start.y},
|
||||
{1, -c.start.x, -c.start.y}
|
||||
});
|
||||
b = new Matrix(new double[][]{
|
||||
{-(pow(p1.end.x, 2) + pow(p1.end.y, 2))},
|
||||
{-(pow(middle.start.x, 2) + pow(middle.start.y, 2))},
|
||||
{-(pow(c.start.x, 2) + pow(c.start.y, 2))},
|
||||
});
|
||||
}
|
||||
*/
|
||||
return a.solve(b);
|
||||
}
|
||||
|
||||
public static boolean canCricleExistBetweenItems(GameObject p1, GameObject p2, GameObject p3) {
|
||||
try {
|
||||
prepareMatrix(p1, p2, p3);
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameObject getLastItem() {
|
||||
return p2;
|
||||
}
|
||||
}
|
55
src/awlex/ospu/polymover/LineMover.java
Normal file
55
src/awlex/ospu/polymover/LineMover.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package awlex.ospu.polymover;
|
||||
|
||||
import itdelatrisu.opsu.objects.DummyObject;
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
import itdelatrisu.opsu.states.Game;
|
||||
import yugecin.opsudance.movers.LinearMover;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 19.11.2016.
|
||||
*/
|
||||
public class LineMover implements PolyMover {
|
||||
|
||||
public static final int ITEMS_NEEDED = 2;
|
||||
|
||||
private GameObject[] objects;
|
||||
private LinearMover m;
|
||||
private int currentIndex;
|
||||
|
||||
|
||||
public LineMover(GameObject[] objects, int startIndex, int count) {
|
||||
this.objects = objects;
|
||||
m = new LinearMover(objects[startIndex], objects[startIndex + 1], 1);
|
||||
currentIndex = startIndex + 1;
|
||||
}
|
||||
|
||||
public LineMover(GameObject[] objects, int count) {
|
||||
this(objects, 0, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getPointAt(int time) {
|
||||
if (objects[currentIndex].getEndTime() < time)
|
||||
m = new LinearMover(objects[currentIndex], objects[currentIndex + 1], 1);
|
||||
return m.getPointAt(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameObject[] getItems() {
|
||||
return objects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameObject getLastItem() {
|
||||
int i = objects.length - 1;
|
||||
while (i > 0) {
|
||||
if (objects[i] != null) {
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
return objects[i];
|
||||
}
|
||||
}
|
15
src/awlex/ospu/polymover/PolyMover.java
Normal file
15
src/awlex/ospu/polymover/PolyMover.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package awlex.ospu.polymover;
|
||||
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 18.11.2016.
|
||||
*/
|
||||
public interface PolyMover {
|
||||
|
||||
double[] getPointAt(int time);
|
||||
|
||||
GameObject[] getItems();
|
||||
|
||||
GameObject getLastItem();
|
||||
}
|
40
src/awlex/ospu/polymover/factory/ArcFactory.java
Normal file
40
src/awlex/ospu/polymover/factory/ArcFactory.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package awlex.ospu.polymover.factory;
|
||||
|
||||
import awlex.ospu.polymover.ArcMover;
|
||||
import awlex.ospu.polymover.LineMover;
|
||||
import awlex.ospu.polymover.PolyMover;
|
||||
import itdelatrisu.opsu.objects.DummyObject;
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 18.11.2016.
|
||||
*/
|
||||
public class ArcFactory extends PolyMoverFactory {
|
||||
|
||||
private static final int PREFFERED_BUFFER_SIZE = 3;
|
||||
|
||||
public void init(GameObject[] objects, int count) {
|
||||
if (count < 3 || (!ArcMover.canCricleExistBetweenItems(objects[0], objects[1], objects[2])))
|
||||
addMover(new LineMover(objects, 3));
|
||||
else
|
||||
addMover(new ArcMover(objects[0], objects[1], objects[2]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxBufferSize() {
|
||||
return ArcMover.ITEMS_NEEDED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinBufferSize() {
|
||||
return LineMover.ITEMS_NEEDED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Arcs";
|
||||
}
|
||||
|
||||
}
|
38
src/awlex/ospu/polymover/factory/LinearFactory.java
Normal file
38
src/awlex/ospu/polymover/factory/LinearFactory.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package awlex.ospu.polymover.factory;
|
||||
|
||||
import awlex.ospu.polymover.LineMover;
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 20.11.2016.
|
||||
*/
|
||||
public class LinearFactory extends PolyMoverFactory {
|
||||
|
||||
public final static int PREFFERED_BUFFER_SIZE = 2;
|
||||
|
||||
@Override
|
||||
public double[] getPointAt(int time) {
|
||||
return getCurrent().getPointAt(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(GameObject[] objects, int count) {
|
||||
addMover(new LineMover(objects, count));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxBufferSize() {
|
||||
return LineMover.ITEMS_NEEDED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinBufferSize() {
|
||||
return LineMover.ITEMS_NEEDED;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Linear";
|
||||
}
|
||||
}
|
132
src/awlex/ospu/polymover/factory/PolyMoverFactory.java
Normal file
132
src/awlex/ospu/polymover/factory/PolyMoverFactory.java
Normal file
|
@ -0,0 +1,132 @@
|
|||
package awlex.ospu.polymover.factory;
|
||||
|
||||
import awlex.ospu.polymover.LineMover;
|
||||
import awlex.ospu.polymover.PolyMover;
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
import yugecin.opsudance.Dancer;
|
||||
import yugecin.opsudance.movers.Mover;
|
||||
import yugecin.opsudance.movers.factories.MoverFactory;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 18.11.2016.
|
||||
*/
|
||||
public abstract class PolyMoverFactory implements MoverFactory {
|
||||
|
||||
private LinkedList<PolyMover> movers;
|
||||
private int latestIndex;
|
||||
|
||||
public PolyMoverFactory() {
|
||||
movers = new LinkedList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param time point in time whose cursor position has to be calculated
|
||||
* @return [x, y]
|
||||
*/
|
||||
public double[] getPointAt(int time) {
|
||||
double[] ret = new double[2];
|
||||
int i = 0;
|
||||
while (i < movers.size()) {
|
||||
if (movers.get(i).getLastItem().getEndTime() < time)
|
||||
break;
|
||||
double[] point = movers.get(i).getPointAt(time);
|
||||
ret[0] += point[0];
|
||||
ret[1] += point[1];
|
||||
i++;
|
||||
}
|
||||
ret[0] /= i;
|
||||
ret[1] /= i;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mover create(GameObject start, GameObject end, int dir) {
|
||||
throw new UnsupportedOperationException("Polymovers should use the create variant with all the gameobjects + startindex");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMultiPoint() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public final void create(GameObject[] objects, int startIndex) {
|
||||
if (latestIndex <= startIndex) {
|
||||
movers.clear();
|
||||
}
|
||||
GameObject[] items = new GameObject[getMaxBufferSize()];
|
||||
int i = 1;
|
||||
items[0] = startIndex == -1 ? Dancer.d : objects[startIndex];
|
||||
while (i < items.length - 1) {
|
||||
GameObject g = objects[startIndex + i];
|
||||
if (g.isSlider() || g.isSpinner())
|
||||
break;
|
||||
items[i++] = g;
|
||||
}
|
||||
items[i] = objects[startIndex + i];
|
||||
latestIndex = startIndex + getMaxBufferSize() + i - items.length;
|
||||
if (++i >= getMinBufferSize()) {
|
||||
init(items, i);
|
||||
}
|
||||
else {
|
||||
addMover(new LineMover(objects, startIndex + 1, i));
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void init(GameObject[] objects, int count);
|
||||
|
||||
public final void update(GameObject g) {
|
||||
GameObject[] items = movers.get(movers.size() - 1).getItems();
|
||||
if (items[items.length - 1] != g) {
|
||||
System.arraycopy(items, 1, items, 0, items.length - 1);
|
||||
items[items.length - 1] = g;
|
||||
create(items, 0);
|
||||
latestIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How many items the Factory would like to look in the future at most
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getMaxBufferSize();
|
||||
|
||||
/**
|
||||
* How many items the Factory would like to look in the future at least
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getMinBufferSize();
|
||||
|
||||
|
||||
public boolean isInitialized() {
|
||||
return movers.isEmpty();
|
||||
}
|
||||
|
||||
protected PolyMover getCurrent() {
|
||||
return movers.peekLast();
|
||||
}
|
||||
|
||||
protected List<PolyMover> getMovers() {
|
||||
return movers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Mover to the end of the list. It will also remove the first mover, if the list is bigger than the buffersize.
|
||||
*
|
||||
* @param mover the mover to be added
|
||||
*/
|
||||
protected void addMover(PolyMover mover) {
|
||||
movers.add(mover);
|
||||
if (movers.size() >= getMaxBufferSize())
|
||||
movers.remove();
|
||||
}
|
||||
|
||||
public int getLatestIndex() {
|
||||
return latestIndex;
|
||||
}
|
||||
|
||||
}
|
|
@ -613,12 +613,13 @@ public class Options {
|
|||
|
||||
@Override
|
||||
public String write() {
|
||||
return Dancer.instance.getMoverFactoryIndex() + "";
|
||||
return String.valueOf(Dancer.instance.getMoverFactoryIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(String s) {
|
||||
Dancer.instance.setMoverFactoryIndex(Integer.parseInt(s));
|
||||
int i = Integer.parseInt(s);
|
||||
Dancer.instance.setMoverFactoryIndex(i);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
@ -424,53 +425,13 @@ public class Game extends BasicGameState {
|
|||
autoMousePressed = false;
|
||||
if (GameMod.AUTO.isActive() || GameMod.AUTOPILOT.isActive()) {
|
||||
Vec2f autoPoint;
|
||||
if (objectIndex < beatmap.objects.length) {
|
||||
GameObject p;
|
||||
if (objectIndex > 0) {
|
||||
p = gameObjects[objectIndex - 1];
|
||||
} else {
|
||||
p = Dancer.d;
|
||||
}
|
||||
if (objectIndex < beatmap.objects.length - Dancer.instance.getPolyMoverFactoryMinBufferSize()) {
|
||||
Dancer d = Dancer.instance;
|
||||
d.update(trackPosition, p, gameObjects[objectIndex]);
|
||||
d.update(trackPosition, objectIndex);
|
||||
autoPoint = new Vec2f(d.x, d.y);
|
||||
if (trackPosition < gameObjects[objectIndex].getTime()) {
|
||||
autoMousePressed = true;
|
||||
}
|
||||
/*
|
||||
// normal object
|
||||
int objectTime = beatmap.objects[objectIndex].getTime();
|
||||
if (trackPosition < objectTime) {
|
||||
Vec2f startPoint = gameObjects[objectIndex - 1].getPointAt(trackPosition);
|
||||
int startTime = gameObjects[objectIndex - 1].getEndTime();
|
||||
if (beatmap.breaks != null && breakIndex < beatmap.breaks.size()) {
|
||||
// starting a break: keep cursor at previous hit object position
|
||||
if (breakTime > 0 || objectTime > beatmap.breaks.get(breakIndex))
|
||||
autoPoint = startPoint;
|
||||
|
||||
// after a break ends: move startTime to break end time
|
||||
else if (breakIndex > 1) {
|
||||
int lastBreakEndTime = beatmap.breaks.get(breakIndex - 1);
|
||||
if (objectTime > lastBreakEndTime && startTime < lastBreakEndTime)
|
||||
startTime = lastBreakEndTime;
|
||||
}
|
||||
}
|
||||
if (autoPoint == null) {
|
||||
Vec2f endPoint = gameObjects[objectIndex].getPointAt(trackPosition);
|
||||
int totalTime = objectTime - startTime;
|
||||
autoPoint = getPointAt(startPoint.x, startPoint.y, endPoint.x, endPoint.y, (float) (trackPosition - startTime) / totalTime);
|
||||
|
||||
// hit circles: show a mouse press
|
||||
int offset300 = hitResultOffset[GameData.HIT_300];
|
||||
if ((beatmap.objects[objectIndex].isCircle() && objectTime - trackPosition < offset300) ||
|
||||
(beatmap.objects[objectIndex - 1].isCircle() && trackPosition - beatmap.objects[objectIndex - 1].getTime() < offset300))
|
||||
autoMousePressed = true;
|
||||
}
|
||||
} else {
|
||||
autoPoint = gameObjects[objectIndex].getPointAt(trackPosition);
|
||||
autoMousePressed = true;
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
// last object
|
||||
autoPoint = gameObjects[objectIndex - 1].getPointAt(trackPosition);
|
||||
|
@ -1490,6 +1451,7 @@ public class Game extends BasicGameState {
|
|||
}
|
||||
|
||||
|
||||
Dancer.instance.setGameObjects(gameObjects);
|
||||
sbOverlay.setGameObjects(gameObjects);
|
||||
if (!checkpointLoaded) {
|
||||
sbOverlay.enter();
|
||||
|
@ -1512,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;
|
||||
|
|
|
@ -19,6 +19,10 @@ package yugecin.opsudance;
|
|||
|
||||
import awlex.ospu.movers.factories.CenterSpiralMoverFactory;
|
||||
import awlex.ospu.movers.factories.SpiralMoverFactory;
|
||||
import awlex.ospu.polymover.PolyMover;
|
||||
import awlex.ospu.polymover.factory.ArcFactory;
|
||||
import awlex.ospu.polymover.factory.LinearFactory;
|
||||
import awlex.ospu.polymover.factory.PolyMoverFactory;
|
||||
import awlex.ospu.spinners.SpiralSpinner;
|
||||
import itdelatrisu.opsu.Options;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
|
@ -49,6 +53,8 @@ public class Dancer {
|
|||
new QuartCircleMoverFactory(),
|
||||
new SpiralMoverFactory(),
|
||||
new CenterSpiralMoverFactory(),
|
||||
new LinearFactory(),
|
||||
new ArcFactory(),
|
||||
};
|
||||
|
||||
public static Spinner[] spinners = new Spinner[]{
|
||||
|
@ -72,6 +78,7 @@ public class Dancer {
|
|||
|
||||
public static Dancer instance = new Dancer();
|
||||
|
||||
public static boolean multipoint = false;
|
||||
public static boolean mirror = false; // this should really get its own place somewhere...
|
||||
public static boolean drawApproach = true; // this should really get its own place somewhere...
|
||||
public static boolean removebg = true; // this should really get its own place somewhere...
|
||||
|
@ -90,7 +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;
|
||||
|
@ -115,7 +124,7 @@ public class Dancer {
|
|||
|
||||
public void reset() {
|
||||
isCurrentLazySlider = false;
|
||||
p = null;
|
||||
objectIndex = -1;
|
||||
dir = 1;
|
||||
for (Spinner s : spinners) {
|
||||
s.init();
|
||||
|
@ -144,15 +153,44 @@ 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 void update(int time, GameObject p, GameObject c) {
|
||||
public int getPolyMoverFactoryMinBufferSize() {
|
||||
if (!multipoint) {
|
||||
return 0;
|
||||
}
|
||||
return ((PolyMoverFactory) moverFactory).getMinBufferSize();
|
||||
}
|
||||
|
||||
public void setGameObjects(GameObject[] objs) {
|
||||
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) {
|
||||
p = d;
|
||||
} else {
|
||||
p = gameObjects[objectIndex - 1];
|
||||
}
|
||||
GameObject c = gameObjects[objectIndex];
|
||||
if (!multipoint) {
|
||||
GameObject[] e = sliderMoverController.process(p, c, time);
|
||||
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]);
|
||||
|
@ -175,16 +213,18 @@ public class Dancer {
|
|||
double[] spinnerStartPoint = spinner.getPoint();
|
||||
c.start = new Vec2f((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
|
||||
}
|
||||
if (p == d) {
|
||||
mover = new LinearMover(p, c, dir);
|
||||
} else {
|
||||
mover = moverFactory.create(p, c, dir);
|
||||
}
|
||||
|
||||
createNewMover();
|
||||
}
|
||||
|
||||
if (time < c.getTime()) {
|
||||
if (!p.isSpinner() || !c.isSpinner()) {
|
||||
double[] point = mover.getPointAt(time);
|
||||
double[] point;
|
||||
if (multipoint) {
|
||||
point = ((PolyMoverFactory) moverFactory).getPointAt(time);
|
||||
} else {
|
||||
point = mover.getPointAt(time);
|
||||
}
|
||||
x = (float) point[0];
|
||||
y = (float) point[1];
|
||||
}
|
||||
|
@ -209,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ public abstract class Mover {
|
|||
protected double endX;
|
||||
protected double endY;
|
||||
|
||||
private GameObject end;
|
||||
|
||||
public Mover(GameObject start, GameObject end, int dir) {
|
||||
this.dir = dir;
|
||||
this.startX = start.end.x;
|
||||
|
@ -40,6 +42,7 @@ public abstract class Mover {
|
|||
this.endY = end.start.y;
|
||||
this.startT = start.getEndTime();
|
||||
this.totalT = end.getTime() - startT;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
protected final double getT(int time) {
|
||||
|
@ -49,4 +52,7 @@ public abstract class Mover {
|
|||
public abstract double[] getPointAt(int time);
|
||||
public abstract String getName();
|
||||
|
||||
public GameObject getEnd() {
|
||||
return end;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,4 +24,8 @@ public interface MoverFactory {
|
|||
|
||||
Mover create(GameObject start, GameObject end, int dir);
|
||||
|
||||
default boolean isMultiPoint() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user