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> <artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version> <version>3.2</version>
<configuration> <configuration>
<source>1.7</source> <source>1.8</source>
<target>1.7</target> <target>1.8</target>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -2,18 +2,18 @@ package awlex.ospu.polymover.factory;
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 yugecin.opsudance.Dancer; 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.LinkedList;
import java.util.List; import java.util.List;
/** /**
* Created by Awlex on 18.11.2016. * Created by Awlex on 18.11.2016.
*/ */
public abstract class PolyMoverFactory { public abstract class PolyMoverFactory implements MoverFactory {
private LinkedList<PolyMover> movers; private LinkedList<PolyMover> movers;
private int latestIndex; private int latestIndex;
@ -42,6 +42,16 @@ public abstract class PolyMoverFactory {
return ret; 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) { public final void create(GameObject[] objects, int startIndex) {
if (latestIndex <= startIndex) { if (latestIndex <= startIndex) {
movers.clear(); 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), 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 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" ) { DANCE_MOVER ("Mover algorithm", "Mover", "Algorithm that decides how to move from note to note" ) {
@Override @Override
public Object[] getListItems() { public Object[] getListItems() {
return Dancer.multipoint ? Dancer.polyMoverFactories : Dancer.moverFactories; return Dancer.moverFactories;
} }
@Override @Override
public void clickListItem(int index) { public void clickListItem(int index) {
if (Dancer.multipoint) Dancer.instance.setMoverFactoryIndex(index);
Dancer.instance.setPolyMoverFactoryIndex(index);
else
Dancer.instance.setMoverFactoryIndex(index);
} }
@Override @Override
public String getValueString() { 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 @Override
public String write() { public String write() {
return String.valueOf(Dancer.multipoint ? Dancer.instance.getPolyMoverFactoryIndex() : Dancer.instance.getMoverFactoryIndex()); return String.valueOf(Dancer.instance.getMoverFactoryIndex());
} }
@Override @Override
public void read(String s) { public void read(String s) {
int i = Integer.parseInt(s); int i = Integer.parseInt(s);
if (Dancer.multipoint) Dancer.instance.setMoverFactoryIndex(i);
Dancer.instance.setPolyMoverFactoryIndex(i);
else
Dancer.instance.setMoverFactoryIndex(i);
} }
}, },

View File

@ -424,11 +424,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;
int lastObjectForDancer = beatmap.objects.length; if (objectIndex < beatmap.objects.length - Dancer.instance.getPolyMoverFactoryMinBufferSize()) {
if (Dancer.multipoint) {
lastObjectForDancer -= Dancer.polyMoverFactories[Dancer.instance.getPolyMoverFactoryIndex()].getMinBufferSize();
}
if (objectIndex < lastObjectForDancer) {
Dancer d = Dancer.instance; Dancer d = Dancer.instance;
d.update(trackPosition, objectIndex); d.update(trackPosition, objectIndex);
autoPoint = new Vec2f(d.x, d.y); autoPoint = new Vec2f(d.x, d.y);

View File

@ -112,7 +112,6 @@ public class OptionsMenu extends BasicGameState {
GameOption.ENABLE_WATCH_SERVICE GameOption.ENABLE_WATCH_SERVICE
}), }),
DANCE ("Dance", new GameOption[] { DANCE ("Dance", new GameOption[] {
GameOption.DANCE_MOVER_TYPE,
GameOption.DANCE_MOVER, GameOption.DANCE_MOVER,
GameOption.DANCE_MOVER_DIRECTION, GameOption.DANCE_MOVER_DIRECTION,
GameOption.DANCE_SLIDER_MOVER_TYPE, 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.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.LinearFactory;
import awlex.ospu.polymover.factory.PolyMoverFactory; import awlex.ospu.polymover.factory.PolyMoverFactory;
@ -52,6 +53,8 @@ public class Dancer {
new QuartCircleMoverFactory(), new QuartCircleMoverFactory(),
new SpiralMoverFactory(), new SpiralMoverFactory(),
new CenterSpiralMoverFactory(), new CenterSpiralMoverFactory(),
new LinearFactory(),
new ArcFactory(),
}; };
public static Spinner[] spinners = new Spinner[]{ public static Spinner[] spinners = new Spinner[]{
@ -73,11 +76,6 @@ public class Dancer {
new InheritedSliderMoverController(), new InheritedSliderMoverController(),
}; };
public static PolyMoverFactory[] polyMoverFactories = new PolyMoverFactory[]{
new LinearFactory(),
new ArcFactory()
};
public static Dancer instance = new Dancer(); public static Dancer instance = new Dancer();
public static boolean multipoint = false; public static boolean multipoint = false;
@ -104,13 +102,11 @@ public class Dancer {
private GameObject[] gameObjects; private GameObject[] gameObjects;
private MoverFactory moverFactory; private MoverFactory moverFactory;
private PolyMoverFactory polyMoverFactory;
private Mover mover; private Mover mover;
private Spinner spinner; private Spinner spinner;
public static SliderMoverController sliderMoverController; public static SliderMoverController sliderMoverController;
private int moverFactoryIndex; private int moverFactoryIndex;
private int polyMoverFactoryIndex;
private int spinnerIndex; private int spinnerIndex;
public float x; public float x;
@ -157,18 +153,14 @@ public class Dancer {
} }
this.moverFactoryIndex = moverFactoryIndex; this.moverFactoryIndex = moverFactoryIndex;
moverFactory = moverFactories[moverFactoryIndex]; moverFactory = moverFactories[moverFactoryIndex];
multipoint = moverFactory.isMultiPoint();
} }
public int getPolyMoverFactoryIndex() { public int getPolyMoverFactoryMinBufferSize() {
return polyMoverFactoryIndex; if (!multipoint) {
} return 0;
public void setPolyMoverFactoryIndex(int polyMoverFactoryIndex) {
if (polyMoverFactoryIndex < 0 || polyMoverFactoryIndex >= polyMoverFactories.length) {
polyMoverFactoryIndex = 0;
} }
this.polyMoverFactoryIndex = polyMoverFactoryIndex; return ((PolyMoverFactory) moverFactory).getMinBufferSize();
polyMoverFactory = polyMoverFactories[polyMoverFactoryIndex];
} }
public void setGameObjects(GameObject[] objs) { public void setGameObjects(GameObject[] objs) {
@ -215,10 +207,11 @@ public class Dancer {
} }
if (multipoint) { if (multipoint) {
if (polyMoverFactory.isInitialized() && polyMoverFactory.getLatestIndex() < objectIndex + polyMoverFactory.getLatestIndex() - 1) { PolyMoverFactory pmf = (PolyMoverFactory) moverFactory;
polyMoverFactory.update(gameObjects[objectIndex + polyMoverFactory.getMaxBufferSize() - 1]); if (pmf.isInitialized() && pmf.getLatestIndex() < objectIndex + pmf.getLatestIndex() - 1) {
pmf.update(gameObjects[objectIndex + pmf.getMaxBufferSize() - 1]);
} else { } else {
polyMoverFactory.create(gameObjects, objectIndex - 1); pmf.create(gameObjects, objectIndex - 1);
} }
} else if (mover == null || mover.getEnd() != c) { } else if (mover == null || mover.getEnd() != c) {
if (p == d) { if (p == d) {
@ -233,7 +226,7 @@ public class Dancer {
if (!p.isSpinner() || !c.isSpinner()) { if (!p.isSpinner() || !c.isSpinner()) {
double[] point; double[] point;
if (multipoint) { if (multipoint) {
point = polyMoverFactory.getPointAt(time); point = ((PolyMoverFactory) moverFactory).getPointAt(time);
} else { } else {
point = mover.getPointAt(time); point = mover.getPointAt(time);
} }

View File

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