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 <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-09-05 09:32:26 -05:00
parent ffe4d5d415
commit 97dbb36e43
2 changed files with 20 additions and 8 deletions

View File

@ -190,19 +190,25 @@ public class Cursor {
// draw a fading trail // draw a fading trail
float alpha = 0f; float alpha = 0f;
float t = 2f / cursorX.size(); float t = 2f / cursorX.size();
if (skin.isCursorTrailRotated()) int cursorTrailWidth = cursorTrail.getWidth(), cursorTrailHeight = cursorTrail.getHeight();
cursorTrail.setRotation(cursorAngle); float cursorTrailRotation = (skin.isCursorTrailRotated()) ? cursorAngle : 0;
Iterator<Integer> iterX = cursorX.iterator(); Iterator<Integer> iterX = cursorX.iterator();
Iterator<Integer> iterY = cursorY.iterator(); Iterator<Integer> iterY = cursorY.iterator();
cursorTrail.startUse();
while (iterX.hasNext()) { while (iterX.hasNext()) {
int cx = iterX.next(); int cx = iterX.next();
int cy = iterY.next(); int cy = iterY.next();
alpha += t; alpha += t;
cursorTrail.setAlpha(alpha); cursorTrail.setImageColor(1f, 1f, 1f, alpha);
// if (cx != x || cy != y) // 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 // draw the other components
if (newStyle && skin.isCursorRotated()) if (newStyle && skin.isCursorRotated())

View File

@ -77,9 +77,10 @@ public class StarStream {
*/ */
public void draw() { public void draw() {
float t = animatedValue.getValue(); float t = animatedValue.getValue();
starImg.setAlpha(Math.min((1 - t) * 5f, 1f)); starImg.setImageColor(1f, 1f, 1f, Math.min((1 - t) * 5f, 1f));
starImg.setRotation(angle); starImg.drawEmbedded(
starImg.draw(containerWidth - (distance * t), ((containerHeight - starImg.getHeight()) / 2) + yOffset); containerWidth - (distance * t), ((containerHeight - starImg.getHeight()) / 2) + yOffset,
starImg.getWidth(), starImg.getHeight(), angle);
} }
/** /**
@ -107,8 +108,13 @@ public class StarStream {
* Draws the star stream. * Draws the star stream.
*/ */
public void draw() { public void draw() {
if (stars.isEmpty())
return;
starImg.startUse();
for (Star star : stars) for (Star star : stars)
star.draw(); star.draw();
starImg.endUse();
} }
/** /**