Merge remote-tracking branch 'refs/remotes/origin/Curving'

This commit is contained in:
Awlex 2016-11-20 13:52:22 +01:00
commit 8dcfe96fff
9 changed files with 285 additions and 146 deletions

View File

@ -1,15 +1,18 @@
package awlex.ospu.polymover; package awlex.ospu.polymover;
import Jama.Matrix; import Jama.Matrix;
import itdelatrisu.opsu.objects.Circle;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import itdelatrisu.opsu.objects.Slider;
import static java.lang.Math.*; import static java.lang.Math.*;
/** /**
* Created by Awlex on 13.11.2016. * Created by Awlex on 13.11.2016.
*/ */
public class ArcMover extends PolyMover { public class ArcMover implements PolyMover {
public static final int ITEMS_NEEDED = 3;
private GameObject p1, middle, p2; private GameObject p1, middle, p2;
private double xm, ym, r, alpha, beta, gamma; private double xm, ym, r, alpha, beta, gamma;
@ -20,21 +23,13 @@ public class ArcMover extends PolyMover {
init(); init();
} }
public ArcMover(PolyMover mover, GameObject p) {
GameObject[] items = mover.getItems();
p1 = items[items.length - 2];
middle = items[items.length - 1];
p2 = p;
init();
}
private void init() { private void init() {
Matrix m = prepareMatrix(p1, middle, p2); Matrix m = prepareMatrix(p1, middle, p2);
xm = m.get(1, 0) * 0.5; xm = m.get(1, 0) * 0.5;
ym = m.get(2, 0) * 0.5; ym = m.get(2, 0) * 0.5;
r = sqrt(pow(xm, 2) + pow(ym, 2) - m.get(0, 0)); r = sqrt(pow(xm, 2) + pow(ym, 2) - m.get(0, 0));
alpha = atan2(p1.end.y - ym, p1.end.x - xm); alpha = atan2(p1.end.y - ym, p1.end.x - xm);
beta = atan2(middle.end.y - ym, middle.end.x - xm); beta = atan2(middle.start.y - ym, middle.start.x - xm);
gamma = atan2(p2.start.y - ym, p2.start.x - xm); gamma = atan2(p2.start.y - ym, p2.start.x - xm);
} }
@ -42,10 +37,11 @@ public class ArcMover extends PolyMover {
public double[] getPointAt(int time) { public double[] getPointAt(int time) {
double angle; double angle;
if (time < middle.getTime()) { if (time < middle.getTime()) {
angle = alpha + beta * ((double) time - p1.getEndTime()) / ((middle.getTime() - p1.getEndTime())); double percent = ((double) time - p1.getEndTime()) / ((middle.getTime() - p1.getEndTime()));
angle = alpha + (beta - alpha) * percent;
} }
else { else {
angle = beta + gamma * ((double) time - middle.getTime()) / (p2.getTime() - middle.getTime()); angle = beta + (gamma - beta) * ((double) time - middle.getTime()) / (p2.getTime() - middle.getTime());
} }
return new double[]{ return new double[]{
xm + r * cos(angle), xm + r * cos(angle),
@ -63,17 +59,34 @@ public class ArcMover extends PolyMover {
} }
private static Matrix prepareMatrix(GameObject p1, GameObject middle, GameObject p2) { private static Matrix prepareMatrix(GameObject p1, GameObject middle, GameObject p2) {
Matrix a = new Matrix(new double[][]{ Matrix a, b;
//if (!p2.isSlider()) {
a = new Matrix(new double[][]{
{1, -p1.end.x, -p1.end.y}, {1, -p1.end.x, -p1.end.y},
{1, -middle.end.x, -middle.end.y}, {1, -middle.start.x, -middle.start.y},
{1, -p2.start.x, -p2.start.y} {1, -p2.start.x, -p2.start.y}
}); });
Matrix b = new Matrix(new double[][]{ b = new Matrix(new double[][]{
{-(pow(p1.end.x, 2) + pow(p1.end.y, 2))}, {-(pow(p1.end.x, 2) + pow(p1.end.y, 2))},
{-(pow(middle.end.x, 2) + pow(middle.end.y, 2))}, {-(pow(middle.start.x, 2) + pow(middle.start.y, 2))},
{-(pow(p2.start.x, 2) + pow(p2.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); return a.solve(b);
} }
@ -85,4 +98,9 @@ public class ArcMover extends PolyMover {
} }
return true; return true;
} }
@Override
public GameObject getLastItem() {
return p2;
}
} }

View File

@ -2,31 +2,54 @@ package awlex.ospu.polymover;
import itdelatrisu.opsu.objects.DummyObject; import itdelatrisu.opsu.objects.DummyObject;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import itdelatrisu.opsu.states.Game;
import yugecin.opsudance.movers.LinearMover; import yugecin.opsudance.movers.LinearMover;
import java.util.Arrays;
/** /**
* Created by Awlex on 19.11.2016. * Created by Awlex on 19.11.2016.
*/ */
public class LineMover extends PolyMover { public class LineMover implements PolyMover {
public static final int ITEMS_NEEDED = 2;
private GameObject[] objects;
private LinearMover m;
private int currentIndex;
GameObject[] objects;
public LineMover(GameObject[] objects, int startIndex, int count) { public LineMover(GameObject[] objects, int startIndex, int count) {
this.objects = new GameObject[count]; this.objects = objects;
System.arraycopy(objects, startIndex, this.objects, 0, count); m = new LinearMover(objects[startIndex], objects[startIndex + 1], 1);
currentIndex = startIndex + 1;
}
public LineMover(GameObject[] objects, int count) {
this(objects, 0, count);
} }
@Override @Override
public double[] getPointAt(int time) { public double[] getPointAt(int time) {
int i = 0; if (objects[currentIndex].getEndTime() < time)
while (time > objects[i].getTime() && i < objects.length - 1) m = new LinearMover(objects[currentIndex], objects[currentIndex + 1], 1);
i++; return m.getPointAt(time);
return new LinearMover(i == 0 ? new DummyObject() : objects[i - 1], objects[i], 1).getPointAt(time);
} }
@Override @Override
public GameObject[] getItems() { public GameObject[] getItems() {
return new GameObject[0]; return objects;
}
@Override
public GameObject getLastItem() {
int i = objects.length - 1;
while (i > 0) {
if (objects[i] != null) {
break;
}
i--;
}
return objects[i];
} }
} }

View File

@ -5,8 +5,11 @@ import itdelatrisu.opsu.objects.GameObject;
/** /**
* Created by Awlex on 18.11.2016. * Created by Awlex on 18.11.2016.
*/ */
public abstract class PolyMover { public interface PolyMover {
public abstract double[] getPointAt(int time);
public abstract GameObject[] getItems(); double[] getPointAt(int time);
GameObject[] getItems();
GameObject getLastItem();
} }

View File

@ -3,60 +3,33 @@ package awlex.ospu.polymover.factory;
import awlex.ospu.polymover.ArcMover; import awlex.ospu.polymover.ArcMover;
import awlex.ospu.polymover.LineMover; import awlex.ospu.polymover.LineMover;
import awlex.ospu.polymover.PolyMover; import awlex.ospu.polymover.PolyMover;
import itdelatrisu.opsu.objects.DummyObject;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import java.util.Arrays;
/** /**
* Created by Awlex on 18.11.2016. * Created by Awlex on 18.11.2016.
*/ */
public class ArcFactory implements PolyMoverFactory { public class ArcFactory extends PolyMoverFactory {
private static final int PREFFERED_BUFFER_SIZE = 3; private static final int PREFFERED_BUFFER_SIZE = 3;
private PolyMover current, previous;
private int lastIndex;
public double[] getPointAt(int time) { public void init(GameObject[] objects, int count) {
if (previous == null) { if (count < 3 || (!ArcMover.canCricleExistBetweenItems(objects[0], objects[1], objects[2])))
return current.getPointAt(time); addMover(new LineMover(objects, 3));
}
double[] point1 = current.getPointAt(time);
double[] point2 = previous.getPointAt(time);
return new double[]{
(point1[0] + point2[0]) * 0.5,
(point1[1] + point2[1]) * 0.5
};
}
public void init(GameObject[] objects, int startIndex) {
if (objects == null)
throw new NullPointerException("Objects musn't be 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 else
current = new ArcMover(objects[startIndex], middle, objects[startIndex + 2]); addMover(new ArcMover(objects[0], objects[1], objects[2]));
lastIndex = startIndex + 2;
previous = null;
}
public void update(GameObject 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 @Override
public int getPrefferedBufferSize() { public int getMaxBufferSize() {
return PREFFERED_BUFFER_SIZE; return ArcMover.ITEMS_NEEDED;
}
@Override
public int getMinBufferSize() {
return LineMover.ITEMS_NEEDED;
} }
@Override @Override
@ -64,14 +37,4 @@ public class ArcFactory implements PolyMoverFactory {
return "Arcs"; return "Arcs";
} }
@Override
public boolean isInitialized() {
return current != null;
}
@Override
public int getLatestIndex() {
return lastIndex;
}
} }

View 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";
}
}

View File

@ -1,30 +1,122 @@
package awlex.ospu.polymover.factory; package awlex.ospu.polymover.factory;
import awlex.ospu.polymover.LineMover;
import awlex.ospu.polymover.PolyMover;
import itdelatrisu.opsu.objects.DummyObject;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import yugecin.opsudance.Dancer;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
/** /**
* Created by Awlex on 18.11.2016. * Created by Awlex on 18.11.2016.
*/ */
public interface PolyMoverFactory { public abstract class PolyMoverFactory {
private LinkedList<PolyMover> movers;
private int latestIndex;
public PolyMoverFactory() {
movers = new LinkedList<>();
}
/** /**
* @param time point in time whose cursor position has to be calculated * @param time point in time whose cursor position has to be calculated
* @return [x, y] * @return [x, y]
*/ */
double[] getPointAt(int time); 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;
}
void init(GameObject[] objects, int startIndex); 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));
}
}
void update(GameObject g); 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 * How many items the Factory would like to look in the future at most
* *
* @return * @return
*/ */
int getPrefferedBufferSize(); public abstract int getMaxBufferSize();
boolean isInitialized(); /**
* 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;
}
int getLatestIndex();
} }

View File

@ -594,7 +594,7 @@ public class Options {
DISABLE_UPDATER ("Disable Automatic Updates", "DisableUpdater", "Disable automatic checking for updates upon starting opsu!.", false), 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), 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) { DANCE_MOVER_TYPE("Mover Type", "Mover type", "More than 2 Points", Dancer.multipoint) {
@Override @Override
public void click(GameContainer container) { public void click(GameContainer container) {
bool = !bool; bool = !bool;
@ -617,7 +617,7 @@ public class Options {
@Override @Override
public void clickListItem(int index) { public void clickListItem(int index) {
if (Dancer.multipoint) if (Dancer.multipoint)
Dancer.instance.setMoverFactoryIndex(index); Dancer.instance.setPolyMoverFactoryIndex(index);
else else
Dancer.instance.setMoverFactoryIndex(index); Dancer.instance.setMoverFactoryIndex(index);
} }

View File

@ -421,7 +421,7 @@ public class Game extends BasicGameState {
autoMousePressed = false; autoMousePressed = false;
if (GameMod.AUTO.isActive() || GameMod.AUTOPILOT.isActive()) { if (GameMod.AUTO.isActive() || GameMod.AUTOPILOT.isActive()) {
Vec2f autoPoint; Vec2f autoPoint;
if (objectIndex < beatmap.objects.length - (Dancer.multipoint ? Dancer.polyMoverFactories[Dancer.instance.getPolyMoverFactoryIndex()].getPrefferedBufferSize() : 0)) { if (objectIndex < beatmap.objects.length - (Dancer.multipoint ? Dancer.polyMoverFactories[Dancer.instance.getPolyMoverFactoryIndex()].getMinBufferSize() : 0)) {
Dancer d = Dancer.instance; Dancer d = Dancer.instance;
if (Dancer.multipoint) { if (Dancer.multipoint) {
d.update(trackPosition, gameObjects, objectIndex); d.update(trackPosition, gameObjects, objectIndex);

View File

@ -19,8 +19,8 @@ package yugecin.opsudance;
import awlex.ospu.movers.factories.CenterSpiralMoverFactory; import awlex.ospu.movers.factories.CenterSpiralMoverFactory;
import awlex.ospu.movers.factories.SpiralMoverFactory; import awlex.ospu.movers.factories.SpiralMoverFactory;
import awlex.ospu.polymover.PolyMover;
import awlex.ospu.polymover.factory.ArcFactory; import awlex.ospu.polymover.factory.ArcFactory;
import awlex.ospu.polymover.factory.LinearFactory;
import awlex.ospu.polymover.factory.PolyMoverFactory; import awlex.ospu.polymover.factory.PolyMoverFactory;
import awlex.ospu.spinners.SpiralSpinner; import awlex.ospu.spinners.SpiralSpinner;
import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Options;
@ -74,6 +74,7 @@ public class Dancer {
}; };
public static PolyMoverFactory[] polyMoverFactories = new PolyMoverFactory[]{ public static PolyMoverFactory[] polyMoverFactories = new PolyMoverFactory[]{
new LinearFactory(),
new ArcFactory() new ArcFactory()
}; };
@ -249,6 +250,7 @@ public class Dancer {
c.start.set((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]); c.start.set((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
} }
} }
isCurrentLazySlider = false; isCurrentLazySlider = false;
// detect lazy sliders, should work pretty good // 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) { if (c.isSlider() && LAZY_SLIDERS && Utils.distance(c.start.x, c.start.y, c.end.x, c.end.y) <= Circle.diameter * 0.8f) {
@ -267,15 +269,15 @@ public class Dancer {
c.start = new Vec2f((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]); c.start = new Vec2f((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
} }
if (polyMoverFactory.isInitialized() && polyMoverFactory.getLatestIndex() < objectIndex + polyMoverFactory.getPrefferedBufferSize() - 1) { if (polyMoverFactory.isInitialized() && polyMoverFactory.getLatestIndex() < objectIndex + polyMoverFactory.getLatestIndex() - 1) {
polyMoverFactory.update(gameObjects[polyMoverFactory.getPrefferedBufferSize() - 1]); polyMoverFactory.update(gameObjects[objectIndex + polyMoverFactory.getMaxBufferSize() - 1]);
} else { }
polyMoverFactory.init(gameObjects, objectIndex); else {
polyMoverFactory.create(gameObjects, objectIndex - 1);
} }
} }
if (time < c.getTime()) { if (time < c.getTime()) {
if (!p.isSpinner() || !c.isSpinner()) { if (!(p.isSpinner() || c.isSpinner())) {
double[] point = polyMoverFactory.getPointAt(time); double[] point = polyMoverFactory.getPointAt(time);
x = (float) point[0]; x = (float) point[0];
y = (float) point[1]; y = (float) point[1];