Refactor dupe nodes - store the node rather than just the id, and move the Vector...
authorAndy Allan <gravitystorm@gmail.com>
Mon, 8 Nov 2010 18:07:04 +0000 (18:07 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Mon, 8 Nov 2010 18:07:04 +0000 (18:07 +0000)
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/connection/Node.as

index 04b7ba1..04cd4e9 100755 (executable)
@@ -107,7 +107,7 @@ package net.systemeD.halcyon.connection {
         protected function setNode(node:Node, queue:Boolean):void {
                        if (!nodes[node.id]) { nodecount++; }
             nodes[node.id] = node;
-            addDupe(node.id, node.lat, node.lon);
+            addDupe(node);
             if (node.loaded) { sendEvent(new EntityEvent(NEW_NODE, node),queue); }
         }
 
@@ -358,30 +358,21 @@ package net.systemeD.halcyon.connection {
             return traces;
         }
 
-        public function updateDupes(id:Number, origLat:Number, origLon:Number, newLat:Number, newLon:Number):void {
-            var dupes:Array = [];
-            for each (var dupe:Number in nodePositions[origLat+","+origLon]) {
-              if (dupe != id) {
-                dupes.push(dupe)
-              }
-            }
-            nodePositions[origLat+","+origLon] = dupes;
-            addDupe(id, newLat, newLon);
-        }
-
-        public function addDupe(id:Number, lat:Number, lon:Number):void {
-            var a:String = lat+","+lon;
+        public function addDupe(node:Node):void {
+            if (getNode(node.id) != node) { return; } // make sure it's on this connection
+            var a:String = node.lat+","+node.lon;
             if(!nodePositions[a]) {
               nodePositions[a] = [];
             }
-            nodePositions[a].push(id);
+            nodePositions[a].push(node);
         }
 
         public function removeDupe(node:Node):void {
+            if (getNode(node.id) != node) { return; } // make sure it's on this connection
             var a:String = node.lat+","+node.lon;
             var dupes:Array = [];
-            for each (var dupe:Number in nodePositions[a]) {
-              if (dupe != node.id) {
+            for each (var dupe:Node in nodePositions[a]) {
+              if (dupe != node) {
                 dupes.push(dupe)
               }
             }
index f4982e9..85ef6b2 100644 (file)
@@ -148,7 +148,7 @@ package net.systemeD.halcyon.connection {
               if (isDeleted) {
                 Connection.getConnection().removeDupe(n);
               } else {
-              Connection.getConnection().addDupe(n.id, n.lat, n.lon);
+                Connection.getConnection().addDupe(n);
               }
             }
                }
index b705482..19a69b9 100644 (file)
@@ -32,12 +32,11 @@ package net.systemeD.halcyon.connection {
 
         private function setLatLonImmediate(lat:Number, lon:Number):void {
             var connection:Connection = Connection.getConnection();
-            if (connection.getNode(this.id) == this) { // don't do this for nodes in Vector Backgrounds
-              connection.updateDupes(this.id, this._lat, this._lon, lat, lon);
-            }
+            connection.removeDupe(this);
             this._lat = lat;
             this._latproj = lat2latp(lat);
             this._lon = lon;
+            connection.addDupe(this);
                        for each (var way:Way in this.parentWays) {
                                way.expandBbox(this);
                        }