From 97dbb36e430c7d29038e92ec1792a086dca4e9af Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Sat, 5 Sep 2015 09:32:26 -0500 Subject: [PATCH] Switch to startUse/drawEmbedded/endUse for cursortrail and star stream. This should be much more efficient when repeatedly rendering the same texture, as in these two cases. Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/ui/Cursor.java | 16 +++++++++++----- src/itdelatrisu/opsu/ui/StarStream.java | 12 +++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/itdelatrisu/opsu/ui/Cursor.java b/src/itdelatrisu/opsu/ui/Cursor.java index c7b46ffb..5c99f085 100644 --- a/src/itdelatrisu/opsu/ui/Cursor.java +++ b/src/itdelatrisu/opsu/ui/Cursor.java @@ -190,19 +190,25 @@ public class Cursor { // draw a fading trail float alpha = 0f; float t = 2f / cursorX.size(); - if (skin.isCursorTrailRotated()) - cursorTrail.setRotation(cursorAngle); + int cursorTrailWidth = cursorTrail.getWidth(), cursorTrailHeight = cursorTrail.getHeight(); + float cursorTrailRotation = (skin.isCursorTrailRotated()) ? cursorAngle : 0; Iterator iterX = cursorX.iterator(); Iterator iterY = cursorY.iterator(); + cursorTrail.startUse(); while (iterX.hasNext()) { int cx = iterX.next(); int cy = iterY.next(); alpha += t; - cursorTrail.setAlpha(alpha); + cursorTrail.setImageColor(1f, 1f, 1f, alpha); // if (cx != x || cy != y) - cursorTrail.drawCentered(cx, cy); + cursorTrail.drawEmbedded( + cx - (cursorTrailWidth / 2f), cy - (cursorTrailHeight / 2f), + cursorTrailWidth, cursorTrailHeight, cursorTrailRotation); } - cursorTrail.drawCentered(mouseX, mouseY); + cursorTrail.drawEmbedded( + mouseX - (cursorTrailWidth / 2f), mouseY - (cursorTrailHeight / 2f), + cursorTrailWidth, cursorTrailHeight, cursorTrailRotation); + cursorTrail.endUse(); // draw the other components if (newStyle && skin.isCursorRotated()) diff --git a/src/itdelatrisu/opsu/ui/StarStream.java b/src/itdelatrisu/opsu/ui/StarStream.java index 3d79aa52..ec42c2aa 100644 --- a/src/itdelatrisu/opsu/ui/StarStream.java +++ b/src/itdelatrisu/opsu/ui/StarStream.java @@ -77,9 +77,10 @@ public class StarStream { */ public void draw() { float t = animatedValue.getValue(); - starImg.setAlpha(Math.min((1 - t) * 5f, 1f)); - starImg.setRotation(angle); - starImg.draw(containerWidth - (distance * t), ((containerHeight - starImg.getHeight()) / 2) + yOffset); + starImg.setImageColor(1f, 1f, 1f, Math.min((1 - t) * 5f, 1f)); + starImg.drawEmbedded( + containerWidth - (distance * t), ((containerHeight - starImg.getHeight()) / 2) + yOffset, + starImg.getWidth(), starImg.getHeight(), angle); } /** @@ -107,8 +108,13 @@ public class StarStream { * Draws the star stream. */ public void draw() { + if (stars.isEmpty()) + return; + + starImg.startUse(); for (Star star : stars) star.draw(); + starImg.endUse(); } /**