Revert "Improved all Spiral Classes."

This reverts commit ffcdeed948.
This commit is contained in:
Awlex 2016-11-19 00:08:10 +01:00
parent e18034473a
commit 375a44722d
8 changed files with 287 additions and 327 deletions

View File

@ -27,30 +27,13 @@ public class FakeGameObject extends GameObject {
} }
public FakeGameObject(GameObject start, GameObject end) { public FakeGameObject(GameObject start, GameObject end) {
halfTime = Math.abs(start.getEndTime() + (end.getTime() - start.getEndTime()) / 2); halfTime = start.getEndTime() + (end.getTime() - start.getEndTime()) / 2;
this.start = new Vec2f(); this.start = new Vec2f();
this.end = new Vec2f(); this.end = new Vec2f();
this.start.x = this.end.x = (start.end.x + end.start.x) / 2; this.start.x = this.end.x = (start.end.x + end.start.x) / 2;
this.start.y = this.end.y = (start.end.y + end.start.y) / 2; this.start.y = this.end.y = (start.end.y + end.start.y) / 2;
} }
@Override
public int getEndTime() {
return halfTime;
}
@Override
public int getTime() {
return halfTime;
}
public void setTime(int time) {
this.halfTime = time;
}
/*
* Everything down here is unimportant
*/
@Override @Override
public void draw(Graphics g, int trackPosition, boolean mirrored) { public void draw(Graphics g, int trackPosition, boolean mirrored) {
@ -71,6 +54,16 @@ public class FakeGameObject extends GameObject {
return null; return null;
} }
@Override
public int getEndTime() {
return halfTime;
}
@Override
public int getTime() {
return halfTime;
}
@Override @Override
public void updatePosition() { public void updatePosition() {
@ -105,4 +98,8 @@ public class FakeGameObject extends GameObject {
return null; return null;
} }
public void setTime(int time) {
this.halfTime = time;
}
} }

View File

