public void RecalculateConnections(QuadtreeNodeHolder holder, int depth, int x, int y)
        {
            if (root == null)
            {
                throw new System.InvalidOperationException("Graph contains no nodes");
            }

            if (holder.node == null)
            {
                throw new System.ArgumentException("No leaf node specified. Holder has no node.");
            }

            int width = 1 << (System.Math.Min(editorHeightLog2, editorWidthLog2) - depth);

            var ls = new List <QuadtreeNode>();

            AddNeighboursRec(ls, root, 0, 0, 0, new IntRect(x, y, x + width, y + width).Expand(0), holder.node);
            holder.node.connections     = ls.ToArray();
            holder.node.connectionCosts = new uint[ls.Count];

            for (int i = 0; i < ls.Count; i++)
            {
                uint d = (uint)(ls[i].position - holder.node.position).costMagnitude;
                holder.node.connectionCosts[i] = d;
            }
        }
Exemple #2
0
        public void RecalculateConnections(QuadtreeNodeHolder holder, int depth, int x, int y)
        {
            if (this.root == null)
            {
                throw new InvalidOperationException("Graph contains no nodes");
            }
            if (holder.node == null)
            {
                throw new ArgumentException("No leaf node specified. Holder has no node.");
            }
            int num = 1 << Math.Min(this.editorHeightLog2, this.editorWidthLog2) - depth;
            List <QuadtreeNode> list     = new List <QuadtreeNode>();
            List <QuadtreeNode> arg_75_1 = list;
            QuadtreeNodeHolder  arg_75_2 = this.root;
            int     arg_75_3             = 0;
            int     arg_75_4             = 0;
            int     arg_75_5             = 0;
            IntRect intRect = new IntRect(x, y, x + num, y + num);

            this.AddNeighboursRec(arg_75_1, arg_75_2, arg_75_3, arg_75_4, arg_75_5, intRect.Expand(0), holder.node);
            holder.node.connections     = list.ToArray();
            holder.node.connectionCosts = new uint[list.Count];
            for (int i = 0; i < list.Count; i++)
            {
                uint costMagnitude = (uint)(list[i].position - holder.node.position).costMagnitude;
                holder.node.connectionCosts[i] = costMagnitude;
            }
        }
        public void AddNeighboursRec(List <QuadtreeNode> arr, QuadtreeNodeHolder holder, int depth, int x, int y, IntRect bounds, QuadtreeNode dontInclude)
        {
            int width = 1 << (System.Math.Min(editorHeightLog2, editorWidthLog2) - depth);
            var r     = new IntRect(x, y, x + width, y + width);

            if (!IntRect.Intersects(r, bounds))
            {
                return;
            }

            if (holder.node != null)
            {
                if (holder.node != dontInclude)
                {
                    arr.Add(holder.node);
                }
            }
            else
            {
                AddNeighboursRec(arr, holder.c0, depth + 1, x, y, bounds, dontInclude);
                AddNeighboursRec(arr, holder.c1, depth + 1, x + width / 2, y, bounds, dontInclude);
                AddNeighboursRec(arr, holder.c2, depth + 1, x + width / 2, y + width / 2, bounds, dontInclude);
                AddNeighboursRec(arr, holder.c3, depth + 1, x, y + width / 2, bounds, dontInclude);
            }
        }
Exemple #4
0
        public void CreateNodeRec(QuadtreeNodeHolder holder, int depth, int x, int y)
        {
            int num2;
            int width = ((int)1) << (Math.Min(this.editorHeightLog2, this.editorWidthLog2) - depth);

            if (depth < this.minDepth)
            {
                num2 = -1;
            }
            else
            {
                num2 = this.CheckNode(x, y, width);
            }
            if (((num2 == 1) || (num2 == 0)) || (width == 1))
            {
                QuadtreeNode node = new QuadtreeNode(base.active);
                node.SetPosition((VInt3)this.LocalToWorldPosition(x, y, width));
                node.Walkable = num2 == 1;
                holder.node   = node;
            }
            else
            {
                holder.c0 = new QuadtreeNodeHolder();
                holder.c1 = new QuadtreeNodeHolder();
                holder.c2 = new QuadtreeNodeHolder();
                holder.c3 = new QuadtreeNodeHolder();
                this.CreateNodeRec(holder.c0, depth + 1, x, y);
                this.CreateNodeRec(holder.c1, depth + 1, x + (width / 2), y);
                this.CreateNodeRec(holder.c2, depth + 1, x + (width / 2), y + (width / 2));
                this.CreateNodeRec(holder.c3, depth + 1, x, y + (width / 2));
            }
        }
        public void CreateNodeRec(QuadtreeNodeHolder holder, int depth, int x, int y)
        {
            int width = 1 << (System.Math.Min(editorHeightLog2, editorWidthLog2) - depth);
            int walkable;

            if (depth < minDepth)
            {
                walkable = -1;
            }
            else
            {
                walkable = CheckNode(x, y, width);
            }

            if (walkable == 1 || walkable == 0 || width == 1)
            {
                var node = new QuadtreeNode(active);
                node.SetPosition((Int3)LocalToWorldPosition(x, y, width));
                node.Walkable = walkable == 1;
                holder.node   = node;
            }
            else                 //walkable = -1 //Undefined
            {
                holder.c0 = new QuadtreeNodeHolder();
                holder.c1 = new QuadtreeNodeHolder();
                holder.c2 = new QuadtreeNodeHolder();
                holder.c3 = new QuadtreeNodeHolder();

                CreateNodeRec(holder.c0, depth + 1, x, y);
                CreateNodeRec(holder.c1, depth + 1, x + width / 2, y);
                CreateNodeRec(holder.c2, depth + 1, x + width / 2, y + width / 2);
                CreateNodeRec(holder.c3, depth + 1, x, y + width / 2);
            }
        }
