diff --git a/src/itdelatrisu/opsu/Utils.java b/src/itdelatrisu/opsu/Utils.java index 62397428..7035825e 100644 --- a/src/itdelatrisu/opsu/Utils.java +++ b/src/itdelatrisu/opsu/Utils.java @@ -619,7 +619,7 @@ public class Utils { public static float easeOut(float t, float a, float b, float d) { return b * ((t = t / d - 1f) * t * t + 1f) + a; } - + /** * Fake bounce ease function. * @param t the current time diff --git a/src/itdelatrisu/opsu/audio/SoundController.java b/src/itdelatrisu/opsu/audio/SoundController.java index 96c5df26..20eb82b4 100644 --- a/src/itdelatrisu/opsu/audio/SoundController.java +++ b/src/itdelatrisu/opsu/audio/SoundController.java @@ -164,7 +164,7 @@ public class SoundController { } if (bestIndex >= 0) return new MultiClip(ref, AudioSystem.getAudioInputStream(formats[bestIndex], audioIn)); - + // still couldn't find anything, try the default clip format return new MultiClip(ref, AudioSystem.getAudioInputStream(clip.getFormat(), audioIn)); } diff --git a/src/itdelatrisu/opsu/objects/Slider.java b/src/itdelatrisu/opsu/objects/Slider.java index 19740c77..57f39643 100644 --- a/src/itdelatrisu/opsu/objects/Slider.java +++ b/src/itdelatrisu/opsu/objects/Slider.java @@ -460,7 +460,7 @@ public class Slider implements HitObject { if (hitObject.getSliderType() == OsuHitObject.SLIDER_PASSTHROUGH && hitObject.getSliderX().length == 2) this.curve = new CircumscribedCircle(hitObject, color); - else if ( hitObject.getSliderType() == OsuHitObject.SLIDER_CATMULL) + else if (hitObject.getSliderType() == OsuHitObject.SLIDER_CATMULL) this.curve = new CatmullCurve(hitObject, color); else this.curve = new LinearBezier(hitObject, color, hitObject.getSliderType() == OsuHitObject.SLIDER_LINEAR); diff --git a/src/itdelatrisu/opsu/objects/curves/Bezier2.java b/src/itdelatrisu/opsu/objects/curves/Bezier2.java index fa02b542..df0a5e09 100644 --- a/src/itdelatrisu/opsu/objects/curves/Bezier2.java +++ b/src/itdelatrisu/opsu/objects/curves/Bezier2.java @@ -23,7 +23,7 @@ package itdelatrisu.opsu.objects.curves; * * @author fluddokt (https://github.com/fluddokt) */ -public class Bezier2 extends CurveType{ +public class Bezier2 extends CurveType { /** The control points of the Bezier curve. */ private Vec2f[] points; @@ -55,12 +55,11 @@ public class Bezier2 extends CurveType{ return c; } - /** * Calculates the binomial coefficient. * http://en.wikipedia.org/wiki/Binomial_coefficient#Binomial_coefficient_in_programming_languages */ - public static long binomialCoefficient(int n, int k) { + private static long binomialCoefficient(int n, int k) { if (k < 0 || k > n) return 0; if (k == 0 || k == n) diff --git a/src/itdelatrisu/opsu/objects/curves/CatmullCurve.java b/src/itdelatrisu/opsu/objects/curves/CatmullCurve.java index 262906f5..07f78d67 100644 --- a/src/itdelatrisu/opsu/objects/curves/CatmullCurve.java +++ b/src/itdelatrisu/opsu/objects/curves/CatmullCurve.java @@ -18,19 +18,20 @@ package itdelatrisu.opsu.objects.curves; -import java.util.LinkedList; - +import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.OsuHitObject; +import java.util.LinkedList; + import org.newdawn.slick.Color; +import org.newdawn.slick.SlickException; /** * Representation of Catmull Curve with equidistant points. * * @author fluddokt (https://github.com/fluddokt) */ -public class CatmullCurve extends EqualDistanceMultiCurve{ - +public class CatmullCurve extends EqualDistanceMultiCurve { /** * Constructor. * @param hitObject the associated OsuHitObject @@ -40,9 +41,8 @@ public class CatmullCurve extends EqualDistanceMultiCurve{ super(hitObject, color); LinkedList catmulls = new LinkedList(); int ncontrolPoints = hitObject.getSliderX().length + 1; - // temporary list of points to separate different curves - LinkedList points = new LinkedList(); - + LinkedList points = new LinkedList(); // temporary list of points to separate different curves + // repeat the first and last points as controls points // aabb // aabc abcc @@ -51,14 +51,23 @@ public class CatmullCurve extends EqualDistanceMultiCurve{ for (int i = 0; i < ncontrolPoints; i++) { points.addLast(new Vec2f(getX(i), getY(i))); if (points.size() >= 4) { - catmulls.add(new CentripetalCatmullRom(points.toArray(new Vec2f[0]))); + try { + catmulls.add(new CentripetalCatmullRom(points.toArray(new Vec2f[0]))); + } catch (SlickException e) { + ErrorHandler.error(null, e, true); + } points.removeFirst(); } } - points.addLast(new Vec2f(getX(ncontrolPoints - 1),getY(ncontrolPoints - 1))); + points.addLast(new Vec2f(getX(ncontrolPoints - 1), getY(ncontrolPoints - 1))); if (points.size() >= 4) { - catmulls.add(new CentripetalCatmullRom(points.toArray(new Vec2f[0]))); + try { + catmulls.add(new CentripetalCatmullRom(points.toArray(new Vec2f[0]))); + } catch (SlickException e) { + ErrorHandler.error(null, e, true); + } } + init(catmulls); } } diff --git a/src/itdelatrisu/opsu/objects/curves/CentripetalCatmullRom.java b/src/itdelatrisu/opsu/objects/curves/CentripetalCatmullRom.java index 283dab2b..5a13d7ce 100644 --- a/src/itdelatrisu/opsu/objects/curves/CentripetalCatmullRom.java +++ b/src/itdelatrisu/opsu/objects/curves/CentripetalCatmullRom.java @@ -18,30 +18,30 @@ package itdelatrisu.opsu.objects.curves; +import org.newdawn.slick.SlickException; + /** * Representation of a Centripetal Catmull–Rom spline. + * (Currently not technically Centripetal Catmull–Rom.) * http://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline - * - * Currently not technically Centripetal Catmull–Rom - * + * * @author fluddokt (https://github.com/fluddokt) */ -public class CentripetalCatmullRom extends CurveType{ - +public class CentripetalCatmullRom extends CurveType { /** The time values of the Catmull curve. */ - float [] time; - + private float [] time; + /** The control points of the Catmull curve. */ - Vec2f[] points; - + private Vec2f[] points; + /** * Constructor. - * @param hitObject the associated OsuHitObject - * @param color the color of this curve + * @param points the control points of the curve + * @throws SlickException */ - protected CentripetalCatmullRom(Vec2f[] points) { + protected CentripetalCatmullRom(Vec2f[] points) throws SlickException { if (points.length != 4) - throw new Error("need exactly 4 points"); + throw new SlickException(String.format("Need exactly 4 points to initialize CentripetalCatmullRom, %d provided.", points.length)); this.points = points; time = new float[4]; @@ -57,12 +57,12 @@ public class CentripetalCatmullRom extends CurveType{ // time[i] = (float) Math.sqrt(len) + time[i-1];// ^(0.5) time[i] = i; } + init(approxLength / 2); } - @Override - public Vec2f pointAt(float t){ + public Vec2f pointAt(float t) { t = t * (time[2] - time[1]) + time[1]; Vec2f A1 = points[0].cpy().scale((time[1] - t) / (time[1] - time[0])) @@ -79,8 +79,7 @@ public class CentripetalCatmullRom extends CurveType{ Vec2f C = B1.cpy().scale((time[2] - t) / (time[2] - time[1])) .add(B2.cpy().scale((t - time[1]) / (time[2] - time[1]))); - + return C; } - } diff --git a/src/itdelatrisu/opsu/objects/curves/CircumscribedCircle.java b/src/itdelatrisu/opsu/objects/curves/CircumscribedCircle.java index 0e334634..0150d145 100644 --- a/src/itdelatrisu/opsu/objects/curves/CircumscribedCircle.java +++ b/src/itdelatrisu/opsu/objects/curves/CircumscribedCircle.java @@ -168,7 +168,6 @@ public class CircumscribedCircle extends Curve { }; } - @Override public float getEndAngle() { return drawEndAngle; } diff --git a/src/itdelatrisu/opsu/objects/curves/Curve.java b/src/itdelatrisu/opsu/objects/curves/Curve.java index 354c0135..3392ef62 100644 --- a/src/itdelatrisu/opsu/objects/curves/Curve.java +++ b/src/itdelatrisu/opsu/objects/curves/Curve.java @@ -31,10 +31,9 @@ import org.newdawn.slick.Image; * @author fluddokt (https://github.com/fluddokt) */ public abstract class Curve { - - /** Points generated along the curve should be spaced this much apart*/ + /** Points generated along the curve should be spaced this far apart. */ protected static float CURVE_POINTS_SEPERATION = 5; - + /** The associated OsuHitObject. */ protected OsuHitObject hitObject; @@ -44,7 +43,7 @@ public abstract class Curve { /** The scaled slider x, y coordinate lists. */ protected float[] sliderX, sliderY; - /** Points along the curve. To be set be inherited classes*/ + /** Points along the curve (set by inherited classes). */ protected Vec2f[] curve; /** @@ -72,9 +71,9 @@ public abstract class Curve { * @param color the color filter */ public void draw(Color color) { - if (curve == null){ + if (curve == null) return; - } + Image hitCircle = GameImage.HITCIRCLE.getImage(); Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage(); for (int i = 0; i < curve.length; i++) diff --git a/src/itdelatrisu/opsu/objects/curves/CurveType.java b/src/itdelatrisu/opsu/objects/curves/CurveType.java index b1986ac1..c6cec272 100644 --- a/src/itdelatrisu/opsu/objects/curves/CurveType.java +++ b/src/itdelatrisu/opsu/objects/curves/CurveType.java @@ -24,7 +24,6 @@ package itdelatrisu.opsu.objects.curves; * @author fluddokt (https://github.com/fluddokt) */ public abstract class CurveType { - /** Points along the curve of the Bezier curve. */ private Vec2f[] curve; @@ -43,11 +42,10 @@ public abstract class CurveType { * @return the point [x, y] */ public abstract Vec2f pointAt(float t); - + /** - * Initialize the curve points and distance - * Must be called by inherited classes - * + * Initialize the curve points and distance. + * Must be called by inherited classes. * @param approxlength an approximate length of the curve */ public void init(float approxlength) { @@ -65,6 +63,7 @@ public abstract class CurveType { totalDistance += curveDis[i]; } } + /** * Returns the points along the curve of the Bezier curve. */ @@ -84,5 +83,4 @@ public abstract class CurveType { * Returns the total distances of this Bezier curve. */ public float totalDistance() { return totalDistance; } - } diff --git a/src/itdelatrisu/opsu/objects/curves/EqualDistanceMultiCurve.java b/src/itdelatrisu/opsu/objects/curves/EqualDistanceMultiCurve.java index f1959ffb..5f19e9b4 100644 --- a/src/itdelatrisu/opsu/objects/curves/EqualDistanceMultiCurve.java +++ b/src/itdelatrisu/opsu/objects/curves/EqualDistanceMultiCurve.java @@ -45,13 +45,11 @@ public abstract class EqualDistanceMultiCurve extends Curve { */ public EqualDistanceMultiCurve(OsuHitObject hitObject, Color color) { super(hitObject, color); - } /** - * Initialize the curve points with equal distance - * Must be called by inherited classes - * + * Initialize the curve points with equal distance. + * Must be called by inherited classes. * @param curvesList a list of curves to join */ public void init(LinkedList curvesList){ @@ -116,7 +114,7 @@ public abstract class EqualDistanceMultiCurve extends Curve { this.endAngle = (float) (Math.atan2(c2.y - c1.y, c2.x - c1.x) * 180 / Math.PI); // } } - + @Override public float[] pointAt(float t) { float indexF = t * ncurve; diff --git a/src/itdelatrisu/opsu/objects/curves/LinearBezier.java b/src/itdelatrisu/opsu/objects/curves/LinearBezier.java index 5d2e7a5c..80b1b668 100644 --- a/src/itdelatrisu/opsu/objects/curves/LinearBezier.java +++ b/src/itdelatrisu/opsu/objects/curves/LinearBezier.java @@ -19,6 +19,7 @@ package itdelatrisu.opsu.objects.curves; import itdelatrisu.opsu.OsuHitObject; + import java.util.LinkedList; import org.newdawn.slick.Color; @@ -30,29 +31,28 @@ import org.newdawn.slick.Color; * @author fluddokt (https://github.com/fluddokt) */ public class LinearBezier extends EqualDistanceMultiCurve { - /** * Constructor. * @param hitObject the associated OsuHitObject * @param color the color of this curve + * @param line whether a new curve should be generated for each sequential pair */ public LinearBezier(OsuHitObject hitObject, Color color, boolean line) { super(hitObject, color); LinkedList beziers = new LinkedList(); - + // Beziers: splits points into different Beziers if has the same points (red points) // a b c - c d - d e f g // Lines: generate a new curve for each sequential pair // ab bc cd de ef fg - int controlPoints = hitObject.getSliderX().length + 1; LinkedList points = new LinkedList(); // temporary list of points to separate different Bezier curves Vec2f lastPoi = null; for (int i = 0; i < controlPoints; i++) { Vec2f tpoi = new Vec2f(getX(i), getY(i)); if (line) { - if(lastPoi != null) { + if (lastPoi != null) { points.add(tpoi); beziers.add(new Bezier2(points.toArray(new Vec2f[0]))); points.clear(); @@ -72,7 +72,7 @@ public class LinearBezier extends EqualDistanceMultiCurve { beziers.add(new Bezier2(points.toArray(new Vec2f[0]))); points.clear(); } - + init(beziers); } } diff --git a/src/itdelatrisu/opsu/objects/curves/Vec2f.java b/src/itdelatrisu/opsu/objects/curves/Vec2f.java index b857ad33..1005cd1d 100644 --- a/src/itdelatrisu/opsu/objects/curves/Vec2f.java +++ b/src/itdelatrisu/opsu/objects/curves/Vec2f.java @@ -70,7 +70,7 @@ public class Vec2f { y += o.y; return this; } - + /** * Subtracts a vector from this vector. * @param o the other vector @@ -120,7 +120,6 @@ public class Vec2f { */ public boolean equals(Vec2f o) { return (x == o.x && y == o.y); } - public String toString(){ - return "Vec2f:"+x+" "+y; - } + @Override + public String toString() { return String.format("(%.3f, %.3f)", x, y); } } diff --git a/src/itdelatrisu/opsu/states/Game.java b/src/itdelatrisu/opsu/states/Game.java index cede90d4..72674b13 100644 --- a/src/itdelatrisu/opsu/states/Game.java +++ b/src/itdelatrisu/opsu/states/Game.java @@ -1044,8 +1044,6 @@ public class Game extends BasicGameState { resetGameData(); // load the first timingPoint for stacking - timingPointIndex = 0; - beatLengthBase = beatLength = 1; if (!osu.timingPoints.isEmpty()) { OsuTimingPoint timingPoint = osu.timingPoints.get(0); if (!timingPoint.isInherited()) { @@ -1053,6 +1051,7 @@ public class Game extends BasicGameState { timingPointIndex++; } } + // initialize object maps for (int i = 0; i < osu.objects.length; i++) { OsuHitObject hitObject = osu.objects[i];