From 49d9c15d375942997692f7fccfb697665d0cb59e Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Sun, 20 Oct 2019 15:27:50 -0400 Subject: [PATCH] Sort by size --- Object3D.java | 192 +++++++++++++++++++++++++++++++++++------------ 1 files changed, 143 insertions(+), 49 deletions(-) diff --git a/Object3D.java b/Object3D.java index 31964db..54f9cd8 100644 --- a/Object3D.java +++ b/Object3D.java @@ -45,6 +45,20 @@ ScriptNode scriptnode; + void GetOrigin(cVector o) + { + o.x = this.toParent[3][0]; + o.y = this.toParent[3][1]; + o.z = this.toParent[3][2]; + } + + void SetOrigin(cVector o) + { + this.toParent[3][0] = o.x; + this.toParent[3][1] = o.y; + this.toParent[3][2] = o.z; + } + void deepCopyNode(Object3D other) { other.skyboxname = skyboxname; @@ -659,27 +673,74 @@ return this; } + class SizeCompare implements Comparable + { + int size; + Object3D child; + + SizeCompare(Object3D c) + { + child = c; + size = c.MemorySize(); + } + + public int compareTo(Object o) + { + SizeCompare comp = (SizeCompare) o; + + return comp.size < size ? 1 : -1; + } + } + + transient SizeCompare[] sizecompare = null; + void SortBySize() { - boolean sorted = false; +// boolean sorted = false; +// +// while (!sorted) +// { +// sorted = true; +// +// for (int i=0; i<Size()-1; i++) +// { +// Object3D obji = get(i); +// Object3D objj = get(i+1); +// +// if (obji.MemorySize() < objj.MemorySize()) +// { +// set(i, objj); +// set(i+1, obji); +// +// sorted = false; +// } +// } +// } + + int count = Size(); - while (!sorted) + if (sizecompare == null || sizecompare.length != count) { - sorted = true; - - for (int i=0; i<Size()-1; i++) + sizecompare = new SizeCompare[count]; + + for (int k=0; k<count; k++) { - Object3D obji = get(i); - Object3D objj = get(i+1); - - if (obji.MemorySize() < objj.MemorySize()) - { - set(i, objj); - set(i+1, obji); - - sorted = false; - } + sizecompare[k] = new SizeCompare(get(k)); } + } + else + { + for (int k=0; k<count; k++) + { + sizecompare[k].size = get(k).MemorySize(); + } + } + + java.util.Arrays.sort(sizecompare); + + for (int i=0; i<count; i++) + { + set(i, sizecompare[i].child); } } @@ -711,34 +772,59 @@ int MemorySize() { - if (memorysize == 0) +// if (memorysize == 0) +// { +// try +// { +// Object3D obj = this; +// +// Object3D parent = obj.parent; +// obj.parent = null; +// Object3D support = obj.support; +// obj.support = null; +// +// java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); +// java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(baos); +// +// out.writeObject(obj); +// +// obj.parent = parent; +// obj.support = support; +// +// memorysize = baos.toByteArray().length; +// } +// catch (Exception e) +// { +// e.printStackTrace(); +// } +// } +// +// return memorysize; + + if (blockloop) { - try - { - Object3D obj = this; + return 0; + } - Object3D parent = obj.parent; - obj.parent = null; - Object3D support = obj.support; - obj.support = null; - - java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); - java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(baos); - - out.writeObject(obj); - - obj.parent = parent; - obj.support = support; - - memorysize = baos.toByteArray().length; - } - catch (Exception e) - { - e.printStackTrace(); - } + int memory = 0; + + if (bRep != null) + { + memory = bRep.VertexCount(); } - return memorysize; + blockloop = true; + + for (int i = 0; i < Size(); i++) + { + Object3D obj = (Object3D) Children().get(i); + + memory += obj.MemorySize(); + } + + blockloop = false; + + return memory; } void Slower() @@ -6193,6 +6279,8 @@ static cVector maxima = new cVector(); static javax.vecmath.Point3d center = new javax.vecmath.Point3d(); + boolean compiling; + void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked) { Invariants(); // june 2013 @@ -6278,7 +6366,8 @@ boolean usecalllists = !IsDynamic() && IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !Link2Support()); // !(this instanceof cSpring) && !(this instanceof BezierPatch); - //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch); + + //usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch); //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass. @@ -6332,7 +6421,9 @@ display.NewList(bRep.displaylist); } + compiling = true; CallList(display, root, selected, blocked); + compiling = false; // compiled = true; if (usecalllists && bRep.displaylist > 0) @@ -6807,14 +6898,17 @@ void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected) { - if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000) - return; // no shadow for transparent objects - - if (display.DrawMode() == iCameraPane.SELECTION && dontselect) - return; - - if (hide) - return; + if (!compiling) + { + if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000) + return; // no shadow for transparent objects + + if (display.DrawMode() == iCameraPane.SELECTION && dontselect) + return; + + if (hide) + return; + } if (scriptnode != null) { @@ -8351,7 +8445,7 @@ objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")"; } else { - objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ ""; + objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + ((bRep==null)?(count - 1):bRep.VertexCount()) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ ""; } // + super.toString(); //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName(); -- Gitblit v1.6.2