Exemple #6
0
        public void CreateNodeRec(QuadtreeNodeHolder holder, int depth, int x, int y)
        {
            int num = 1 << Math.Min(this.editorHeightLog2, this.editorWidthLog2) - depth;
            int num2;

            if (depth < this.minDepth)
            {
                num2 = -1;
            }
            else
            {
                num2 = this.CheckNode(x, y, num);
            }
            if (num2 == 1 || num2 == 0 || num == 1)
            {
                QuadtreeNode quadtreeNode = new QuadtreeNode(this.active);
                quadtreeNode.SetPosition((Int3)this.LocalToWorldPosition(x, y, num));
                quadtreeNode.Walkable = (num2 == 1);
                holder.node           = quadtreeNode;
            }
            else
            {
                holder.c0 = new QuadtreeNodeHolder();
                holder.c1 = new QuadtreeNodeHolder();
                holder.c2 = new QuadtreeNodeHolder();
                holder.c3 = new QuadtreeNodeHolder();
                this.CreateNodeRec(holder.c0, depth + 1, x, y);
                this.CreateNodeRec(holder.c1, depth + 1, x + num / 2, y);
                this.CreateNodeRec(holder.c2, depth + 1, x + num / 2, y + num / 2);
                this.CreateNodeRec(holder.c3, depth + 1, x, y + num / 2);
            }
        }
Exemple #7
0
		public void RecalculateConnectionsRec (QuadtreeNodeHolder holder, int depth, int x, int y) {
			if (holder.node != null) {
				RecalculateConnections (holder, depth, x,y);
			} else {
				var width = 1 << (Math.Min (editorHeightLog2,editorWidthLog2)-depth);
				
				RecalculateConnectionsRec (holder.c0,depth+1,x          , y          );
				RecalculateConnectionsRec (holder.c1,depth+1,x + width/2, y          );
				RecalculateConnectionsRec (holder.c2,depth+1,x + width/2, y + width/2);
				RecalculateConnectionsRec (holder.c3,depth+1,x          , y + width/2);
			}
		}
Exemple #8
0
 public void RecalculateConnectionsRec(QuadtreeNodeHolder holder, int depth, int x, int y)
 {
     if (holder.node != null)
     {
         this.RecalculateConnections(holder, depth, x, y);
     }
     else
     {
         int num = 1 << Math.Min(this.editorHeightLog2, this.editorWidthLog2) - depth;
         this.RecalculateConnectionsRec(holder.c0, depth + 1, x, y);
         this.RecalculateConnectionsRec(holder.c1, depth + 1, x + num / 2, y);
         this.RecalculateConnectionsRec(holder.c2, depth + 1, x + num / 2, y + num / 2);
         this.RecalculateConnectionsRec(holder.c3, depth + 1, x, y + num / 2);
     }
 }
        public void RecalculateConnectionsRec(QuadtreeNodeHolder holder, int depth, int x, int y)
        {
            if (holder.node != null)
            {
                RecalculateConnections(holder, depth, x, y);
            }
            else
            {
                int width = 1 << (System.Math.Min(editorHeightLog2, editorWidthLog2) - depth);

                RecalculateConnectionsRec(holder.c0, depth + 1, x, y);
                RecalculateConnectionsRec(holder.c1, depth + 1, x + width / 2, y);
                RecalculateConnectionsRec(holder.c2, depth + 1, x + width / 2, y + width / 2);
                RecalculateConnectionsRec(holder.c3, depth + 1, x, y + width / 2);
            }
        }
