Optimise rendering speed by a factor of lots.
authorRichard Fairhurst <richard@systemeD.net>
Thu, 17 Nov 2011 16:02:55 +0000 (16:02 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Fri, 18 Nov 2011 17:08:42 +0000 (17:08 +0000)
net/systemeD/halcyon/MapPaint.as
net/systemeD/halcyon/NodeUI.as
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/styleparser/RuleSet.as

index 6dc75b4..8016686 100644 (file)
@@ -188,7 +188,7 @@ package net.systemeD.halcyon {
                        }
 
                        for each (poi in o.poisInside) {
-                               if (!nodeuis[poi.id]) { createNodeUI(poi); }
+                               if (!nodeuis[poi.id]) { createNodeUI(poi,true); }
                                else if (redraw) { nodeuis[poi.id].redraw(); }
                        }
 
@@ -263,11 +263,12 @@ package net.systemeD.halcyon {
                }
 
                /** Make a UI object representing a node. */
-               public function createNodeUI(node:Node,rotation:Number=0,layer:int=NO_LAYER,stateClasses:Object=null):NodeUI {
+               public function createNodeUI(node:Node,isPOI:Boolean,rotation:Number=0,layer:int=NO_LAYER,stateClasses:Object=null):NodeUI {
                        if (!nodeuis[node.id]) {
-                               nodeuis[node.id]=new NodeUI(node,this,rotation,layer,stateClasses);
+                               nodeuis[node.id]=new NodeUI(node,this,isPOI,rotation,layer,stateClasses);
                                node.addEventListener(Connection.NODE_DELETED, nodeDeleted);
                        } else {
+                               nodeuis[node.id].isPOI=isPOI;
                                for (var state:String in stateClasses) {
                                        nodeuis[node.id].setStateClass(state,stateClasses[state]);
                                }
@@ -348,15 +349,14 @@ package net.systemeD.halcyon {
                /** Redraw all entities */
                public function redraw():void {
                        for each (var w:WayUI in wayuis) { w.recalculate(); w.invalidateStyleList(); w.redraw(); }
-                       /* sometimes (e.g. in Map.setStyle) Mappaint.redrawPOIs() is called immediately afterwards anyway. FIXME? */
-                       for each (var p:NodeUI in nodeuis) { p.invalidateStyleList(); p.redraw(); }
-            for each (var m:MarkerUI in markeruis) { m.invalidateStyleList(); m.redraw(); }
+                       for each (var p:NodeUI in nodeuis) { if (p.isPOI) { p.invalidateStyleList(); p.redraw(); } }
+                       for each (var m:MarkerUI in markeruis) { m.invalidateStyleList(); m.redraw(); }
                }
 
                /** Redraw nodes and markers only */
                public function redrawPOIs():void {
-                       for each (var p:NodeUI in nodeuis) { p.invalidateStyleList(); p.redraw(); }
-            for each (var m:MarkerUI in markeruis) { m.invalidateStyleList(); m.redraw(); }
+                       for each (var p:NodeUI in nodeuis) { if (p.isPOI) { p.invalidateStyleList(); p.redraw(); } }
+                       for each (var m:MarkerUI in markeruis) { m.invalidateStyleList(); m.redraw(); }
                }
                
                /** Redraw a single entity if it exists */
@@ -393,7 +393,7 @@ package net.systemeD.halcyon {
         private function newPOICreatedListener(event:EntityEvent):void {
             var node:Node = event.entity as Node;
                        if (!node.within(map.edge_l, map.edge_r, map.edge_t, map.edge_b)) { return; }
-                       createNodeUI(node);
+                       createNodeUI(node,true);
         }
 
         private function newMarkerCreatedListener(event:EntityEvent):void {
index 4ad2c59..11bcc02 100644 (file)
@@ -16,6 +16,7 @@ package net.systemeD.halcyon {
        public class NodeUI extends EntityUI {
                
                public var loaded:Boolean=false;
+               public var isPOI:Boolean;
                private var iconnames:Object={};                        // name of icon on each subpart
                private var heading:Number=0;                           // heading within way
                private var rotation:Number=0;                          // rotation applied to this POI
@@ -27,9 +28,10 @@ package net.systemeD.halcyon {
                 * @param heading Optional angle.
                 * @param layer Which layer on the MapPaint object it sits on. @default Top layer
                 * @param stateClasses A settings object definining the initial state of the node (eg, highlighted, hover...) */
-               public function NodeUI(node:Node, paint:MapPaint, heading:Number=0, layer:int=NO_LAYER, stateClasses:Object=null) {
+               public function NodeUI(node:Node, paint:MapPaint, isPOI:Boolean, heading:Number=0, layer:int=NO_LAYER, stateClasses:Object=null) {
                        super(node,paint);
                        if (layer==NO_LAYER) { this.layer=paint.maxlayer; } else { this.layer=layer; }
+                       this.isPOI=isPOI;
                        this.heading = heading;
                        if (stateClasses) {
                                for (var state:String in stateClasses) {
@@ -77,7 +79,7 @@ package net.systemeD.halcyon {
                        tags=applyStateClasses(tags);
                        if (entity.status) { tags['_status']=entity.status; }
                        if (!styleList || !styleList.isValidAt(paint.map.scale)) {
-                               styleList=paint.ruleset.getStyles(entity,tags,paint.map.scale); 
+                               styleList=paint.ruleset.getStyles(entity,tags,paint.map.scale,isPOI); 
                        }
 
                        var suggestedLayer:Number=styleList.layerOverride();
index ed9156f..a7e101d 100644 (file)
@@ -347,7 +347,7 @@ package net.systemeD.halcyon {
 //                                  else { nodetags['_heading']=(heading[i]+heading[i-1])/2; }
                                // ** FIXME - heading isn't currently applied
                                nodeStateClasses['junction']=(node.numParentWays>1);
-                               paint.createNodeUI(node,r,layer,nodeStateClasses);
+                               paint.createNodeUI(node,false,r,layer,nodeStateClasses);
                        }
                        if (!drawn) { return false; } // If not visible, no hitzone.
                        
index de8d3dd..9c16687 100644 (file)
@@ -235,12 +235,17 @@ package net.systemeD.halcyon.styleparser {
                }
 
                /** Create a StyleList for an Entity, by creating a blank StyleList, then running each StyleChooser over it.
+                   Optionally, styleUntagged can be set to false, to abort (and return a blank StyleList) if the tag hash is empty.
                        @see net.systemeD.halcyon.styleparser.StyleList */
 
-               public function getStyles(obj:Entity, tags:Object, zoom:uint):StyleList {
+               public function getStyles(obj:Entity, tags:Object, zoom:uint, styleUntagged:Boolean=true):StyleList {
                        var sl:StyleList=new StyleList();
-                       for each (var sc:StyleChooser in choosers) {
-                               sc.updateStyles(obj,tags,sl,zoom);
+                       var tagged:Boolean=styleUntagged;
+                       for (var k:String in tags) { tagged=true; break; }
+                       if (tagged) {
+                               for each (var sc:StyleChooser in choosers) {
+                                       sc.updateStyles(obj,tags,sl,zoom);
+                               }
                        }
                        return sl;
                }