Merge branch 'knorkesliders' into knorkemergingsliders

# Conflicts:
#	src/itdelatrisu/opsu/objects/Slider.java
This commit is contained in:
yugecin 2016-12-03 18:54:09 +01:00
commit 022035dce5
2 changed files with 28 additions and 20 deletions

View File

@ -60,7 +60,7 @@ public abstract class Curve {
private CurveRenderState renderState; private CurveRenderState renderState;
/** Points along the curve (set by inherited classes). */ /** Points along the curve (set by inherited classes). */
protected Vec2f[] curve; public Vec2f[] curve;
public Vec2f[] getCurvePoints() { public Vec2f[] getCurvePoints() {
return curve; return curve;
@ -121,25 +121,27 @@ public abstract class Curve {
* Draws the full curve to the graphics context. * Draws the full curve to the graphics context.
* @param color the color filter * @param color the color filter
*/ */
public void draw(Color color) { draw(color, 1f); } public void draw(Color color) { draw(color, 0f, 1f); }
/** /**
* Draws the curve in the range [0, t] (where the full range is [0, 1]) to the graphics context. * Draws the curve in the range [0, t] (where the full range is [0, 1]) to the graphics context.
* @param color the color filter * @param color the color filter
* @param t set the curve interval to [0, t] * @param t set the curve interval to [0, t]
*/ */
public void draw(Color color, float t) { public void draw(Color color, float t1, float t2) {
if (curve == null) if (curve == null)
return; return;
t = Utils.clamp(t, 0f, 1f); t1 = Utils.clamp(t1, 0f, 1f);
t2 = Utils.clamp(t2, 0f, 1f);
// peppysliders // peppysliders
if (Options.isFallbackSliders() || Options.getSkin().getSliderStyle() == Skin.STYLE_PEPPYSLIDER || !mmsliderSupported) { if (Options.isFallbackSliders() || Options.getSkin().getSliderStyle() == Skin.STYLE_PEPPYSLIDER || !mmsliderSupported) {
int drawUpTo = (int) (curve.length * t); int drawFrom = (int) (curve.length * t1);
int drawUpTo = (int) (curve.length * t2);
Image hitCircle = GameImage.HITCIRCLE.getImage(); Image hitCircle = GameImage.HITCIRCLE.getImage();
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage(); Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
for (int i = 0; i < drawUpTo; i++) for (int i = drawFrom; i < drawUpTo; i++)
hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Colors.WHITE_FADE); hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Colors.WHITE_FADE);
float a = fallbackSliderColor.a; float a = fallbackSliderColor.a;
fallbackSliderColor.a = color.a; fallbackSliderColor.a = color.a;
@ -152,7 +154,7 @@ public abstract class Curve {
else { else {
if (renderState == null) if (renderState == null)
renderState = new CurveRenderState(hitObject, curve); renderState = new CurveRenderState(hitObject, curve);
renderState.draw(color, borderColor, t); renderState.draw(color, borderColor, t1, t2);
} }
} }

View File

@ -64,6 +64,7 @@ public class CurveRenderState {
/** The point to which the curve has last been rendered into the texture (as an index into {@code curve}). */ /** The point to which the curve has last been rendered into the texture (as an index into {@code curve}). */
private int lastPointDrawn; private int lastPointDrawn;
private int firstPointDrawn;
/** /**
* Set the width and height of the container that Curves get drawn into. * Set the width and height of the container that Curves get drawn into.
@ -85,7 +86,7 @@ public class CurveRenderState {
/** /**
* Undo the static state. Static state setup caused by calls to * Undo the static state. Static state setup caused by calls to
* {@link #draw(org.newdawn.slick.Color, org.newdawn.slick.Color, float)} * {@link #draw(org.newdawn.slick.Color, org.newdawn.slick.Color, float, float)}
* are undone. * are undone.
*/ */
public static void shutdown() { public static void shutdown() {
@ -110,10 +111,11 @@ public class CurveRenderState {
* runs it just draws the cached copy to the screen. * runs it just draws the cached copy to the screen.
* @param color tint of the curve * @param color tint of the curve
* @param borderColor the curve border color * @param borderColor the curve border color
* @param t the point up to which the curve should be drawn (in the interval [0, 1]) * @param t2 the point up to which the curve should be drawn (in the interval [0, 1])
*/ */
public void draw(Color color, Color borderColor, float t) { public void draw(Color color, Color borderColor, float t1, float t2) {
t = Utils.clamp(t, 0.0f, 1.0f); t1 = Utils.clamp(t1, 0.0f, 1.0f);
t2 = Utils.clamp(t2, 0.0f, 1.0f);
float alpha = color.a; float alpha = color.a;
// if this curve hasn't been drawn, draw it and cache the result // if this curve hasn't been drawn, draw it and cache the result
@ -128,12 +130,10 @@ public class CurveRenderState {
lastPointDrawn = -1; lastPointDrawn = -1;
} }
int drawUpTo = (int) (t * curve.length); int drawFrom = (int) (t1 * curve.length);
int drawUpTo = (int) (t2 * curve.length);
if (lastPointDrawn != drawUpTo) {
if (drawUpTo == lastPointDrawn)
return;
if (lastPointDrawn != drawUpTo || firstPointDrawn != drawFrom) {
int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT); int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
//glGetInteger requires a buffer of size 16, even though just 4 //glGetInteger requires a buffer of size 16, even though just 4
@ -147,8 +147,11 @@ public class CurveRenderState {
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
} }
if (firstPointDrawn != drawFrom) {
this.renderCurve(color, borderColor, lastPointDrawn, drawUpTo); this.renderCurve(color, borderColor, drawFrom, drawUpTo, true);
} else {
this.renderCurve(color, borderColor, lastPointDrawn, drawUpTo, false);
}
lastPointDrawn = drawUpTo; lastPointDrawn = drawUpTo;
color.a = 1f; color.a = 1f;
@ -295,7 +298,7 @@ public class CurveRenderState {
* @param color the color of the curve * @param color the color of the curve
* @param borderColor the curve border color * @param borderColor the curve border color
*/ */
private void renderCurve(Color color, Color borderColor, int from, int to) { private void renderCurve(Color color, Color borderColor, int from, int to, boolean clearFirst) {
staticState.initGradient(); staticState.initGradient();
RenderState state = saveRenderState(); RenderState state = saveRenderState();
staticState.initShaderProgram(); staticState.initShaderProgram();
@ -310,6 +313,9 @@ public class CurveRenderState {
//2*4 is for skipping the first 2 floats (u,v) //2*4 is for skipping the first 2 floats (u,v)
GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4); GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0); GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
if (clearFirst) {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
}
for (int i = from * 2; i < to * 2 - 1; ++i) for (int i = from * 2; i < to * 2 - 1; ++i)
GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2); GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
GL11.glFlush(); GL11.glFlush();