Exemple #10
0
        public void DrawRec(QuadtreeNodeHolder h, int depth, int x, int y, Vector3 parentPos)
        {
            int     num    = 1 << Math.Min(this.editorHeightLog2, this.editorWidthLog2) - depth;
            Vector3 vector = this.LocalToWorldPosition(x, y, num);

            Debug.DrawLine(vector, parentPos, Color.red);
            if (h.node != null)
            {
                Debug.DrawRay(vector, Vector3.down, (!h.node.Walkable) ? Color.yellow : Color.green);
            }
            else
            {
                this.DrawRec(h.c0, depth + 1, x, y, vector);
                this.DrawRec(h.c1, depth + 1, x + num / 2, y, vector);
                this.DrawRec(h.c2, depth + 1, x + num / 2, y + num / 2, vector);
                this.DrawRec(h.c3, depth + 1, x, y + num / 2, vector);
            }
        }
Exemple #11
0
        public override void ScanInternal(OnScanStatus statusCallback)
        {
            this.Width  = 1 << this.editorWidthLog2;
            this.Height = 1 << this.editorHeightLog2;
            this.map    = new BitArray(this.Width * this.Height);
            for (int i = 0; i < this.Width; i++)
            {
                for (int j = 0; j < this.Height; j++)
                {
                    this.map.Set(i + j * this.Width, this.CheckCollision(i, j));
                }
            }
            QuadtreeNodeHolder holder = new QuadtreeNodeHolder();

            this.CreateNodeRec(holder, 0, 0, 0);
            this.root = holder;
            this.RecalculateConnectionsRec(this.root, 0, 0, 0);
        }
Exemple #12
0
        public void DrawRec(QuadtreeNodeHolder h, int depth, int x, int y, Vector3 parentPos)
        {
            int     width = ((int)1) << (Math.Min(this.editorHeightLog2, this.editorWidthLog2) - depth);
            Vector3 start = this.LocalToWorldPosition(x, y, width);

            Debug.DrawLine(start, parentPos, Color.red);
            if (h.node != null)
            {
                Debug.DrawRay(start, Vector3.down, !h.node.Walkable ? Color.yellow : Color.green);
            }
            else
            {
                this.DrawRec(h.c0, depth + 1, x, y, start);
                this.DrawRec(h.c1, depth + 1, x + (width / 2), y, start);
                this.DrawRec(h.c2, depth + 1, x + (width / 2), y + (width / 2), start);
                this.DrawRec(h.c3, depth + 1, x, y + (width / 2), start);
            }
        }
        public QuadtreeNode QueryPoint(int qx, int qy)
        {
            if (root == null)
            {
                return(null);
            }
            QuadtreeNodeHolder c = root;
            int depth            = 0;
            int x = 0;
            int y = 0;

            while (c.node == null)
            {
                int width = 1 << (System.Math.Min(editorHeightLog2, editorWidthLog2) - depth);
                if (qx >= x + width / 2)
                {
                    x = x + width / 2;
                    if (qy >= y + width / 2)
                    {
                        y = y + width / 2;
                        c = c.c2;
                    }
                    else
                    {
                        c = c.c1;
                    }
                }
                else
                {
                    if (qy >= y + width / 2)
                    {
                        y = y + width / 2;
                        c = c.c3;
                    }
                    else
                    {
                        c = c.c0;
                    }
                }
                depth++;
            }
            return(c.node);
        }
		public void ScanInternal (OnScanStatus statusCallback) {
			Width = 1 << editorWidthLog2;
			Height = 1 << editorHeightLog2;
			/** \todo Check if can clear */
			map = new BitArray(Width*Height);

			for (int x=0;x<Width;x++) {
				for (int y=0;y<Height;y++) {
					map.Set(x+y*Width, CheckCollision (x,y));
				}
			}

			var h = new QuadtreeNodeHolder();

			CreateNodeRec (h, 0, 0,0);
			root = h;

			RecalculateConnectionsRec (root, 0,0,0);
		}
        public void DrawRec(QuadtreeNodeHolder h, int depth, int x, int y, Vector3 parentPos)
        {
            int width = 1 << (System.Math.Min(editorHeightLog2, editorWidthLog2) - depth);

            Vector3 pos = LocalToWorldPosition(x, y, width);

            Debug.DrawLine(pos, parentPos, Color.red);

            if (h.node != null)
            {
                Debug.DrawRay(pos, Vector3.down, h.node.Walkable ? Color.green : Color.yellow);
            }
            else
            {
                DrawRec(h.c0, depth + 1, x, y, pos);
                DrawRec(h.c1, depth + 1, x + width / 2, y, pos);
                DrawRec(h.c2, depth + 1, x + width / 2, y + width / 2, pos);
                DrawRec(h.c3, depth + 1, x, y + width / 2, pos);
            }
        }
