Revision: 3196
          http://vexi.svn.sourceforge.net/vexi/?rev=3196&view=rev
Author:   clrg
Date:     2008-11-13 01:45:55 +0000 (Thu, 13 Nov 2008)

Log Message:
-----------
Some minor improvements to BasicTree (reduce an arraycopy on insertion) and 
update code docs and tree-helper functions for Box

Modified Paths:
--------------
    trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
    trunk/core/org.vexi.core/src/org/vexi/util/BasicTree.java

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp  2008-11-12 01:11:58 UTC 
(rev 3195)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp  2008-11-13 01:45:55 UTC 
(rev 3196)
@@ -5,11 +5,6 @@
 package org.vexi.core;
 
 /**
- *  FIXME: if we trap on cols, then set rows to 0 (forcing cols to 1)
- *         should/does the cols trap get triggered?
- *  FIXME: mouse move/release still needs to propagate to boxen in which
- *         the mouse was pressed and is still held down
- *  
  *  FEATURE: mark to reflow starting with a certain child
  *  FEATURE: reintroduce surface.abort
  */
@@ -32,8 +27,8 @@
  *  <p>Encapsulates the data for a single Vexi box as well as all layout
  *     rendering logic.</p>
  *
- *  <p>The rendering process consists of four phases; the first three require
- *     one DFS (Depth First Search) pass over the tree and the fourth uses a
+ *  <p>The rendering process consists of four phases; the first two require
+ *     one DFS (Depth First Search) pass over the tree and the third uses a
  *     TFS (Top First Search) pass over the box tree:</p>
  *
  *  <ol>
@@ -240,9 +235,12 @@
         for(Box cur = this; cur != null; cur = cur.parent) {
             // get around sub-sampling of enlarged textures
             if (cur.texture != null && !cur.test(TILE_IMAGE)) {
-                // inefficient
+                // FIXME: inefficient but otherwise the consistency of
+                // translating enlarged pixels to on-screen coordinates
+                // can not be guarranteed as it depends upon first
+                // rendering the image at the full size of its box
                 x = 0; y = 0; w = cur.width; h = cur.height;
-                /** better but not quite right
+                /** better but not quite right - see above FIXME
                 //#repeat _w/_h w/h width/height x/y xps/yps
                 float xps = (float)cur.width/(float)cur.texture.width;
                 if (xps > 1) {
@@ -1587,6 +1585,7 @@
         int chainlength = 0;
         JSExn exn;
 
+        /** add a trap on 'b.prop' to the trap chain by executing pre-put of 
'val' */
         public JS beforeCascade(Box b, JS prop, JS val) {
             Trap t = b.wtrap(prop);
             try {
@@ -1601,8 +1600,10 @@
             return null;
         }
 
+        /** use to invoke internal finishTraps */
         public void finishTraps() throws JSExn { finishTraps(exn); }
 
+        /** finish the trap chain represented by this object */
         private void finishTraps(JSExn exn) throws JSExn {
             while (chainlength>0) {
                 try {
@@ -1613,6 +1614,7 @@
                     exn = e;
                 }
             }
+            // exception was not caught in JS, re-throw
             if (exn != null) throw exn;
         }
     }
@@ -1673,8 +1675,7 @@
 
     // children
     protected final int treeSize() { return bt == null ? 0 : bt.treeSize(); }
-    protected final Box getChild(int i) { if (i < 0 || i >= treeSize()) return 
null; return getNode(i); }
-    private final Box getNode(int p) { return (Box)bt.getNode(p); }
+    protected final Box getChild(int i) { return bt == null ? null : 
(Box)bt.getNode(i); }
     private final int indexNode(Box b) { return bt == null ? -1 : 
bt.indexNode(b); }
     private final void deleteNode(int p) { bt.deleteNode(p); }
     private final void insertNode(int p, Box b) { if (bt == null) bt = new 
BasicTree(); bt.insertNode(p,b); }
@@ -1761,19 +1762,23 @@
         }
     }
 
