Very minor formatting changes to #76.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-04-12 22:33:20 -04:00
parent a69f960e26
commit 5fcff76690
13 changed files with 61 additions and 62 deletions

View File

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

View File

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

View File

@ -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,8 +41,7 @@ public class CatmullCurve extends EqualDistanceMultiCurve{
super(hitObject, color);
LinkedList<CurveType> catmulls = new LinkedList<CurveType>();
int ncontrolPoints = hitObject.getSliderX().length + 1;
// temporary list of points to separate different curves
LinkedList<Vec2f> points = new LinkedList<Vec2f>();
LinkedList<Vec2f> points = new LinkedList<Vec2f>(); // temporary list of points to separate different curves
// repeat the first and last points as controls points
// aabb
@ -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);
}
}

View File

@ -18,30 +18,30 @@
package itdelatrisu.opsu.objects.curves;
import org.newdawn.slick.SlickException;
/**
* Representation of a Centripetal CatmullRom spline.
* (Currently not technically Centripetal CatmullRom.)
* http://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
*
* Currently not technically Centripetal CatmullRom
*
* @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]))
@ -82,5 +82,4 @@ public class CentripetalCatmullRom extends CurveType{
return C;
}
}

View File

@ -168,7 +168,6 @@ public class CircumscribedCircle extends Curve {
};
}
@Override
public float getEndAngle() { return drawEndAngle; }

View File

@ -31,8 +31,7 @@ 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. */
@ -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++)

View File

@ -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;
@ -45,9 +44,8 @@ public abstract class CurveType {
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; }
}

View File

@ -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<CurveType> curvesList){

View File

@ -19,6 +19,7 @@
package itdelatrisu.opsu.objects.curves;
import itdelatrisu.opsu.OsuHitObject;
import java.util.LinkedList;
import org.newdawn.slick.Color;
@ -30,11 +31,11 @@ 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);
@ -45,14 +46,13 @@ public class LinearBezier extends EqualDistanceMultiCurve {
// 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<Vec2f> points = new LinkedList<Vec2f>(); // 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();

View File

@ -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); }
}

View File

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