From 6ae0c319ac5e1b2e54b00bd2504d7733a7380c63 Mon Sep 17 00:00:00 2001 From: badlogic Date: Mon, 27 Mar 2017 19:05:35 +0200 Subject: [PATCH] [libgdx] Minor cleanup & optimizations, timing code in ClipTest --- .../com/esotericsoftware/spine/ClippingTest.java | 15 +++++++++++++-- .../esotericsoftware/spine/SkeletonRenderer.java | 10 ++++++---- .../spine/utils/SutherlandHodgmanClipper.java | 5 ----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/ClippingTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/ClippingTest.java index 6b1d44d1a..e2d19ac46 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/ClippingTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/ClippingTest.java @@ -37,29 +37,36 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.math.WindowedMean; import com.esotericsoftware.spine.attachments.ClippingAttachment; import com.esotericsoftware.spine.utils.TwoColorPolygonBatch; public class ClippingTest extends ApplicationAdapter { OrthographicCamera camera; - TwoColorPolygonBatch batch; + PolygonSpriteBatch batch; SkeletonRenderer renderer; SkeletonRendererDebug debugRenderer; + BitmapFont font; TextureAtlas atlas; Skeleton skeleton; AnimationState state; + + WindowedMean mean = new WindowedMean(30); public void create () { camera = new OrthographicCamera(); - batch = new TwoColorPolygonBatch(2048); + batch = new PolygonSpriteBatch(2048); renderer = new SkeletonRenderer(); renderer.setPremultipliedAlpha(true); renderer.setSoftwareClipping(true); debugRenderer = new SkeletonRendererDebug(); debugRenderer.setBoundingBoxes(false); debugRenderer.setRegionAttachments(false); + font = new BitmapFont(); atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy-pma.atlas")); SkeletonJson json = new SkeletonJson(atlas); @@ -122,7 +129,11 @@ public class ClippingTest extends ApplicationAdapter { debugRenderer.getShapeRenderer().setProjectionMatrix(camera.combined); batch.begin(); + long start = System.nanoTime(); renderer.draw(batch, skeleton); + mean.addValue((System.nanoTime() - start) / 1000000.0f); + renderer.setPremultipliedAlpha(false); + font.draw(batch, "Time: " + mean.getMean() + "ms", 10, Gdx.graphics.getHeight() - font.getLineHeight()); batch.end(); debugRenderer.draw(skeleton); diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java index a28c41992..5e9d307c0 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java @@ -444,9 +444,11 @@ public class SkeletonRenderer { float denom = 1 / (d0 * d2 + d1 * d3); - for (int j = 0; j < clipOutput.size; j += 2) { - float x = clipOutput.get(j); - float y = clipOutput.get(j + 1); + float[] clipVertices = clipOutput.items; + + for (int j = 0, n = clipOutput.size; j < n; j += 2) { + float x = clipVertices[j]; + float y = clipVertices[j + 1]; float a = (d0 * (x - x3) + d1 * (y - y3)) * denom; float b = (d4 * (x - x3) + d2 * (y - y3)) * denom; @@ -462,7 +464,7 @@ public class SkeletonRenderer { clippedVertices.add(v); } - for (int j = 1; j < (clipOutput.size >> 1) - 1; j++) { + for (int j = 1, n = (clipOutput.size >> 1) - 1; j < n; j++) { clippedTriangles.add(idx); clippedTriangles.add(idx + j); clippedTriangles.add(idx + j + 1); diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/SutherlandHodgmanClipper.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/SutherlandHodgmanClipper.java index 9b9fca445..88a0fa01c 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/SutherlandHodgmanClipper.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/utils/SutherlandHodgmanClipper.java @@ -43,19 +43,14 @@ public class SutherlandHodgmanClipper { edgeY2 = tmp; } - // System.out.println("-- Edge " + i / 2 + ": (" + edgeX + ", " + edgeY + ")-(" + edgeX2 + ", " + edgeY2 + ")"); - for (int j = 0; j < input.size; j += 2) { float inputX = input.items[j % input.size]; float inputY = input.items[(j + 1) % input.size]; float inputX2 = input.items[(j + 2) % input.size]; float inputY2 = input.items[(j + 3) % input.size]; - // System.out.println("\tinput " + j / 2 + ": (" + inputX + ", " + inputY + ")-(" + inputX2 + ", " + inputY2 + ")"); - int side = pointLineSide(edgeX2, edgeY2, edgeX, edgeY, inputX, inputY); int side2 = pointLineSide(edgeX2, edgeY2, edgeX, edgeY, inputX2, inputY2); - // System.out.println("\tv1: " + (side < 0 ? "outside" : "inside" ) + ", v2: " + (side2 < 0 ? "outside" : "inside")); // v1 inside, v2 inside if (side >= 0 && side2 >= 0) {