-    /** put child box */
-    private void put(int i, JS value) throws JSExn{ put(i,value,true,true);}
-    // REMARK hasNewParent - if a child has a new parent and a previous parent 
then
-    // it is being moved from the old to the new. In this case we only want to
-    // fire visible,surface,enter/leave traps once so it is not the same as 
-    // removing and then adding in discrete steps.
-    // REMARK viaRedirect - normally all put/get are transparently forwarded 
to the
-    // redirect (ignoring traps for simplicity), however if a box tries to 
remove
-    // itself from its parent, the parent may be redirected as it is quite 
normal
-    // for the redirect to be set after some children are created. So in this 
case 
-    // we want to ignore the redirect and remove ourselves from the parent (in 
the
-    // knowledge that we may never return!!) and not on the redirect where we 
don't
-    // exist!
+    /** put child box 'value' to position 'i' */
+    private void put(int i, JS value) throws JSExn{ put(i,value,true,true); }
+    
+    /**  
+     * @param hasNewParent - if a child has a new parent and a previous parent 
then
+     * it is being moved from the old to the new. In this case we only want to
+     * fire visible,surface,enter/leave traps once so it is not the same as 
+     * removing and then adding in discrete steps.
+     * 
+     * @param viaRedirect - normally all put/get are transparently forwarded 
to the
+     * redirect (ignoring traps for simplicity), however if a box tries to 
remove
+     * itself from its parent, the parent may be redirected as it is quite 
normal
+     * for the redirect to be set after some children are created. So in this 
case
+     * we want to ignore the redirect and remove ourselves from the parent (in 
the
+     * knowledge that we may never return!!) and not on the redirect where we 
don't
+     * exist!
+     */
     private void put(int i, JS value, boolean fireTrapsOnRemove, boolean 
viaRedirect) throws JSExn{
         Trap rangeTrap = test(CHILDREN_TRAP) ? wtrap(SC_Children) : null;
         JSExn rangeTrapException = null;
@@ -1838,7 +1843,7 @@
         }
     }
     
-    // children
+    /** get child from position 'i' via redirects and Children trap */
     private final JS get(int i) throws JSExn { 
         Trap rangeTrap = test(CHILDREN_READ_TRAP) ? rtrap(SC_Children) : null;
         JSExn rangeTrapException = null;

Modified: trunk/core/org.vexi.core/src/org/vexi/util/BasicTree.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/util/BasicTree.java   2008-11-12 
01:11:58 UTC (rev 3195)
+++ trunk/core/org.vexi.core/src/org/vexi/util/BasicTree.java   2008-11-13 
01:45:55 UTC (rev 3196)
@@ -7,9 +7,9 @@
 
 /**
  * Derived from the Ibex class Hash.Array, this is a very simple
- * implementation of the key 'tree' functions to replace the way
- * too complex (and as such notoriously problematic and notably
- * slightly slow) BalancedTree.  If there's any bugs in this code
+ * implementation of the key 'tree' functions used by Box. It is
+ * just manages an array, ensuring no null values in the active
+ * range.  As it is very simple, if there are any bugs here then
  * I'll eat my hat.  Fortunately I'm not wearing one right now.
  * 
  * @author Charles Goodwin
@@ -23,11 +23,25 @@
 
     final public void insertNode(Object obj) { insertNode(size, obj); }
     final public void insertNode(int i, Object obj) {
-        treeSize(size+1);
-        if (size > i) {
-            System.arraycopy(o, i, o, i+1, size-i);
+        // place obj at end of o
+        if (i >= size) {
+            treeSize(size+1);
+            o[size] = obj;
+
+        // insert obj into o
+        } else {
+            // avoid duplicate arraycopy calls that will
+            // caused by treeSize(size+1) then insertion
+            if (size >= o.length) {
+                Object[] newo = new Object[o.length+10];
+                System.arraycopy(o, 0, newo, 0, i);
+                System.arraycopy(o, i, newo, i+1, o.length-i);
+                o = newo;
+            } else {
+                System.arraycopy(o, i, o, i+1, size-i);
+            }
             o[i] = obj;
-        } else o[size] = obj;
+        }
         size++;
     }
     
@@ -35,6 +49,7 @@
         if (i > size) {
             treeSize(size+1);
             i = size;
+            size++;
         }
         Object old = o[i];
         o[i] = obj;
@@ -50,25 +65,23 @@
         if (i >= size || i < 0) return null;
         Object old = o[i];
         if (size == 1) o = null;
-        else if (size-1 > i)
-            System.arraycopy(o, i+1, o, i, size-i-1);
-        else o[size-1] = null;
+        else {
+            if (size-1 > i)
+                System.arraycopy(o, i+1, o, i, size-i-1);
+            // either remove i or (size-1>i) assist gc
+            o[size-1] = null;
+        }
         size--;
         return old;
     }
 
+    final public boolean containsValue(Object obj) { return 
indexNode(obj)!=-1; }
     final public int indexNode(Object obj) {
         for (int i=0; i < size; i++)
-            if ((obj == null && o[i] == null) || obj.equals(o[i])) return i;
+            if (o[i] == obj) return i;
         return -1;
     }
 
-    final public boolean containsValue(Object obj) {
-        for (int i=0; i < size; i++)
-            if ((obj == null && o[i] == null) || obj.equals(o[i])) return true;
-        return false;
-    }
-    
     final public void clear() { clearTree(); }
     final public void clearTree() {
         for (int i=0; i < size; i++) o[i] = null;


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to