From 017ab991faf87e46b218f91e6b3fc3309e8e8466 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 4 Oct 2016 03:35:25 -0400 Subject: [PATCH] v0.4.3: significantly reduced number of calls to updatematrix --- .../main/java/com/watabou/noosa/Visual.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Visual.java b/SPD-classes/src/main/java/com/watabou/noosa/Visual.java index 70cc7222b..4869cada0 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Visual.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Visual.java @@ -52,6 +52,9 @@ public class Visual extends Gizmo { public float angle; public float angularSpeed; + + private float lastX, lastY, lastW, lastH, lastA; + private PointF lastScale = new PointF(), lastOrigin = new PointF(); public Visual( float x, float y, float width, float height ) { this.x = x; @@ -76,12 +79,34 @@ public class Visual extends Gizmo { } @Override + //TODO caching the last value of all these variables does improve performance a bunch + // by letting us skip many calls to updateMatrix, but it is quite messy. It would be better to + // control their editing and have a single boolean to tell if the matrix needs updating. public void draw() { - updateMatrix(); + if (lastX != x || + lastY != y || + lastW != width || + lastH != height || + lastA != angle || + lastScale.x != scale.x || + lastScale.y != scale.y || + lastOrigin.x != origin.x || + lastOrigin.y != origin.y){ + + lastX = x; + lastY = y; + lastW = width; + lastH = height; + lastA = angle; + lastScale.x = scale.x; + lastScale.y = scale.y; + lastOrigin.x = origin.x; + lastOrigin.y = origin.y; + + updateMatrix(); + } } - //FIXME this is recomputing a lot of stuff every frame - // would be far better to redo this only when changes happen protected void updateMatrix() { Matrix.setIdentity( matrix ); Matrix.translate( matrix, x, y );