Merge remote-tracking branch 'refs/remotes/origin/Curving'
This commit is contained in:
commit
9ff2145b39
|
@ -8,19 +8,19 @@ import static java.lang.Math.*;
|
|||
/**
|
||||
* Created by Awlex on 13.11.2016.
|
||||
*/
|
||||
public class Arc extends PolyMover {
|
||||
public class ArcMover extends PolyMover {
|
||||
|
||||
private GameObject p1, middle, p2;
|
||||
private double xm, ym, r, alpha, beta, gamma;
|
||||
|
||||
public Arc(GameObject p1, GameObject middle, GameObject p2) {
|
||||
public ArcMover(GameObject p1, GameObject middle, GameObject p2) {
|
||||
this.p1 = p1;
|
||||
this.middle = middle;
|
||||
this.p2 = p2;
|
||||
init();
|
||||
}
|
||||
|
||||
public Arc(PolyMover mover, GameObject p) {
|
||||
public ArcMover(PolyMover mover, GameObject p) {
|
||||
GameObject[] items = mover.getItems();
|
||||
p1 = items[items.length - 2];
|
||||
middle = items[items.length - 1];
|
||||
|
@ -30,27 +30,22 @@ public class Arc extends PolyMover {
|
|||
|
||||
private void init() {
|
||||
Matrix m = prepareMatrix(p1, middle, p2);
|
||||
xm = m.get(2, 1);
|
||||
ym = m.get(3, 1);
|
||||
r = pow(xm, 2) + pow(ym, 2) - m.get(1, 1);
|
||||
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.end.y - ym, middle.end.x - xm);
|
||||
gamma = atan2(p2.start.y - ym, p2.start.x - xm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getPoint(int time) {
|
||||
double percent;
|
||||
public double[] getPointAt(int time) {
|
||||
double angle;
|
||||
if (time < middle.getTime()) {
|
||||
time -= p1.getEndTime();
|
||||
percent = ((double) time) / ((middle.getTime() - p1.getEndTime()));
|
||||
angle = alpha + beta * percent;
|
||||
angle = alpha + beta * ((double) time - p1.getEndTime()) / ((middle.getTime() - p1.getEndTime()));
|
||||
}
|
||||
else {
|
||||
time -= middle.getTime();
|
||||
percent = ((double) time) / (p2.getTime() - middle.getTime());
|
||||
angle = beta + gamma * percent;
|
||||
angle = beta + gamma * ((double) time - middle.getTime()) / (p2.getTime() - middle.getTime());
|
||||
}
|
||||
return new double[]{
|
||||
xm + r * cos(angle),
|
||||
|
@ -67,7 +62,7 @@ public class Arc extends PolyMover {
|
|||
};
|
||||
}
|
||||
|
||||
private Matrix prepareMatrix(GameObject p1, GameObject middle, GameObject p2) {
|
||||
private static Matrix prepareMatrix(GameObject p1, GameObject middle, GameObject p2) {
|
||||
Matrix a = new Matrix(new double[][]{
|
||||
{1, -p1.end.x, -p1.end.y},
|
||||
{1, -middle.end.x, -middle.end.y},
|
||||
|
@ -83,6 +78,11 @@ public class Arc extends PolyMover {
|
|||
}
|
||||
|
||||
public static boolean canCricleExistBetweenItems(GameObject p1, GameObject p2, GameObject p3) {
|
||||
return !((p1.end.x == p2.start.x && p1.end.x == p3.start.x) || (p1.end.y == p2.start.y && p1.end.y == p3.start.y));
|
||||
try {
|
||||
prepareMatrix(p1, p2, p3);
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
32
src/awlex/ospu/polymover/LineMover.java
Normal file
32
src/awlex/ospu/polymover/LineMover.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package awlex.ospu.polymover;
|
||||
|
||||
import itdelatrisu.opsu.objects.DummyObject;
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
import yugecin.opsudance.movers.LinearMover;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 19.11.2016.
|
||||
*/
|
||||
public class LineMover extends PolyMover {
|
||||
|
||||
GameObject[] objects;
|
||||
|
||||
public LineMover(GameObject[] objects, int startIndex, int count) {
|
||||
this.objects = new GameObject[count];
|
||||
System.arraycopy(objects, startIndex, this.objects, 0, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getPointAt(int time) {
|
||||
int i = 0;
|
||||
while (time > objects[i].getTime() && i < objects.length - 1)
|
||||
i++;
|
||||
|
||||
return new LinearMover(i == 0 ? new DummyObject() : objects[i - 1], objects[i], 1).getPointAt(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameObject[] getItems() {
|
||||
return new GameObject[0];
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ import itdelatrisu.opsu.objects.GameObject;
|
|||
* Created by Awlex on 18.11.2016.
|
||||
*/
|
||||
public abstract class PolyMover {
|
||||
public abstract double[] getPoint(int time);
|
||||
public abstract double[] getPointAt(int time);
|
||||
|
||||
public abstract GameObject[] getItems();
|
||||
}
|
|
@ -1,25 +1,26 @@
|
|||
package awlex.ospu.polymover.factory;
|
||||
|
||||
import awlex.ospu.polymover.Arc;
|
||||
import awlex.ospu.polymover.ArcMover;
|
||||
import awlex.ospu.polymover.LineMover;
|
||||
import awlex.ospu.polymover.PolyMover;
|
||||
import itdelatrisu.opsu.objects.GameObject;
|
||||
|
||||
/**
|
||||
* Created by Awlex on 18.11.2016.
|
||||
*/
|
||||
public class ArcFactory implements MultiMoverFactory {
|
||||
public class ArcFactory implements PolyMoverFactory {
|
||||
|
||||
private static final int PREFFERED_BUFFER_SIZE = 3;
|
||||
private PolyMover arc1, arc2;
|
||||
private PolyMover current, previous;
|
||||
private int lastIndex;
|
||||
|
||||
@Override
|
||||
public double[] getPoint(int time) {
|
||||
if (arc2 == null) {
|
||||
return arc1.getPoint(time);
|
||||
public double[] getPointAt(int time) {
|
||||
if (previous == null) {
|
||||
return current.getPointAt(time);
|
||||
}
|
||||
|
||||
double[] point1 = arc1.getPoint(time);
|
||||
double[] point2 = arc2.getPoint(time);
|
||||
double[] point1 = current.getPointAt(time);
|
||||
double[] point2 = previous.getPointAt(time);
|
||||
|
||||
return new double[]{
|
||||
(point1[0] + point2[0]) * 0.5,
|
||||
|
@ -31,15 +32,26 @@ public class ArcFactory implements MultiMoverFactory {
|
|||
public void init(GameObject[] objects, int startIndex) {
|
||||
if (objects == null)
|
||||
throw new NullPointerException("Objects musn't be null");
|
||||
if (objects.length < startIndex + 2)
|
||||
arc1 = new Arc(objects[startIndex], objects[startIndex + 1], objects[startIndex + 2]);
|
||||
arc2 = null;
|
||||
|
||||
GameObject middle = objects[startIndex + 1];
|
||||
if (middle.isSlider() || middle.isSpinner() || !ArcMover.canCricleExistBetweenItems(objects[startIndex], middle, objects[startIndex + 2]))
|
||||
current = new LineMover(objects, startIndex, 3);
|
||||
else
|
||||
current = new ArcMover(objects[startIndex], middle, objects[startIndex + 2]);
|
||||
lastIndex = startIndex + 2;
|
||||
previous = null;
|
||||
}
|
||||
|
||||
public void update(GameObject p) {
|
||||
if (arc2 != null)
|
||||
arc1 = arc2;
|
||||
arc2 = new Arc(arc1, p);
|
||||
GameObject[] items = (previous == null ? current : previous).getItems();
|
||||
GameObject last = items[items.length - 1];
|
||||
if (last != p) {
|
||||
if (ArcMover.canCricleExistBetweenItems(items[items.length - 2], items[items.length - 1], p)) {
|
||||
previous = current;
|
||||
current = new ArcMover(previous, p);
|
||||
}
|
||||
}
|
||||
lastIndex++;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,4 +63,15 @@ public class ArcFactory implements MultiMoverFactory {
|
|||
public String toString() {
|
||||
return "Arcs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return current != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLatestIndex() {
|
||||
return lastIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,14 +5,13 @@ import itdelatrisu.opsu.objects.GameObject;
|
|||
/**
|
||||
* Created by Awlex on 18.11.2016.
|
||||
*/
|
||||
public interface MultiMoverFactory {
|
||||
|
||||
public interface PolyMoverFactory {
|
||||
|
||||
/**
|
||||
* @param time point in time whose cursor position has to be calculated
|
||||
* @return [x, y]
|
||||
*/
|
||||
double[] getPoint(int time);
|
||||
double[] getPointAt(int time);
|
||||
|
||||
void init(GameObject[] objects, int startIndex);
|
||||
|
||||
|
@ -24,4 +23,8 @@ public interface MultiMoverFactory {
|
|||
* @return
|
||||
*/
|
||||
int getPrefferedBufferSize();
|
||||
|
||||
boolean isInitialized();
|
||||
|
||||
int getLatestIndex();
|
||||
}
|
|
@ -594,30 +594,51 @@ public class Options {
|
|||
DISABLE_UPDATER ("Disable Automatic Updates", "DisableUpdater", "Disable automatic checking for updates upon starting opsu!.", false),
|
||||
ENABLE_WATCH_SERVICE ("Enable Watch Service", "WatchService", "Watch the beatmap directory for changes. Requires a restart.", false),
|
||||
|
||||
DANCE_MOVER_TYPE("Mover Type", "Mover type", "More Points", Dancer.multipoint) {
|
||||
@Override
|
||||
public void click(GameContainer container) {
|
||||
bool = !bool;
|
||||
Dancer.multipoint = bool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(String s) {
|
||||
super.read(s);
|
||||
Dancer.multipoint = bool;
|
||||
}
|
||||
},
|
||||
|
||||
DANCE_MOVER ("Mover algorithm", "Mover", "Algorithm that decides how to move from note to note" ) {
|
||||
@Override
|
||||
public Object[] getListItems() {
|
||||
return Dancer.moverFactories;
|
||||
return Dancer.multipoint ? Dancer.polyMoverFactories : Dancer.moverFactories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clickListItem(int index) {
|
||||
if (Dancer.multipoint)
|
||||
Dancer.instance.setMoverFactoryIndex(index);
|
||||
else
|
||||
Dancer.instance.setMoverFactoryIndex(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueString() {
|
||||
return Dancer.moverFactories[Dancer.instance.getMoverFactoryIndex()].toString();
|
||||
return Dancer.multipoint ? Dancer.polyMoverFactories[Dancer.instance.getPolyMoverFactoryIndex()].toString() : Dancer.moverFactories[Dancer.instance.getMoverFactoryIndex()].toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String write() {
|
||||
return Dancer.instance.getMoverFactoryIndex() + "";
|
||||
return String.valueOf(Dancer.multipoint ? Dancer.instance.getPolyMoverFactoryIndex() : Dancer.instance.getMoverFactoryIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(String s) {
|
||||
Dancer.instance.setMoverFactoryIndex(Integer.parseInt(s));
|
||||
int i = Integer.parseInt(s);
|
||||
if (Dancer.multipoint)
|
||||
Dancer.instance.setPolyMoverFactoryIndex(i);
|
||||
else
|
||||
Dancer.instance.setMoverFactoryIndex(i);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -421,15 +421,20 @@ public class Game extends BasicGameState {
|
|||
autoMousePressed = false;
|
||||
if (GameMod.AUTO.isActive() || GameMod.AUTOPILOT.isActive()) {
|
||||
Vec2f autoPoint;
|
||||
if (objectIndex < beatmap.objects.length) {
|
||||
if (objectIndex < beatmap.objects.length - (Dancer.multipoint ? Dancer.polyMoverFactories[Dancer.instance.getPolyMoverFactoryIndex()].getPrefferedBufferSize() : 0)) {
|
||||
Dancer d = Dancer.instance;
|
||||
if (Dancer.multipoint) {
|
||||
d.update(trackPosition, gameObjects, objectIndex);
|
||||
} else {
|
||||
GameObject p;
|
||||
if (objectIndex > 0) {
|
||||
p = gameObjects[objectIndex - 1];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
p = Dancer.d;
|
||||
}
|
||||
Dancer d = Dancer.instance;
|
||||
d.update(trackPosition, p, gameObjects[objectIndex]);
|
||||
}
|
||||
autoPoint = new Vec2f(d.x, d.y);
|
||||
if (trackPosition < gameObjects[objectIndex].getTime()) {
|
||||
autoMousePressed = true;
|
||||
|
|
|
@ -112,6 +112,7 @@ public class OptionsMenu extends BasicGameState {
|
|||
GameOption.ENABLE_WATCH_SERVICE
|
||||
}),
|
||||
DANCE ("Dance", new GameOption[] {
|
||||
GameOption.DANCE_MOVER_TYPE,
|
||||
GameOption.DANCE_MOVER,
|
||||
GameOption.DANCE_MOVER_DIRECTION,
|
||||
GameOption.DANCE_SLIDER_MOVER_TYPE,
|
||||
|
|
|
@ -19,6 +19,9 @@ 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.PolyMoverFactory;
|
||||
import awlex.ospu.spinners.SpiralSpinner;
|
||||
import itdelatrisu.opsu.Options;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
|
@ -70,8 +73,13 @@ public class Dancer {
|
|||
new InheritedSliderMoverController(),
|
||||
};
|
||||
|
||||
public static PolyMoverFactory[] polyMoverFactories = new PolyMoverFactory[]{
|
||||
new ArcFactory()
|
||||
};
|
||||
|
||||
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...
|
||||
|
@ -93,11 +101,13 @@ public class Dancer {
|
|||
private GameObject p;
|
||||
|
||||
private MoverFactory moverFactory;
|
||||
private PolyMoverFactory polyMoverFactory;
|
||||
private Mover mover;
|
||||
private Spinner spinner;
|
||||
public static SliderMoverController sliderMoverController;
|
||||
|
||||
private int moverFactoryIndex;
|
||||
private int polyMoverFactoryIndex;
|
||||
private int spinnerIndex;
|
||||
|
||||
public float x;
|
||||
|
@ -146,6 +156,18 @@ public class Dancer {
|
|||
moverFactory = moverFactories[moverFactoryIndex];
|
||||
}
|
||||
|
||||
public int getPolyMoverFactoryIndex() {
|
||||
return polyMoverFactoryIndex;
|
||||
}
|
||||
|
||||
public void setPolyMoverFactoryIndex(int polyMoverFactoryIndex) {
|
||||
if (polyMoverFactoryIndex < 0 || polyMoverFactoryIndex >= polyMoverFactories.length) {
|
||||
polyMoverFactoryIndex = 0;
|
||||
}
|
||||
this.polyMoverFactoryIndex = polyMoverFactoryIndex;
|
||||
polyMoverFactory = polyMoverFactories[polyMoverFactoryIndex];
|
||||
}
|
||||
|
||||
public void update(int time, GameObject p, GameObject c) {
|
||||
GameObject[] e = sliderMoverController.process(p, c, time);
|
||||
p = e[0];
|
||||
|
@ -175,9 +197,11 @@ public class Dancer {
|
|||
double[] spinnerStartPoint = spinner.getPoint();
|
||||
c.start = new Vec2f((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
|
||||
}
|
||||
if (mover == null || mover.getEnd() != c)
|
||||
if (p == d) {
|
||||
mover = new LinearMover(p, c, dir);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
mover = moverFactory.create(p, c, dir);
|
||||
}
|
||||
}
|
||||
|
@ -188,14 +212,16 @@ public class Dancer {
|
|||
x = (float) point[0];
|
||||
y = (float) point[1];
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (c.isSpinner()) {
|
||||
Spinner.PROGRESS = (double) (time - c.getTime()) / (double) (c.getEndTime() - c.getTime());
|
||||
double[] point = spinner.getPoint();
|
||||
x = (float) point[0];
|
||||
y = (float) point[1];
|
||||
c.end = new Vec2f(x, y);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Vec2f point = c.getPointAt(time);
|
||||
if (isCurrentLazySlider) {
|
||||
point = c.start;
|
||||
|
@ -209,4 +235,71 @@ public class Dancer {
|
|||
y = Utils.clamp(y, 10, Options.height - 10);
|
||||
}
|
||||
|
||||
public void update(int time, GameObject[] gameObjects, int objectIndex) {
|
||||
GameObject p, c;
|
||||
GameObject[] e = objectIndex > 0 ? sliderMoverController.process(gameObjects[objectIndex - 1], gameObjects[objectIndex], time)
|
||||
: sliderMoverController.process(d, gameObjects[objectIndex], time);
|
||||
p = e[0];
|
||||
c = e[1];
|
||||
if (this.p != p) {
|
||||
this.p = p;
|
||||
if (this.p == d) {
|
||||
if (c.isSpinner()) {
|
||||
double[] spinnerStartPoint = spinner.getPoint();
|
||||
c.start.set((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
|
||||
}
|
||||
}
|
||||
isCurrentLazySlider = false;
|
||||
// detect lazy sliders, should work pretty good
|
||||
if (c.isSlider() && LAZY_SLIDERS && Utils.distance(c.start.x, c.start.y, c.end.x, c.end.y) <= Circle.diameter * 0.8f) {
|
||||
Slider s = (Slider) c;
|
||||
Vec2f mid = s.getCurve().pointAt(1f);
|
||||
if (s.getRepeats() == 1 || Utils.distance(c.start.x, c.start.y, mid.x, mid.y) <= Circle.diameter * 0.8f) {
|
||||
mid = s.getCurve().pointAt(0.5f);
|
||||
if (Utils.distance(c.start.x, c.start.y, mid.x, mid.y) <= Circle.diameter * 0.8f) {
|
||||
isCurrentLazySlider = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
dir = moverDirection.getDirection(dir);
|
||||
if (c.isSpinner()) {
|
||||
double[] spinnerStartPoint = spinner.getPoint();
|
||||
c.start = new Vec2f((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
|
||||
}
|
||||
|
||||
if (polyMoverFactory.isInitialized() && polyMoverFactory.getLatestIndex() < objectIndex + polyMoverFactory.getPrefferedBufferSize() - 1) {
|
||||
polyMoverFactory.update(gameObjects[polyMoverFactory.getPrefferedBufferSize() - 1]);
|
||||
} else {
|
||||
polyMoverFactory.init(gameObjects, objectIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (time < c.getTime()) {
|
||||
if (!p.isSpinner() || !c.isSpinner()) {
|
||||
double[] point = polyMoverFactory.getPointAt(time);
|
||||
x = (float) point[0];
|
||||
y = (float) point[1];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (c.isSpinner()) {
|
||||
Spinner.PROGRESS = (double) (time - c.getTime()) / (double) (c.getEndTime() - c.getTime());
|
||||
double[] point = spinner.getPoint();
|
||||
x = (float) point[0];
|
||||
y = (float) point[1];
|
||||
c.end = new Vec2f(x, y);
|
||||
}
|
||||
else {
|
||||
Vec2f point = c.getPointAt(time);
|
||||
if (isCurrentLazySlider) {
|
||||
point = c.start;
|
||||
}
|
||||
x = point.x;
|
||||
y = point.y;
|
||||
}
|
||||
}
|
||||
Pippi.dance(time, c, isCurrentLazySlider);
|
||||
x = Utils.clamp(x, 10, Options.width - 10);
|
||||
y = Utils.clamp(y, 10, Options.height - 10);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user