@ -1,24 +1,38 @@
package awlex.ospu.movers; package awlex.ospu.movers;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import yugecin.opsudance.movers.Mover; import yugecin.opsudance.movers.Mover;
/** /**
* Created by Alex Wieser on 09.10.2016. * Created by Alex Wieser on 09.10.2016.
* WHO DO YOU THINK I AM? * WHO DO YOU THINK I AM?
* <p> *
* This {@link Mover} starts the spiral from the start object * This {@link Mover} starts the spiral from the start object
*/ */
public class CentralSpiralMover extends SpiralMover { public class CentralSpiralMover extends Mover {
/**
* How many times the cursor goes around the center
* For satisfying results this musn't be a multiple of 2
*/
private final int CIRCLENAVIGATIONS = 1;
double startAng;
double startRad;
public CentralSpiralMover(GameObject start, GameObject end, int dir) { public CentralSpiralMover(GameObject start, GameObject end, int dir) {
super(start, end, dir); super(start, end, dir);
startAng = Math.atan2(endY - startY, endX - startX);
startRad = Utils.distance(startX, startY, endX, endY);
if (startRad < 20)
startRad = 20 + startRad / 20d;
} }
@Override @Override
public double[] getPointAt(int time) { public double[] getPointAt(int time) {
double rad = radius * getT(time); double rad = startRad * getT(time);
double ang = angle + 2d * Math.PI * getT(time) * dir; double ang = CIRCLENAVIGATIONS * (startAng + 2d * Math.PI * getT(time) * dir);
return new double[]{ return new double[]{
startX + rad * Math.cos(ang), startX + rad * Math.cos(ang),
startY + rad * Math.sin(ang) startY + rad * Math.sin(ang)
@ -26,11 +40,7 @@ public class CentralSpiralMover extends SpiralMover {
} }
@Override @Override
public boolean checkBounds() { public String getName() {
boolean ret = true; return "Spiral2";
int totalTime = endTime - startTime;
for (int i = 0; ret && i <= 20; i++)
ret = checkIfPointInBounds(getPointAt((int) (startTime + totalTime * (i / 20d))));
return ret;
} }
} }

View File

@ -4,8 +4,6 @@ import awlex.ospu.FakeGameObject;
import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import yugecin.opsudance.movers.CircleMover;
import yugecin.opsudance.movers.LinearMover;
import yugecin.opsudance.movers.Mover; import yugecin.opsudance.movers.Mover;
import yugecin.opsudance.movers.factories.AutoMoverFactory; import yugecin.opsudance.movers.factories.AutoMoverFactory;
@ -18,7 +16,7 @@ import yugecin.opsudance.movers.factories.AutoMoverFactory;
* 2 inner {@link Mover}s around it. This class works recursively and might lead to * 2 inner {@link Mover}s around it. This class works recursively and might lead to
* high ram usage on very jumpy maps or even a StackOverFlow. * high ram usage on very jumpy maps or even a StackOverFlow.
*/ */
public class CombinedSpiralMover extends SpiralMover { public class CombinedSpiralMover extends Mover {
private Mover[] movers; private Mover[] movers;
private GameObject fakeObject; private GameObject fakeObject;
@ -27,10 +25,6 @@ public class CombinedSpiralMover extends SpiralMover {
private int endTime; private int endTime;
public CombinedSpiralMover(GameObject middle, GameObject start, GameObject end, int dir) { public CombinedSpiralMover(GameObject middle, GameObject start, GameObject end, int dir) {
this(true, middle, start, end, dir);
}
public CombinedSpiralMover(boolean prefered, GameObject middle, GameObject start, GameObject end, int dir) {
super(start, end, dir); super(start, end, dir);
fakeObject = middle != null ? middle : new FakeGameObject(start, end); fakeObject = middle != null ? middle : new FakeGameObject(start, end);
@ -39,32 +33,14 @@ public class CombinedSpiralMover extends SpiralMover {
endTime = end.getTime(); endTime = end.getTime();
movers = new Mover[2]; movers = new Mover[2];
movers[0] = bestPick(prefered ? 0 : 1, start, fakeObject, dir); movers[0] = bestPick(0, start, fakeObject, dir);
movers[1] = bestPick(prefered ? 1 : 0, fakeObject, end, dir); movers[1] = bestPick(1, fakeObject, end, dir);
} }
public CombinedSpiralMover(GameObject start, GameObject end, int dir) { public CombinedSpiralMover(GameObject start, GameObject end, int dir) {
this(null, start, end, dir); this(null, start, end, dir);
} }
@Override
public boolean checkBounds() {
/*Not needed in this case*/
return true;
}
public CombinedSpiralMover(Mover mover1, Mover mover2, int startTime, int halfTime, int endTime) {
super(new FakeGameObject(), new FakeGameObject(), 0); //With this constructor you only care about the movers
this.startTime = startTime;
this.endTime = endTime;
this.halfTime = halfTime;
movers = new Mover[]{
mover1,
mover2
};
}
/** /**
* Method to pick the 2 inner {@link Mover}s. * Method to pick the 2 inner {@link Mover}s.
* Tries to pick a {@link SpiralToMover} first position and a * Tries to pick a {@link SpiralToMover} first position and a
@ -78,25 +54,23 @@ public class CombinedSpiralMover extends SpiralMover {
*/ */
private Mover bestPick(int pos, GameObject start, GameObject end, int dir) { private Mover bestPick(int pos, GameObject start, GameObject end, int dir) {
if (endTime - startTime < 40 || Utils.distance(start.end.x, start.end.y, end.start.x, end.start.y) < 40) if (endTime - startTime < 10 || Utils.distance(start.end.x, start.end.y, end.start.x, end.start.y) < 40)
return new LinearMover(start, end, dir); return new AutoMoverFactory().create(start, end, dir);
SpiralToMover spiralTo = new SpiralToMover(start, end, dir); SpiralToMover spiralTo = new SpiralToMover(start, end, dir);
CentralSpiralMover center = new CentralSpiralMover(start, end, dir); CentralSpiralMover center = new CentralSpiralMover(start, end, dir);
if (pos == 0) { if (pos == 0) {
if (spiralTo.checkBounds() || (spiralTo = new SpiralToMover(start, end, -dir)).checkBounds()) if (inBounds1(spiralTo) || inBounds1(spiralTo = new SpiralToMover(start, end, -dir)))
return spiralTo; return spiralTo;
else if (center.checkBounds() || (center = new CentralSpiralMover(start, end, -dir)).checkBounds()) else if (inBounds1(center) || inBounds1(center = new CentralSpiralMover(start, end, -dir)))
return center; return center;
} } else if (pos == 1) {
else if (pos == 1) { if (inBounds2(center) || inBounds2(center = new CentralSpiralMover(start, end, -dir)))
if (center.checkBounds() || (center = new CentralSpiralMover(start, end, -dir)).checkBounds())
return center; return center;
else if ((spiralTo = new SpiralToMover(start, end, -dir)).checkBounds() || (spiralTo = new SpiralToMover(start, end, dir)).checkBounds()) else if (inBounds2(spiralTo = new SpiralToMover(start, end, -dir)) || inBounds2(spiralTo = new SpiralToMover(start, end, dir)))
return spiralTo; return spiralTo;
} } else throw new IllegalStateException("Only 2 inner Movers allowed");
else throw new IllegalStateException("Only 2 inner Movers allowed");
return new CombinedSpiralMover(start, end, dir); return new CombinedSpiralMover(start, end, dir);
} }
@ -114,4 +88,48 @@ public class CombinedSpiralMover extends SpiralMover {
}; };
} }
@Override
public String getName() {
return "CombinedSpiralMover";
}
/**
* /**
* Check if the first object would be inbounds
*
* @param mover - the mover to check
* @return is mover always inbounds
*/
public boolean inBounds1(Mover mover) {
boolean ret = true;
int middle = halfTime - startTime;
for (int i = 1; ret && i < 15; i++) {
ret = checkBounds(mover.getPointAt(startTime + (middle * i) / 16));
//System.out.println("i: " + i + " = " + ret);
}
return ret;
}
/**
* /**
* Check if the second object would be inbounds
*
* @param mover - the mover to check
* @return is mover always inbounds
*/
private boolean inBounds2(Mover mover) {
boolean ret = true;
int middle = endTime - halfTime;
for (int i = 1; ret && i < 15; i++) {
ret = checkBounds(mover.getPointAt(startTime + (middle * i) / 16));
//System.out.println("i: " + i + " = " + ret);
}
return ret;
}
private boolean checkBounds(double[] pos) {
return 0 < pos[0] && pos[0] < Options.width && 0 < pos[1] && pos[1] < Options.height;
}
} }

View File

@ -1,55 +0,0 @@
package awlex.ospu.movers;
import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.objects.GameObject;
import org.newdawn.slick.util.pathfinding.Mover;
/**
* Created by Alex Wieser on 22.10.2016.
*/
abstract class SpiralMover extends yugecin.opsudance.movers.Mover {
protected double angle;
protected double radius;
int startTime;
int endTime;
SpiralMover(GameObject start, GameObject end, int dir) {
super(start, end, dir);
angle = Math.atan2(endY - startY, endX - startX);
radius = Utils.distance(startX, startY, endX, endY);
startTime = start.getEndTime();
endTime = end.getTime();
}
public double getAngle() {
return angle;
}
public double getRadius() {
return radius;
}
public int getDir() {
return dir;
}
public abstract boolean checkBounds();
@Override
public String getName() {
return getClass().getSimpleName();
}
/**
* checks if a point is in bounds
*
* @param pos x and y coordinations
* @return whether this point is within the screen
*/
boolean checkIfPointInBounds(double[] pos) {
return 0 < pos[0] && pos[0] < Options.width && 0 < pos[1] && pos[1] < Options.height;
}
}

View File

@ -1,24 +1,38 @@
package awlex.ospu.movers; package awlex.ospu.movers;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.objects.GameObject; import itdelatrisu.opsu.objects.GameObject;
import yugecin.opsudance.movers.Mover; import yugecin.opsudance.movers.Mover;
/** /**
* Created by Alex Wieser on 09.10.2016. * Created by Alex Wieser on 09.10.2016.
* WHO DO YOU THINK I AM? * WHO DO YOU THINK I AM?
* <p> *
* This {@link Mover} ends the spiral from the start object * This {@link Mover} ends the spiral from the start object
*/ */
public class SpiralToMover extends SpiralMover { public class SpiralToMover extends Mover {
/**
* How many times the cursor goes around the center
* For satisfying results this musn't be a multiple of 2
*/
private final int CIRCLENAVIGATIONS = 1;
double startAng;
double startRad;
public SpiralToMover(GameObject start, GameObject end, int dir) { public SpiralToMover(GameObject start, GameObject end, int dir) {
super(start, end, dir); super(start, end, dir);
startAng = Math.atan2(endY - startY, endX - startX) + Math.PI;
startRad = Utils.distance(startX, startY, endX, endY);
if (startRad < 20)
startRad = 20 + startRad / 20d;
} }
@Override @Override
public double[] getPointAt(int time) { public double[] getPointAt(int time) {
double rad = radius * (1 - getT(time)); double rad = startRad * (1 - getT(time));
double ang = angle + Math.PI + 2d * Math.PI * (1 - getT(time)) * dir; double ang = CIRCLENAVIGATIONS * (startAng + 2d * Math.PI * (1 - getT(time)) * dir);
return new double[]{ return new double[]{
endX + rad * Math.cos(ang), endX + rad * Math.cos(ang),
endY + rad * Math.sin(ang) endY + rad * Math.sin(ang)
@ -26,11 +40,7 @@ public class SpiralToMover extends SpiralMover {
} }
@Override @Override
public boolean checkBounds() { public String getName() {
boolean ret = true; return "Spiral2";
int totalTime = endTime - startTime;
for (int i = 0; ret && i <= 20; i++)
ret = checkIfPointInBounds(getPointAt((int) (startTime + totalTime * (1 - i / 20d))));
return ret;
} }
} }

View File

@ -8,14 +8,14 @@ import yugecin.opsudance.movers.factories.MoverFactory;
/** /**
* Created by Alex Wieser on 10.10.2016. * Created by Alex Wieser on 10.10.2016.
* Best With Only one direction (Left or Right)
*/ */
public class CenterSpiralMoverFactory implements MoverFactory { public class CenterSpiralMoverFactory implements MoverFactory {
private static FakeGameObject middle = new FakeGameObject(); private static FakeGameObject middle;
@Override @Override
public Mover create(GameObject start, GameObject end, int dir) { public Mover create(GameObject start, GameObject end, int dir) {
if (middle == null)
middle = new FakeGameObject();
middle.setTime(start.getEndTime() + (end.getTime() - start.getEndTime()) / 2); middle.setTime(start.getEndTime() + (end.getTime() - start.getEndTime()) / 2);
return new CombinedSpiralMover(middle, start, end, dir); return new CombinedSpiralMover(middle, start, end, dir);
} }

View File

@ -1,22 +0,0 @@
package awlex.ospu.movers.factories;
import awlex.ospu.movers.CombinedSpiralMover;
import itdelatrisu.opsu.objects.GameObject;
import yugecin.opsudance.movers.Mover;
import yugecin.opsudance.movers.factories.MoverFactory;
/**
* Created by Alex Wieser on 26.10.2016.
*/
public class CombinedSpiralMoverFactory implements MoverFactory {
@Override
public Mover create(GameObject start, GameObject end, int dir) {
return new CombinedSpiralMover(start, end, dir);
}
@Override
public String toString() {
return "Spiral even more";
}
}

View File

@ -33,8 +33,8 @@ public class SpiralSpinner extends Spinner {
private final double DELTA = -Math.PI / 20; private final double DELTA = -Math.PI / 20;
private int MAX_RAD; private int MAX_RAD;
private int index; private int index;
private double[][] points; double[][] points;
private boolean down; boolean down;
@Override @Override
public void init() { public void init() {
@ -65,6 +65,7 @@ public class SpiralSpinner extends Spinner {
@Override @Override
public double[] getPoint() { public double[] getPoint() {
//if (waitForDelay()) {
if (down) { if (down) {
if (--index == 0) if (--index == 0)
down = !down; down = !down;
@ -76,6 +77,7 @@ public class SpiralSpinner extends Spinner {
} else if (down && index == SIZE - 2) { } else if (down && index == SIZE - 2) {
rotatePointAroundCenter(points[SIZE - 1], DELTA); rotatePointAroundCenter(points[SIZE - 1], DELTA);
} }
//}
rotatePointAroundCenter(points[index], DELTA); rotatePointAroundCenter(points[index], DELTA);
return points[index]; return points[index];
} }