From a400cb1c58492f49005dbe0ee9120bb20db8e52f Mon Sep 17 00:00:00 2001 From: Bebul Date: Wed, 12 Nov 2014 11:38:43 +0100 Subject: [PATCH 1/2] Optimize updateGeometricState to not recurse all children when not necessary Conflicts: jme3-core/src/main/java/com/jme3/scene/Node.java --- jme3-core/src/main/java/com/jme3/scene/Node.java | 15 ++++++++++++++- .../src/main/java/com/jme3/scene/Spatial.java | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/scene/Node.java b/jme3-core/src/main/java/com/jme3/scene/Node.java index f22c5b4b0..2f251ad03 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Node.java +++ b/jme3-core/src/main/java/com/jme3/scene/Node.java @@ -114,6 +114,16 @@ public class Node extends Spatial implements Savable { child.setLightListRefresh(); } + + Spatial p = parent; + while (p != null) { + if (p.refreshFlags != 0) { + return; //any refresh flag is sufficient, as each propagates to the root Node + } + p.refreshFlags |= RF_CHILD_LIGHTLIST; + p = p.parent; + } + } @Override @@ -154,6 +164,9 @@ public class Node extends Spatial implements Savable { @Override public void updateGeometricState(){ + boolean somethingToRefresh = (refreshFlags != 0); + if (!somethingToRefresh) return; + if ((refreshFlags & RF_LIGHTLIST) != 0){ updateWorldLightList(); } @@ -170,6 +183,7 @@ public class Node extends Spatial implements Savable { // a round-trip later on. // NOTE 9/19/09 // Although it does save a round trip, + refreshFlags &= ~RF_CHILD_LIGHTLIST; for (Spatial child : children.getArray()) { child.updateGeometricState(); } @@ -638,5 +652,4 @@ public class Node extends Spatial implements Savable { protected void breadthFirstTraversal(SceneGraphVisitor visitor, Queue queue) { queue.addAll(children); } - } diff --git a/jme3-core/src/main/java/com/jme3/scene/Spatial.java b/jme3-core/src/main/java/com/jme3/scene/Spatial.java index b6c61f81e..62add98ce 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Spatial.java +++ b/jme3-core/src/main/java/com/jme3/scene/Spatial.java @@ -118,7 +118,8 @@ public abstract class Spatial implements Savable, Cloneable, Collidable, Cloneab */ protected static final int RF_TRANSFORM = 0x01, // need light resort + combine transforms RF_BOUND = 0x02, - RF_LIGHTLIST = 0x04; // changes in light lists + RF_LIGHTLIST = 0x04, // changes in light lists + RF_CHILD_LIGHTLIST = 0x08; // some child need geometry update protected CullHint cullHint = CullHint.Inherit; protected BatchHint batchHint = BatchHint.Inherit; From c19842c55f57b28c6ec23f95c12136ed1d50e090 Mon Sep 17 00:00:00 2001 From: Bebul Date: Thu, 4 Dec 2014 14:55:49 +0100 Subject: [PATCH 2/2] clear RF_CHILD_LIGHTLIST even when there are no children --- jme3-core/src/main/java/com/jme3/scene/Node.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/scene/Node.java b/jme3-core/src/main/java/com/jme3/scene/Node.java index 2f251ad03..14b837011 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Node.java +++ b/jme3-core/src/main/java/com/jme3/scene/Node.java @@ -177,13 +177,13 @@ public class Node extends Spatial implements Savable { updateWorldTransforms(); } + refreshFlags &= ~RF_CHILD_LIGHTLIST; if (!children.isEmpty()) { // the important part- make sure child geometric state is refreshed // first before updating own world bound. This saves // a round-trip later on. // NOTE 9/19/09 // Although it does save a round trip, - refreshFlags &= ~RF_CHILD_LIGHTLIST; for (Spatial child : children.getArray()) { child.updateGeometricState(); }