Exemple #16
0
        public QuadtreeNode QueryPoint(int qx, int qy)
        {
            if (this.root == null)
            {
                return(null);
            }
            QuadtreeNodeHolder quadtreeNodeHolder = this.root;
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            while (quadtreeNodeHolder.node == null)
            {
                int num4 = 1 << Math.Min(this.editorHeightLog2, this.editorWidthLog2) - num;
                if (qx >= num2 + num4 / 2)
                {
                    num2 += num4 / 2;
                    if (qy >= num3 + num4 / 2)
                    {
                        num3 += num4 / 2;
                        quadtreeNodeHolder = quadtreeNodeHolder.c2;
                    }
                    else
                    {
                        quadtreeNodeHolder = quadtreeNodeHolder.c1;
                    }
                }
                else if (qy >= num3 + num4 / 2)
                {
                    num3 += num4 / 2;
                    quadtreeNodeHolder = quadtreeNodeHolder.c3;
                }
                else
                {
                    quadtreeNodeHolder = quadtreeNodeHolder.c0;
                }
                num++;
            }
            return(quadtreeNodeHolder.node);
        }
Exemple #17
0
        public QuadtreeNode QueryPoint(int qx, int qy)
        {
            if (this.root == null)
            {
                return(null);
            }
            QuadtreeNodeHolder root = this.root;
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            while (root.node == null)
            {
                int num4 = ((int)1) << (Math.Min(this.editorHeightLog2, this.editorWidthLog2) - num);
                if (qx >= (num2 + (num4 / 2)))
                {
                    num2 += num4 / 2;
                    if (qy >= (num3 + (num4 / 2)))
                    {
                        num3 += num4 / 2;
                        root  = root.c2;
                    }
                    else
                    {
                        root = root.c1;
                    }
                }
                else if (qy >= (num3 + (num4 / 2)))
                {
                    num3 += num4 / 2;
                    root  = root.c3;
                }
                else
                {
                    root = root.c0;
                }
                num++;
            }
            return(root.node);
        }
        public void ScanInternal(OnScanStatus statusCallback)
        {
            Width  = 1 << editorWidthLog2;
            Height = 1 << editorHeightLog2;
            /** \todo Check if can clear */
            map = new BitArray(Width * Height);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    map.Set(x + y * Width, CheckCollision(x, y));
                }
            }

            var h = new QuadtreeNodeHolder();

            CreateNodeRec(h, 0, 0, 0);
            root = h;

            RecalculateConnectionsRec(root, 0, 0, 0);
        }
Exemple #19
0
        public void AddNeighboursRec(ListView <QuadtreeNode> arr, QuadtreeNodeHolder holder, int depth, int x, int y, IntRect bounds, QuadtreeNode dontInclude)
        {
            int     num = ((int)1) << (Math.Min(this.editorHeightLog2, this.editorWidthLog2) - depth);
            IntRect a   = new IntRect(x, y, x + num, y + num);

            if (IntRect.Intersects(a, bounds))
            {
                if (holder.node != null)
                {
                    if (holder.node != dontInclude)
                    {
                        arr.Add(holder.node);
                    }
                }
                else
                {
                    this.AddNeighboursRec(arr, holder.c0, depth + 1, x, y, bounds, dontInclude);
                    this.AddNeighboursRec(arr, holder.c1, depth + 1, x + (num / 2), y, bounds, dontInclude);
                    this.AddNeighboursRec(arr, holder.c2, depth + 1, x + (num / 2), y + (num / 2), bounds, dontInclude);
                    this.AddNeighboursRec(arr, holder.c3, depth + 1, x, y + (num / 2), bounds, dontInclude);
                }
            }
        }
