merge the movers into one list, use java8 for default impl in interfaces

This commit is contained in:
yugecin 2016-11-20 17:24:58 +01:00
parent b325b53e4f
commit cdd88d9a8d
7 changed files with 38 additions and 56 deletions

View File

@ -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>

View File

@ -2,18 +2,18 @@ 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 yugecin.opsudance.Dancer;
import yugecin.opsudance.movers.Mover;
import yugecin.opsudance.movers.factories.MoverFactory;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
/**
* Created by Awlex on 18.11.2016.
*/
public abstract class PolyMoverFactory {
public abstract class PolyMoverFactory implements MoverFactory {
private LinkedList<PolyMover> movers;
private int latestIndex;
@ -42,6 +42,16 @@ public abstract class PolyMoverFactory {
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();

View File

@ -595,51 +595,31 @@ 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 than 2 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.multipoint ? Dancer.polyMoverFactories : Dancer.moverFactories;
return Dancer.moverFactories;
}
@Override
public void clickListItem(int index) {
if (Dancer.multipoint)
Dancer.instance.setPolyMoverFactoryIndex(index);
else
Dancer.instance.setMoverFactoryIndex(index);
Dancer.instance.setMoverFactoryIndex(index);
}
@Override
public String getValueString() {
return Dancer.multipoint ? Dancer.polyMoverFactories[Dancer.instance.getPolyMoverFactoryIndex()].toString() : Dancer.moverFactories[Dancer.instance.getMoverFactoryIndex()].toString();
return Dancer.moverFactories[Dancer.instance.getMoverFactoryIndex()].toString();
}
@Override
public String write() {
return String.valueOf(Dancer.multipoint ? Dancer.instance.getPolyMoverFactoryIndex() : Dancer.instance.getMoverFactoryIndex());
return String.valueOf(Dancer.instance.getMoverFactoryIndex());
}
@Override
public void read(String s) {
int i = Integer.parseInt(s);
if (Dancer.multipoint)
Dancer.instance.setPolyMoverFactoryIndex(i);
else
Dancer.instance.setMoverFactoryIndex(i);
Dancer.instance.setMoverFactoryIndex(i);
}
},

View File

@ -424,11 +424,7 @@ public class Game extends BasicGameState {
autoMousePressed = false;
if (GameMod.AUTO.isActive() || GameMod.AUTOPILOT.isActive()) {
Vec2f autoPoint;
int lastObjectForDancer = beatmap.objects.length;
if (Dancer.multipoint) {
lastObjectForDancer -= Dancer.polyMoverFactories[Dancer.instance.getPolyMoverFactoryIndex()].getMinBufferSize();
}
if (objectIndex < lastObjectForDancer) {
if (objectIndex < beatmap.objects.length - Dancer.instance.getPolyMoverFactoryMinBufferSize()) {
Dancer d = Dancer.instance;
d.update(trackPosition, objectIndex);
autoPoint = new Vec2f(d.x, d.y);

View File

@ -112,7 +112,6 @@ 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,

View File

@ -19,6 +19,7 @@ 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;
@ -52,6 +53,8 @@ public class Dancer {
new QuartCircleMoverFactory(),
new SpiralMoverFactory(),
new CenterSpiralMoverFactory(),
new LinearFactory(),
new ArcFactory(),
};
public static Spinner[] spinners = new Spinner[]{
@ -73,11 +76,6 @@ public class Dancer {
new InheritedSliderMoverController(),
};
public static PolyMoverFactory[] polyMoverFactories = new PolyMoverFactory[]{
new LinearFactory(),
new ArcFactory()
};
public static Dancer instance = new Dancer();
public static boolean multipoint = false;
@ -104,13 +102,11 @@ public class Dancer {
private GameObject[] gameObjects;
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;
@ -157,18 +153,14 @@ public class Dancer {
}
this.moverFactoryIndex = moverFactoryIndex;
moverFactory = moverFactories[moverFactoryIndex];
multipoint = moverFactory.isMultiPoint();
}
public int getPolyMoverFactoryIndex() {
return polyMoverFactoryIndex;
}
public void setPolyMoverFactoryIndex(int polyMoverFactoryIndex) {
if (polyMoverFactoryIndex < 0 || polyMoverFactoryIndex >= polyMoverFactories.length) {
polyMoverFactoryIndex = 0;
public int getPolyMoverFactoryMinBufferSize() {
if (!multipoint) {
return 0;
}
this.polyMoverFactoryIndex = polyMoverFactoryIndex;
polyMoverFactory = polyMoverFactories[polyMoverFactoryIndex];
return ((PolyMoverFactory) moverFactory).getMinBufferSize();
}
public void setGameObjects(GameObject[] objs) {
@ -215,10 +207,11 @@ public class Dancer {
}
if (multipoint) {
if (polyMoverFactory.isInitialized() && polyMoverFactory.getLatestIndex() < objectIndex + polyMoverFactory.getLatestIndex() - 1) {
polyMoverFactory.update(gameObjects[objectIndex + polyMoverFactory.getMaxBufferSize() - 1]);
PolyMoverFactory pmf = (PolyMoverFactory) moverFactory;
if (pmf.isInitialized() && pmf.getLatestIndex() < objectIndex + pmf.getLatestIndex() - 1) {
pmf.update(gameObjects[objectIndex + pmf.getMaxBufferSize() - 1]);
} else {
polyMoverFactory.create(gameObjects, objectIndex - 1);
pmf.create(gameObjects, objectIndex - 1);
}
} else if (mover == null || mover.getEnd() != c) {
if (p == d) {
@ -233,7 +226,7 @@ public class Dancer {
if (!p.isSpinner() || !c.isSpinner()) {
double[] point;
if (multipoint) {
point = polyMoverFactory.getPointAt(time);
point = ((PolyMoverFactory) moverFactory).getPointAt(time);
} else {
point = mover.getPointAt(time);
}

View File

@ -24,4 +24,8 @@ public interface MoverFactory {
Mover create(GameObject start, GameObject end, int dir);
default boolean isMultiPoint() {
return false;
}
}