diff options
author | phil <[email protected]> | 2017-02-27 09:59:00 +1300 |
---|---|---|
committer | phil <[email protected]> | 2017-02-27 09:59:00 +1300 |
commit | 6785c4efc44b4c411aa9b295528d9a6b1ad7c58a (patch) | |
tree | 98e11e055247910c84a48877dc0f56c2535f2b6a | |
parent | e803a9c992e1b210181433f257275bad92c45878 (diff) |
Performance improvements intersects and j3dmessage
The boundingBox intersects maths removes some repeated multiplications
SceneGrph objects that were heavy users of J3dMessages now hold onto the
previous messages and reuse them if possible to reduce the amount of new
statements
6 files changed, 74 insertions, 31 deletions
diff --git a/src/main/java/org/jogamp/java3d/BoundingBox.java b/src/main/java/org/jogamp/java3d/BoundingBox.java index 02bcbbc..aa7e739 100644 --- a/src/main/java/org/jogamp/java3d/BoundingBox.java +++ b/src/main/java/org/jogamp/java3d/BoundingBox.java @@ -1754,22 +1754,30 @@ public void setUpper(Point3d p1) { int i = 5; while (i>=0){ Vector4d vc = frustum.clipPlanes[i--]; - if ((( upper.x*vc.x + upper.y*vc.y + - upper.z*vc.z + vc.w ) < 0.0 ) && - (( upper.x*vc.x + lower.y*vc.y + - upper.z*vc.z + vc.w ) < 0.0 ) && - (( upper.x*vc.x + lower.y*vc.y + - lower.z*vc.z + vc.w ) < 0.0 ) && - (( upper.x*vc.x + upper.y*vc.y + - lower.z*vc.z + vc.w ) < 0.0 ) && - (( lower.x*vc.x + upper.y*vc.y + - upper.z*vc.z + vc.w ) < 0.0 ) && - (( lower.x*vc.x + lower.y*vc.y + - upper.z*vc.z + vc.w ) < 0.0 ) && - (( lower.x*vc.x + lower.y*vc.y + - lower.z*vc.z + vc.w ) < 0.0 ) && - (( lower.x*vc.x + upper.y*vc.y + - lower.z*vc.z + vc.w ) < 0.0 )) { + + double upxxvcx = upper.x*vc.x; + double loxxvcx = lower.x*vc.x; + double upyxvcy = upper.y*vc.y; + double loyxvcy = lower.y*vc.y; + double upzxvcz = upper.z*vc.z; + double lozxvcz = lower.z*vc.z; + + if ((( upxxvcx + upyxvcy + + upzxvcz + vc.w ) < 0.0 ) && + (( upxxvcx + loyxvcy + + upzxvcz + vc.w ) < 0.0 ) && + (( upxxvcx + loyxvcy + + lozxvcz + vc.w ) < 0.0 ) && + (( upxxvcx + upyxvcy + + lozxvcz + vc.w ) < 0.0 ) && + (( loxxvcx + upyxvcy + + upzxvcz + vc.w ) < 0.0 ) && + (( loxxvcx + loyxvcy + + upzxvcz + vc.w ) < 0.0 ) && + (( loxxvcx + loyxvcy + + lozxvcz + vc.w ) < 0.0 ) && + (( loxxvcx + upyxvcy + + lozxvcz + vc.w ) < 0.0 )) { // all corners outside this frustum plane // System.err.println("*** all corners outside this frustum plane"); return false; diff --git a/src/main/java/org/jogamp/java3d/CompileState.java b/src/main/java/org/jogamp/java3d/CompileState.java index 242fc94..8e1b2fe 100644 --- a/src/main/java/org/jogamp/java3d/CompileState.java +++ b/src/main/java/org/jogamp/java3d/CompileState.java @@ -185,6 +185,10 @@ AppearanceRetained getAppearance(AppearanceRetained app) { Shape3DRetained[] shapes = new Shape3DRetained[numShapes]; curList.copyInto(shapes); Shape3DRetained[] toBeMergedShapes = new Shape3DRetained[numShapes]; +//must be at least 2 to try a merge + if(numShapes>1) + { + for (int i = 0; i < numShapes; i++) { if (shapes[i] == null) { continue; @@ -286,6 +290,7 @@ AppearanceRetained getAppearance(AppearanceRetained app) { } } } + } // Clear the shapelists for the next merge shapeLists.clear(); diff --git a/src/main/java/org/jogamp/java3d/GeometryArrayRetained.java b/src/main/java/org/jogamp/java3d/GeometryArrayRetained.java index 0aa3e2b..e6731c2 100644 --- a/src/main/java/org/jogamp/java3d/GeometryArrayRetained.java +++ b/src/main/java/org/jogamp/java3d/GeometryArrayRetained.java @@ -3463,9 +3463,9 @@ ArrayList<ArrayList<MorphRetained>> morphUserLists = null; } - + J3dMessage[] m; void sendDataChangedMessage(boolean coordinatesChanged) { - J3dMessage[] m; + int i, j, k, numShapeMessages, numMorphMessages; synchronized(liveStateLock) { @@ -3483,6 +3483,7 @@ ArrayList<ArrayList<MorphRetained>> morphUserLists = null; synchronized (universeList) { numShapeMessages = universeList.size(); + if(m==null||m.length<numShapeMessages) m = new J3dMessage[numShapeMessages]; k = 0; @@ -3514,6 +3515,7 @@ ArrayList<ArrayList<MorphRetained>> morphUserLists = null; gaList.add(Shape3DRetained.getGeomAtom(s)); } + if(m[k]==null) m[k] = new J3dMessage(); m[k].type = J3dMessage.GEOMETRY_CHANGED; diff --git a/src/main/java/org/jogamp/java3d/SceneGraphObjectRetained.java b/src/main/java/org/jogamp/java3d/SceneGraphObjectRetained.java index b434b3e..f94b2a9 100644 --- a/src/main/java/org/jogamp/java3d/SceneGraphObjectRetained.java +++ b/src/main/java/org/jogamp/java3d/SceneGraphObjectRetained.java @@ -151,10 +151,12 @@ abstract class SceneGraphObjectRetained extends IndexedObject void traverse(boolean sameLevel, int level) { System.err.println(); - for (int i = 0; i < level; i++) { + for (int i = 0; i < level; i++) + { System.err.print("."); } - System.err.print(this); + System.err.print( + this.source.getName() + " ret:" + this.getClass().getSimpleName() + " source:" + this.source.getClass().getSimpleName()); } /** diff --git a/src/main/java/org/jogamp/java3d/TransformGroupRetained.java b/src/main/java/org/jogamp/java3d/TransformGroupRetained.java index cd6d634..426acea 100644 --- a/src/main/java/org/jogamp/java3d/TransformGroupRetained.java +++ b/src/main/java/org/jogamp/java3d/TransformGroupRetained.java @@ -122,22 +122,35 @@ ArrayList<NodeRetained> childTransformLinks = new ArrayList<NodeRetained>(1); * the passed transform. * @param t1 the transform to be copied */ + // re-use previous to avoid object creation, if nothing is still using it + private J3dMessage prevMessage; + private Transform3D trans = new Transform3D(); void setTransform(Transform3D t1) { + + //int i, j; J3dMessage tchangeMessage = null; - int i, j; - Transform3D trans = null; + if (prevMessage != null && prevMessage.getRefcount() == 0) + { + tchangeMessage = prevMessage; + } + else + { + tchangeMessage = new J3dMessage(); + // trans will still be in use as well in prev message re-create + trans = new Transform3D(); + } if (staticTransform != null) { // this writeable transformGroup has a static transform // merged into this node - trans = new Transform3D(staticTransform.transform); + trans.set(staticTransform.transform); trans.mul(t1); transform.setWithLock(trans); } else { - trans = new Transform3D(t1); + trans.set(t1); transform.setWithLock(t1); } @@ -151,7 +164,6 @@ ArrayList<NodeRetained> childTransformLinks = new ArrayList<NodeRetained>(1); throw new BadTransformException(J3dI18N.getString("ViewPlatformRetained0")); } - tchangeMessage = new J3dMessage(); tchangeMessage.type = J3dMessage.TRANSFORM_CHANGED; tchangeMessage.threads = targetThreads; tchangeMessage.args[1] = this; @@ -160,6 +172,7 @@ ArrayList<NodeRetained> childTransformLinks = new ArrayList<NodeRetained>(1); tchangeMessage.universe = universe; //System.err.println("TransformGroupRetained --- TRANSFORM_CHANGED " + this); VirtualUniverse.mc.processMessage(tchangeMessage); + prevMessage = tchangeMessage; } dirtyBoundsCache(); } @@ -415,12 +428,13 @@ ArrayList<NodeRetained> childTransformLinks = new ArrayList<NodeRetained>(1); for (int i = 0; i < level; i++) { System.err.print("."); } - System.err.print(this); + System.err.print( + this.source.getName() + " ret:" + this.getClass().getSimpleName() + " source:" + this.source.getClass().getSimpleName()); if (isStatic()) { System.err.print(" (s)"); } else { - System.err.print(" (w)"); + System.err.print(" (non-s)"); } System.err.println(); System.err.println(transform.toString()); diff --git a/src/main/java/org/jogamp/java3d/WakeupCondition.java b/src/main/java/org/jogamp/java3d/WakeupCondition.java index 14b436b..52eaa63 100644 --- a/src/main/java/org/jogamp/java3d/WakeupCondition.java +++ b/src/main/java/org/jogamp/java3d/WakeupCondition.java @@ -109,11 +109,22 @@ public abstract class WakeupCondition extends Object { /** * this sets the conditionMet flag. */ - void setConditionMet(int id, Boolean checkSchedulingRegion) { - - if (!conditionMet) { + // re-use previous to avoid object creation, if nothing is stillusing it + private J3dMessage prevMessage; + void setConditionMet(int id, Boolean checkSchedulingRegion) + { + if (!conditionMet) + { conditionMet = true; - J3dMessage message = new J3dMessage(); + J3dMessage message = null; + if (prevMessage != null && prevMessage.getRefcount() == 0) + { + message = prevMessage; + } + else + { + message = new J3dMessage(); + } message.type = J3dMessage.COND_MET; message.threads = J3dThread.UPDATE_BEHAVIOR; message.universe = behav.universe; @@ -121,6 +132,7 @@ public abstract class WakeupCondition extends Object { message.args[1] = checkSchedulingRegion; message.args[2] = this; VirtualUniverse.mc.processMessage(message); + prevMessage = message; } } |