Skip to content

Commit

Permalink
Follow-up to #263.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Mar 9, 2017
1 parent 959f46c commit cf51a3a
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 203 deletions.
21 changes: 10 additions & 11 deletions src/itdelatrisu/opsu/GameData.java
Original file line number Diff line number Diff line change
Expand Up @@ -1088,33 +1088,31 @@ else if (Options.isHitLightingEnabled() && !hitResult.hideResult && hitResult.re
*/
private void drawHitAnimations(HitObjectResult hitResult, int trackPosition) {
// fade out slider curve
if (hitResult.result != HIT_SLIDER_REPEAT && hitResult.curve != null && !(Options.isExperimentalSliderStyle() && Options.isShrinkingSliders())) {
if (hitResult.result != HIT_SLIDER_REPEAT && hitResult.curve != null &&
!(Options.isExperimentalSliderStyle() && Options.isExperimentalSliderShrinking())) {
float progress = AnimationEquation.OUT_CUBIC.calc(
(float) Utils.clamp(trackPosition - hitResult.time, 0, HITCIRCLE_FADE_TIME) / HITCIRCLE_FADE_TIME);
float alpha = 1f - progress;
float oldWhiteAlpha = Colors.WHITE_FADE.a;
float oldColorAlpha = hitResult.color.a;
Colors.WHITE_FADE.a = hitResult.color.a = alpha;
if (Options.isExperimentalSliderStyle()) {
hitResult.curve.draw(hitResult.color, Options.isMergingSliders() ? 1 : 0, hitResult.curve.getCurvePoints().length);
} else {
if (Options.isExperimentalSliderStyle())
hitResult.curve.draw(hitResult.color, Options.isExperimentalSliderMerging() ? 1 : 0, hitResult.curve.getCurvePoints().length);
else
hitResult.curve.draw(hitResult.color);
}
Colors.WHITE_FADE.a = oldWhiteAlpha;
hitResult.color.a = oldColorAlpha;
}

// miss, don't draw an animation
if (hitResult.result == HIT_MISS) {
if (hitResult.result == HIT_MISS)
return;
}

// not a circle?
if (hitResult.hitResultType != HitObjectType.CIRCLE &&
hitResult.hitResultType != HitObjectType.SLIDER_FIRST &&
hitResult.hitResultType != HitObjectType.SLIDER_LAST) {
hitResult.hitResultType != HitObjectType.SLIDER_LAST)
return;
}

// slider follow circle
if (hitResult.expand && hitResult.result != HIT_SLIDER_REPEAT && (
Expand All @@ -1129,9 +1127,10 @@ private void drawHitAnimations(HitObjectResult hitResult, int trackPosition) {
fc.drawCentered(hitResult.x, hitResult.y);
}

if (hitResult.result != HIT_SLIDER_REPEAT && hitResult.curve != null && !Options.isDrawSliderEndCircles()) {
// hide end circles?
if (Options.isExperimentalSliderStyle() && !Options.isExperimentalSliderCapsDrawn() &&
hitResult.result != HIT_SLIDER_REPEAT && hitResult.curve != null)
return;
}

// hit circles
float progress = AnimationEquation.OUT_CUBIC.calc(
Expand Down
2 changes: 1 addition & 1 deletion src/itdelatrisu/opsu/GameImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected Image process_sub(Image img, int w, int h) {

// Slider
SLIDER_GRADIENT ("slidergradient", "png"),
SLIDER_GRADIENT_EX ("slidergradient_ex", "png"),
SLIDER_GRADIENT_EXPERIMENTAL ("slidergradient_ex", "png"),
SLIDER_BALL ("sliderb", "sliderb%d", "png"),
SLIDER_FOLLOWCIRCLE ("sliderfollowcircle", "png"),
REVERSEARROW ("reversearrow", "png"),
Expand Down
13 changes: 0 additions & 13 deletions src/itdelatrisu/opsu/beatmap/HitObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,6 @@ else if ((type & HitObject.TYPE_SLIDER) > 0) {
}
}

/**
* Constructor to make fake/temp hitobj
* @param x xpos
* @param y ypos
* @param time time
*/
public HitObject( float x, float y, int time) {
this.x = x;
this.y = y;
this.time = time;
this.type = HitObject.TYPE_CIRCLE;
}

/**
* Returns the raw starting x coordinate.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/itdelatrisu/opsu/objects/Circle.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
public class Circle implements GameObject {
/** The diameter of hit circles. */
public static float diameter;
private static float diameter;

/** The associated HitObject. */
private HitObject hitObject;
Expand Down
83 changes: 49 additions & 34 deletions src/itdelatrisu/opsu/objects/Slider.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,12 @@ public class Slider implements GameObject {
/** The animation progress for the release of the follow circle. */
private AnimatedValue releaseExpand = new AnimatedValue(100, 0f, 1f, AnimationEquation.IN_QUAD);

/** Container dimensions. */
private static int containerWidth, containerHeight;

/** Curve color for experimental style sliders. */
private static Color curveColor = new Color(0, 0, 0, 20);

/** Start index of this slider in the merged slider. */
public int baseSliderFrom;

/** Container dimensions. */
private static int containerWidth, containerHeight;

/**
* Initializes the Slider data type with images and dimensions.
* @param container the game container
Expand Down Expand Up @@ -223,13 +220,13 @@ public void draw(Graphics g, int trackPosition) {
isCurveCompletelyDrawn = Options.isSliderSnaking() || alpha == 1f;
curve.draw(color, isCurveCompletelyDrawn ? 1f : alpha);
} else {
curveColor.a = sliderAlpha;
isCurveCompletelyDrawn = drawSliderTrack(trackPosition, Utils.clamp(1d - (double) (timeDiff - approachTime + fadeInTime) / fadeInTime, 0d, 1d));
isCurveCompletelyDrawn = drawExperimentalSliderTrack(trackPosition, Utils.clamp(1d - (double) (timeDiff - approachTime + fadeInTime) / fadeInTime, 0d, 1d), sliderAlpha);
color.a = alpha;
}

// end circle (only draw if ball still has to go there)
if (isCurveCompletelyDrawn && (!Options.isExperimentalSliderStyle() || Options.isDrawSliderEndCircles()) && currentRepeats < repeatCount - (repeatCount % 2 == 0 ? 1 : 0)) {
if (isCurveCompletelyDrawn && currentRepeats < repeatCount - (repeatCount % 2 == 0 ? 1 : 0) &&
(!Options.isExperimentalSliderStyle() || Options.isExperimentalSliderCapsDrawn())) {
Color circleColor = new Color(color);
Color overlayColor = new Color(Colors.WHITE_FADE);
if (currentRepeats == 0) {
Expand Down Expand Up @@ -295,10 +292,8 @@ public void draw(Graphics g, int trackPosition) {
Image arrow = GameImage.REVERSEARROW.getImage();
// bouncing animation
//arrow = arrow.getScaledCopy((float) (1 + 0.2d * ((trackPosition + sliderTime * tcurRepeat) % 292) / 292));
Color arrowColor = Color.white;
if (!Options.isExperimentalSliderStyle() && Utils.getLuminance(color) >= 0.8f) {
arrowColor = Color.black;
}
Color arrowColor = (Utils.getLuminance(color) < 0.8f || Options.isExperimentalSliderStyle()) ?
Color.white : Color.black;
if (tcurRepeat == 0) {
arrow.setAlpha(Options.isSliderSnaking() ? decorationsAlpha : 1f);
} else {
Expand Down Expand Up @@ -423,37 +418,55 @@ private void drawSliderTicks(int trackPosition, float curveAlpha, float decorati

/**
* Draws the slider track for the experimental style sliders.
* @param trackPosition position of the song
* @param snakingSliderProgress progress of the snaking sliders [0, 1]
* @param trackPosition the current track position
* @param snakingSliderProgress the progress of the snaking sliders [0,1]
* @param sliderAlpha the slider alpha level
* @return true if the track was completely drawn
*/
private boolean drawSliderTrack(int trackPosition, double snakingSliderProgress) {
private boolean drawExperimentalSliderTrack(int trackPosition, double snakingSliderProgress, float sliderAlpha) {
double curveIntervalTo = Options.isSliderSnaking() ? snakingSliderProgress : 1d;
double curveIntervalFrom = 0d;
if (Options.isShrinkingSliders()) {
double sliderprogress = (trackPosition - hitObject.getTime() - ((double) sliderTime * (hitObject.getRepeatCount() - 1))) / (double) sliderTime;
if (sliderprogress > 0) {
curveIntervalFrom = sliderprogress;
}
if (Options.isExperimentalSliderShrinking()) {
double sliderProgress = (trackPosition - hitObject.getTime() - ((double) sliderTime * (hitObject.getRepeatCount() - 1))) / sliderTime;
if (sliderProgress > 0)
curveIntervalFrom = sliderProgress;
}
int curvelen = curve.getCurvePoints().length;
if (Options.isMergingSliders()) {
if (Options.isShrinkingSliders() && curveIntervalFrom > 0) {
int curveLength = curve.getCurvePoints().length;

// merging sliders
if (Options.isExperimentalSliderMerging()) {
if (Options.isExperimentalSliderShrinking() && curveIntervalFrom > 0) {
if (hitObject.getRepeatCount() % 2 == 0) {
game.addMergedSliderPointsToRender(baseSliderFrom, baseSliderFrom + (int) ((1d - curveIntervalFrom) * curvelen));
game.addMergedSliderPointsToRender(
baseSliderFrom,
baseSliderFrom + (int) ((1d - curveIntervalFrom) * curveLength)
);
} else {
game.addMergedSliderPointsToRender(baseSliderFrom + (int) (curveIntervalFrom * curvelen) + 1, baseSliderFrom + (int) (curveIntervalTo * curve.getCurvePoints().length));
game.addMergedSliderPointsToRender(
baseSliderFrom + (int) (curveIntervalFrom * curveLength) + 1,
baseSliderFrom + (int) (curveIntervalTo * curve.getCurvePoints().length)
);
}
} else {
game.addMergedSliderPointsToRender(baseSliderFrom, baseSliderFrom + (int) (curveIntervalTo * curve.getCurvePoints().length));
game.addMergedSliderPointsToRender(
baseSliderFrom,
baseSliderFrom + (int) (curveIntervalTo * curve.getCurvePoints().length)
);
}
} else {
if (Options.isShrinkingSliders() && curveIntervalFrom > 0 && hitObject.getRepeatCount() % 2 == 0) {
curve.splice((int) ((1d - curveIntervalFrom) * curvelen), curvelen);
}

// non-merging sliders
else {
if (Options.isExperimentalSliderShrinking() && curveIntervalFrom > 0 && hitObject.getRepeatCount() % 2 == 0) {
curve.splice((int) ((1d - curveIntervalFrom) * curveLength), curveLength);
curveIntervalFrom = 0d;
}
curve.draw(curveColor, (int) (curveIntervalFrom * curvelen), (int) (curveIntervalTo * curvelen));
float oldBlackAlpha = Colors.BLACK_ALPHA.a;
Colors.BLACK_ALPHA.a = sliderAlpha;
curve.draw(Colors.BLACK_ALPHA, (int) (curveIntervalFrom * curveLength), (int) (curveIntervalTo * curveLength));
Colors.BLACK_ALPHA.a = oldBlackAlpha;
}

return curveIntervalTo == 1d;
}

Expand Down Expand Up @@ -758,6 +771,7 @@ else if (GameMod.RELAX.isActive() && trackPosition >= time)

// calculate and send slider result
hitResult();

return true;
}

Expand Down Expand Up @@ -803,9 +817,10 @@ private float getT(int trackPosition, boolean raw) {
}
}

public Curve getCurve() {
return curve;
}
/**
* Returns the underlying curve.
*/
public Curve getCurve() { return curve; }

@Override
public void reset() {
Expand Down
25 changes: 14 additions & 11 deletions src/itdelatrisu/opsu/objects/curves/Curve.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ public abstract class Curve {
/** Points along the curve (set by inherited classes). */
protected Vec2f[] curve;

/**
* Get the curve points
* @return curve points
*/
public Vec2f[] getCurvePoints() {
return curve;
}

/**
* Constructor.
* @param hitObject the associated HitObject
Expand Down Expand Up @@ -117,6 +109,11 @@ public static void init(int width, int height, float circleDiameter, Color borde
}
}

/**
* Returns the points along the curve.
*/
public Vec2f[] getCurvePoints() { return curve; }

/**
* Returns the point on the curve at a value t.
* @param t the t value [0, 1]
Expand Down Expand Up @@ -160,6 +157,12 @@ public void draw(Color color, float t) {
}
}

/**
* Draws a section of the curve to the graphics context.
* @param color the color filter
* @param from the start index to draw from
* @param to end the index to draw to (exclusive)
*/
public void draw(Color color, int from, int to) {
if (curve == null)
return;
Expand All @@ -169,9 +172,9 @@ public void draw(Color color, int from, int to) {
}

/**
* Splice the curve to draw (= flag a part of it as 'do not draw'). Bases on the curve point indices.
* @param from start index to splice
* @param to end index to splice
* Splices a section of the curve for drawing, based on the given curve point indices.
* @param from the start index to splice
* @param to the end index to splice
*/
public void splice(int from, int to) {
if (legacyRenderState == null)
Expand Down
43 changes: 25 additions & 18 deletions src/itdelatrisu/opsu/objects/curves/FakeCombinedCurve.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,43 @@
* You should have received a copy of the GNU General Public License
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
*/

package itdelatrisu.opsu.objects.curves;

import itdelatrisu.opsu.beatmap.HitObject;
import itdelatrisu.opsu.render.LegacyCurveRenderState;
import org.newdawn.slick.Color;

import java.util.ArrayList;
import java.util.List;

public class FakeCombinedCurve extends Curve {
import org.newdawn.slick.Color;

private List<Integer> pointsToRender;
/**
* Combined curve (for merging sliders).
*
* @author yugecin (https://github.com/yugecin)
*/
public class FakeCombinedCurve extends Curve {
/** The current points to render (pairs of indices: from, to). */
private List<Integer> pointsToRender = new ArrayList<Integer>();

/**
* Constructor.
* @param points the list of curve points
*/
public FakeCombinedCurve(Vec2f[] points) {
super(new HitObject(0, 0, 0), false);
super(new HitObject("0,0,0,1,2"), false);
this.curve = points;
pointsToRender = new ArrayList<>();
}

public void initForFrame() {
pointsToRender.clear();
}
/** Clears the list of points to render. */
public void clearPoints() { pointsToRender.clear(); }

/**
* Adds a range of points to render.
* @param from the start index to render
* @param to the end point index to render
*/
public void addRange(int from, int to) {
pointsToRender.add(from);
pointsToRender.add(to);
Expand All @@ -51,18 +65,11 @@ public void draw(Color color) {
}

@Override
public Vec2f pointAt(float t) {
return null;
}
public Vec2f pointAt(float t) { return null; }

@Override
public float getEndAngle() {
return 0;
}
public float getEndAngle() { return 0; }

@Override
public float getStartAngle() {
return 0;
}

public float getStartAngle() { return 0; }
}
2 changes: 1 addition & 1 deletion src/itdelatrisu/opsu/options/OptionGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class OptionGroup {
GameOption.EXPERIMENTAL_SLIDERS,
GameOption.EXPERIMENTAL_SLIDERS_MERGE,
GameOption.EXPERIMENTAL_SLIDERS_SHRINK,
GameOption.EXPERIMENTAL_SLIDERS_DRAW_ENDCIRCLES,
GameOption.EXPERIMENTAL_SLIDERS_CAPS,
}),
new OptionGroup("MAIN MENU", new GameOption[] {
GameOption.DYNAMIC_BACKGROUND,
Expand Down
Loading

0 comments on commit cf51a3a

Please sign in to comment.