Exemple #20
0
        public void RecalculateConnections(QuadtreeNodeHolder holder, int depth, int x, int y)
        {
            if (this.root == null)
            {
                throw new InvalidOperationException("Graph contains no nodes");
            }
            if (holder.node == null)
            {
                throw new ArgumentException("No leaf node specified. Holder has no node.");
            }
            int num = ((int)1) << (Math.Min(this.editorHeightLog2, this.editorWidthLog2) - depth);
            ListLinqView <QuadtreeNode> arr = new ListLinqView <QuadtreeNode>();
            IntRect rect = new IntRect(x, y, x + num, y + num);

            this.AddNeighboursRec(arr, this.root, 0, 0, 0, rect.Expand(0), holder.node);
            holder.node.connections     = arr.ToArray();
            holder.node.connectionCosts = new uint[arr.Count];
            for (int i = 0; i < arr.Count; i++)
            {
                VInt3 num4 = arr[i].position - holder.node.position;
                holder.node.connectionCosts[i] = (uint)num4.costMagnitude;
            }
        }
Exemple #21
0
		public void CreateNodeRec (QuadtreeNodeHolder holder, int depth, int x, int y) {
			
			var width = 1 << (Math.Min (editorHeightLog2,editorWidthLog2)-depth);
			int walkable;
			if (depth < minDepth) {
				walkable = -1;
			} else {
				walkable = CheckNode (x,y, width);
			}
			
			if (walkable == 1 || walkable == 0 || width == 1) {
				var node = new QuadtreeNode(active);
				node.SetPosition ((Int3)LocalToWorldPosition(x,y,width));
				node.Walkable = walkable == 1;
				holder.node = node;
				
				
			} else { //walkable = -1 //Undefined
				holder.c0 = new QuadtreeNodeHolder ();
				holder.c1 = new QuadtreeNodeHolder ();
				holder.c2 = new QuadtreeNodeHolder ();
				holder.c3 = new QuadtreeNodeHolder ();
				
				CreateNodeRec (holder.c0,depth+1,x          , y          );
				CreateNodeRec (holder.c1,depth+1,x + width/2, y          );
				CreateNodeRec (holder.c2,depth+1,x + width/2, y + width/2);
				CreateNodeRec (holder.c3,depth+1,x          , y + width/2);
			}
		}
Exemple #22
0
		public void DrawRec (QuadtreeNodeHolder h, int depth, int x, int y, Vector3 parentPos) {
			var width = 1 << (Math.Min (editorHeightLog2,editorWidthLog2)-depth);
			
			var pos = LocalToWorldPosition (x,y,width);
			
			Debug.DrawLine (pos, parentPos, Color.red);
			
			if (h.node != null) {
				Debug.DrawRay (pos, Vector3.down, h.node.Walkable ? Color.green : Color.yellow);
			} else {
				DrawRec (h.c0, depth+1,x        , y          , pos);
				DrawRec (h.c1, depth+1,x+width/2, y          , pos);
				DrawRec (h.c2, depth+1,x+width/2, y + width/2, pos);
				DrawRec (h.c3, depth+1,x        , y + width/2, pos);
			}
		}
Exemple #23
0
		public void AddNeighboursRec (List<QuadtreeNode> arr, QuadtreeNodeHolder holder, int depth, int x, int y, IntRect bounds, QuadtreeNode dontInclude) {
			var width = 1 << (Math.Min (editorHeightLog2,editorWidthLog2)-depth);
			var r = new IntRect(x,y,x+width,y+width);
			if (!IntRect.Intersects (r,bounds)) return;
			
			if (holder.node != null) {
				if (holder.node != dontInclude) {
					arr.Add (holder.node);
				}
			} else {
				AddNeighboursRec (arr, holder.c0, depth+1,x        , y          , bounds, dontInclude);
				AddNeighboursRec (arr, holder.c1, depth+1,x+width/2, y          , bounds, dontInclude);
				AddNeighboursRec (arr, holder.c2, depth+1,x+width/2, y + width/2, bounds, dontInclude);
				AddNeighboursRec (arr, holder.c3, depth+1,x        , y + width/2, bounds, dontInclude);
			}
		}
Exemple #24
0
		public void RecalculateConnections (QuadtreeNodeHolder holder, int depth, int x, int y) {
			
			if (root == null) throw new InvalidOperationException ("Graph contains no nodes");
				
			if (holder.node == null) throw new ArgumentException ("No leaf node specified. Holder has no node.");
			
			var width = 1 << (Math.Min (editorHeightLog2,editorWidthLog2)-depth);
			
			var ls = new List<QuadtreeNode>();
			AddNeighboursRec (ls, root, 0,0,0, new IntRect (x,y,x+width,y+width).Expand(0), holder.node);
			holder.node.connections = ls.ToArray();
			holder.node.connectionCosts = new uint[ls.Count];
			
			for (var i=0;i<ls.Count;i++) {
				var d = (uint)(ls[i].position - holder.node.position).costMagnitude;
				holder.node.connectionCosts[i] = d;
			}
		}