2015-01-30 02:36:23 +01:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
|
|
|
* Copyright (C) 2014, 2015 Jeffrey Han
|
|
|
|
*
|
|
|
|
* opsu! is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu! is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2015-04-12 16:25:03 +02:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
2015-06-08 21:02:28 +02:00
|
|
|
import itdelatrisu.opsu.Options;
|
2015-04-12 16:25:03 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
2015-05-17 03:42:03 +02:00
|
|
|
import itdelatrisu.opsu.beatmap.HitObject;
|
2015-06-08 21:02:28 +02:00
|
|
|
import itdelatrisu.opsu.render.CurveRenderState;
|
|
|
|
import itdelatrisu.opsu.skins.Skin;
|
2015-01-30 02:36:23 +01:00
|
|
|
|
2015-06-22 04:32:00 +02:00
|
|
|
import org.lwjgl.opengl.ContextCapabilities;
|
2015-06-08 21:02:28 +02:00
|
|
|
import org.lwjgl.opengl.GLContext;
|
2015-01-30 02:36:23 +01:00
|
|
|
import org.newdawn.slick.Color;
|
2015-04-12 16:25:03 +02:00
|
|
|
import org.newdawn.slick.Image;
|
2015-03-30 14:19:39 +02:00
|
|
|
import org.newdawn.slick.util.Log;
|
2015-01-30 02:36:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Representation of a curve.
|
2015-02-11 08:56:02 +01:00
|
|
|
*
|
|
|
|
* @author fluddokt (https://github.com/fluddokt)
|
2015-01-30 02:36:23 +01:00
|
|
|
*/
|
|
|
|
public abstract class Curve {
|
2015-04-13 04:33:20 +02:00
|
|
|
/** Points generated along the curve should be spaced this far apart. */
|
2015-04-12 19:19:33 +02:00
|
|
|
protected static float CURVE_POINTS_SEPERATION = 5;
|
2015-04-13 04:33:20 +02:00
|
|
|
|
2015-06-08 22:42:54 +02:00
|
|
|
/** The curve border color. */
|
|
|
|
private static Color borderColor;
|
|
|
|
|
2015-06-22 04:32:00 +02:00
|
|
|
/** Whether mmsliders are supported. */
|
|
|
|
private static boolean mmsliderSupported = false;
|
2015-06-08 21:02:28 +02:00
|
|
|
|
2015-05-17 03:42:03 +02:00
|
|
|
/** The associated HitObject. */
|
|
|
|
protected HitObject hitObject;
|
2015-01-30 02:36:23 +01:00
|
|
|
|
2015-03-13 01:12:43 +01:00
|
|
|
/** The scaled starting x, y coordinates. */
|
|
|
|
protected float x, y;
|
|
|
|
|
|
|
|
/** The scaled slider x, y coordinate lists. */
|
|
|
|
protected float[] sliderX, sliderY;
|
2015-06-08 21:02:28 +02:00
|
|
|
|
|
|
|
/** Per-curve render-state used for the new style curve renders. */
|
2015-03-30 14:19:39 +02:00
|
|
|
private CurveRenderState renderState;
|
2015-03-13 01:12:43 +01:00
|
|
|
|
2015-04-13 04:33:20 +02:00
|
|
|
/** Points along the curve (set by inherited classes). */
|
2015-04-12 16:25:03 +02:00
|
|
|
protected Vec2f[] curve;
|
|
|
|
|
2015-01-30 02:36:23 +01:00
|
|
|
/**
|
|
|
|
* Constructor.
|
2015-05-17 03:42:03 +02:00
|
|
|
* @param hitObject the associated HitObject
|
2015-01-30 02:36:23 +01:00
|
|
|
* @param color the color of this curve
|
|
|
|
*/
|
2015-05-17 03:42:03 +02:00
|
|
|
protected Curve(HitObject hitObject, Color color) {
|
2015-01-30 02:36:23 +01:00
|
|
|
this.hitObject = hitObject;
|
2015-03-13 01:12:43 +01:00
|
|
|
this.x = hitObject.getScaledX();
|
|
|
|
this.y = hitObject.getScaledY();
|
|
|
|
this.sliderX = hitObject.getScaledSliderX();
|
|
|
|
this.sliderY = hitObject.getScaledSliderY();
|
2015-03-30 14:19:39 +02:00
|
|
|
this.renderState = null;
|
2015-01-30 02:36:23 +01:00
|
|
|
}
|
|
|
|
|
2015-06-08 15:38:46 +02:00
|
|
|
/**
|
2015-06-08 21:02:28 +02:00
|
|
|
* Set the width and height of the container that Curves get drawn into.
|
2015-06-08 15:38:46 +02:00
|
|
|
* Should be called before any curves are drawn.
|
2015-06-08 21:02:28 +02:00
|
|
|
* @param width the container width
|
|
|
|
* @param height the container height
|
|
|
|
* @param circleSize the circle size
|
2015-06-08 22:42:54 +02:00
|
|
|
* @param borderColor the curve border color
|
2015-06-08 15:38:46 +02:00
|
|
|
*/
|
2015-06-08 22:42:54 +02:00
|
|
|
public static void init(int width, int height, float circleSize, Color borderColor) {
|
|
|
|
Curve.borderColor = borderColor;
|
2015-06-22 04:32:00 +02:00
|
|
|
|
|
|
|
ContextCapabilities capabilities = GLContext.getCapabilities();
|
2015-08-08 14:43:56 +02:00
|
|
|
mmsliderSupported = capabilities.GL_EXT_framebuffer_object && capabilities.OpenGL33;
|
2015-06-22 04:32:00 +02:00
|
|
|
if (mmsliderSupported)
|
2015-06-08 21:02:28 +02:00
|
|
|
CurveRenderState.init(width, height, circleSize);
|
|
|
|
else {
|
|
|
|
if (Options.getSkin().getSliderStyle() != Skin.STYLE_PEPPYSLIDER)
|
2015-06-22 04:32:00 +02:00
|
|
|
Log.warn("New slider style requires FBO support and OpenGL 3.2.");
|
2015-06-08 21:02:28 +02:00
|
|
|
}
|
2015-06-08 15:38:46 +02:00
|
|
|
}
|
2015-06-08 21:02:28 +02:00
|
|
|
|
2015-01-30 02:36:23 +01:00
|
|
|
/**
|
|
|
|
* Returns the point on the curve at a value t.
|
|
|
|
* @param t the t value [0, 1]
|
|
|
|
* @return the point [x, y]
|
|
|
|
*/
|
|
|
|
public abstract float[] pointAt(float t);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the full curve to the graphics context.
|
2015-04-08 08:05:12 +02:00
|
|
|
* @param color the color filter
|
2015-01-30 02:36:23 +01:00
|
|
|
*/
|
2015-04-12 16:25:03 +02:00
|
|
|
public void draw(Color color) {
|
2015-06-08 21:02:28 +02:00
|
|
|
if (curve == null)
|
2015-06-08 15:38:46 +02:00
|
|
|
return;
|
2015-06-08 21:02:28 +02:00
|
|
|
|
|
|
|
// peppysliders
|
2015-06-22 04:32:00 +02:00
|
|
|
if (Options.getSkin().getSliderStyle() == Skin.STYLE_PEPPYSLIDER || !mmsliderSupported) {
|
2015-06-08 15:38:46 +02:00
|
|
|
Image hitCircle = GameImage.HITCIRCLE.getImage();
|
|
|
|
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
|
2015-06-08 21:02:28 +02:00
|
|
|
for (int i = 0; i < curve.length; i++)
|
2015-06-08 15:38:46 +02:00
|
|
|
hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Utils.COLOR_WHITE_FADE);
|
2015-06-08 21:02:28 +02:00
|
|
|
for (int i = 0; i < curve.length; i++)
|
2015-06-08 15:38:46 +02:00
|
|
|
hitCircle.drawCentered(curve[i].x, curve[i].y, color);
|
2015-06-08 21:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// mmsliders
|
|
|
|
else {
|
|
|
|
if (renderState == null)
|
|
|
|
renderState = new CurveRenderState(hitObject);
|
2015-06-08 22:42:54 +02:00
|
|
|
renderState.draw(color, borderColor, curve);
|
2015-06-08 15:38:46 +02:00
|
|
|
}
|
2015-04-12 16:25:03 +02:00
|
|
|
}
|
2015-01-30 02:36:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the angle of the first control point.
|
|
|
|
*/
|
|
|
|
public abstract float getEndAngle();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the angle of the last control point.
|
|
|
|
*/
|
|
|
|
public abstract float getStartAngle();
|
|
|
|
|
|
|
|
/**
|
2015-03-13 01:12:43 +01:00
|
|
|
* Returns the scaled x coordinate of the control point at index i.
|
|
|
|
* @param i the control point index
|
2015-01-30 02:36:23 +01:00
|
|
|
*/
|
2015-03-13 01:12:43 +01:00
|
|
|
public float getX(int i) { return (i == 0) ? x : sliderX[i - 1]; }
|
2015-01-30 02:36:23 +01:00
|
|
|
|
|
|
|
/**
|
2015-03-13 01:12:43 +01:00
|
|
|
* Returns the scaled y coordinate of the control point at index i.
|
|
|
|
* @param i the control point index
|
2015-01-30 02:36:23 +01:00
|
|
|
*/
|
2015-03-13 01:12:43 +01:00
|
|
|
public float getY(int i) { return (i == 0) ? y : sliderY[i - 1]; }
|
2015-01-30 02:36:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Linear interpolation of a and b at t.
|
|
|
|
*/
|
|
|
|
protected float lerp(float a, float b, float t) {
|
|
|
|
return a * (1 - t) + b * t;
|
|
|
|
}
|
2015-03-30 14:19:39 +02:00
|
|
|
|
2015-06-08 21:02:28 +02:00
|
|
|
/**
|
|
|
|
* Discards the slider cache (only used for mmsliders).
|
|
|
|
*/
|
2015-03-30 14:19:39 +02:00
|
|
|
public void discardCache() {
|
2015-06-08 21:02:28 +02:00
|
|
|
if (renderState != null)
|
2015-03-30 14:19:39 +02:00
|
|
|
renderState.discardCache();
|
|
|
|
}
|
2015-01-30 02:36:23 +01:00
|
|
|
}
|