From 08834471fc1c8395235a6e929035011cad2b5da3 Mon Sep 17 00:00:00 2001 From: yugecin Date: Sat, 3 Dec 2016 18:18:18 +0100 Subject: [PATCH] first attemt at shrinking sliders --- src/itdelatrisu/opsu/objects/Slider.java | 2 +- .../opsu/objects/curves/Curve.java | 16 ++++++---- .../opsu/render/CurveRenderState.java | 32 +++++++++++-------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/itdelatrisu/opsu/objects/Slider.java b/src/itdelatrisu/opsu/objects/Slider.java index 7a2c95b0..2b0b46d2 100644 --- a/src/itdelatrisu/opsu/objects/Slider.java +++ b/src/itdelatrisu/opsu/objects/Slider.java @@ -220,7 +220,7 @@ public class Slider extends GameObject { curveColor.a = curveAlpha; float curveInterval = Options.isSliderSnaking() ? alpha : 1f; - curve.draw(curveColor, curveInterval); + curve.draw(curveColor, Math.max(0, (trackPosition - getTime()) / sliderTimeTotal), curveInterval); color.a = alpha; g.pushTransform(); diff --git a/src/itdelatrisu/opsu/objects/curves/Curve.java b/src/itdelatrisu/opsu/objects/curves/Curve.java index 2a881b3a..6b5dd293 100644 --- a/src/itdelatrisu/opsu/objects/curves/Curve.java +++ b/src/itdelatrisu/opsu/objects/curves/Curve.java @@ -60,7 +60,7 @@ public abstract class Curve { private CurveRenderState renderState; /** Points along the curve (set by inherited classes). */ - protected Vec2f[] curve; + public Vec2f[] curve; private Color fallbackSliderColor = new Color(20, 20, 20); @@ -117,25 +117,27 @@ public abstract class Curve { * Draws the full curve to the graphics context. * @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. * @param color the color filter * @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) return; - t = Utils.clamp(t, 0f, 1f); + t1 = Utils.clamp(t1, 0f, 1f); + t2 = Utils.clamp(t2, 0f, 1f); // peppysliders 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 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); float a = fallbackSliderColor.a; fallbackSliderColor.a = color.a; @@ -148,7 +150,7 @@ public abstract class Curve { else { if (renderState == null) renderState = new CurveRenderState(hitObject, curve); - renderState.draw(color, borderColor, t); + renderState.draw(color, borderColor, t1, t2); } } diff --git a/src/itdelatrisu/opsu/render/CurveRenderState.java b/src/itdelatrisu/opsu/render/CurveRenderState.java index 34080c0c..64ff3cfd 100644 --- a/src/itdelatrisu/opsu/render/CurveRenderState.java +++ b/src/itdelatrisu/opsu/render/CurveRenderState.java @@ -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}). */ private int lastPointDrawn; + private int firstPointDrawn; /** * 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 - * {@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. */ public static void shutdown() { @@ -110,10 +111,11 @@ public class CurveRenderState { * runs it just draws the cached copy to the screen. * @param color tint of the curve * @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) { - t = Utils.clamp(t, 0.0f, 1.0f); + public void draw(Color color, Color borderColor, float t1, float t2) { + t1 = Utils.clamp(t1, 0.0f, 1.0f); + t2 = Utils.clamp(t2, 0.0f, 1.0f); float alpha = color.a; // if this curve hasn't been drawn, draw it and cache the result @@ -127,13 +129,11 @@ public class CurveRenderState { //write impossible value to make sure the fbo is cleared lastPointDrawn = -1; } - - int drawUpTo = (int) (t * curve.length); - - if (lastPointDrawn != drawUpTo) { - if (drawUpTo == lastPointDrawn) - return; + int drawFrom = (int) (t1 * curve.length); + int drawUpTo = (int) (t2 * curve.length); + + if (lastPointDrawn != drawUpTo || firstPointDrawn != drawFrom) { int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT); int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); //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.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); } - - this.renderCurve(color, borderColor, lastPointDrawn, drawUpTo); + if (firstPointDrawn != drawFrom) { + this.renderCurve(color, borderColor, drawFrom, drawUpTo, true); + } else { + this.renderCurve(color, borderColor, lastPointDrawn, drawUpTo, false); + } lastPointDrawn = drawUpTo; color.a = 1f; @@ -295,7 +298,7 @@ public class CurveRenderState { * @param color the color of the curve * @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(); RenderState state = saveRenderState(); staticState.initShaderProgram(); @@ -310,6 +313,9 @@ public class CurveRenderState { //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.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) GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2); GL11.glFlush();