示例#1
0
        public bool SearchForIntersect(VMObstacle rect)
        {
            if (rect.Intersects(Rect))
            {
                return(true);
            }
            //search in child nodes.
            int dontSearch = 0;

            switch (Dimension)
            {
            case IntersectRectDimension.Top:
                dontSearch = (rect.y2 <= Rect.y1) ? 2 : 0; break;     //if true, do not have to search right (where top greater)

            case IntersectRectDimension.Left:
                dontSearch = (rect.x2 <= Rect.x1) ? 2 : 0; break;     //if true, do not have to search right (where left greater)

            case IntersectRectDimension.Bottom:
                dontSearch = (rect.y1 >= Rect.y2) ? 1 : 0; break;     //if true, do not have to search left (where bottom less)

            case IntersectRectDimension.Right:
                dontSearch = (rect.x1 >= Rect.x2) ? 1 : 0; break;     //if true, do not have to search left (where right less)
            }

            //may need to search both :'( won't happen often with our small rectangles over large space though.
            return((dontSearch != 1 && LeftChild != null && LeftChild.SearchForIntersect(rect)) ||
                   (dontSearch != 2 && RightChild != null && RightChild.SearchForIntersect(rect)));
        }
示例#2
0
 public bool SearchForIntersect(VMObstacle rect)
 {
     if (Root == -1)
     {
         return(false);
     }
     else
     {
         return(SearchForIntersect(ref Nodes[Root], rect));
     }
 }
示例#3
0
 public bool SearchForIntersect(VMObstacle rect)
 {
     if (Root == null)
     {
         return(false);
     }
     else
     {
         return(Root.SearchForIntersect(rect));
     }
 }
示例#4
0
 public VMObstacleSetNodeOld(VMObstacleSetNodeOld last)
 {
     Rect      = last.Rect;
     Dimension = last.Dimension;
     if (last.LeftChild != null)
     {
         LeftChild = new VMObstacleSetNodeOld(last.LeftChild);
     }
     if (last.RightChild != null)
     {
         RightChild = new VMObstacleSetNodeOld(last.RightChild);
     }
 }
示例#5
0
        public List <VMObstacle> OnEdge(VMObstacle rect)
        {
            var result = new List <VMObstacle>();

            if (Root == -1)
            {
                return(result);
            }
            else
            {
                OnEdge(ref Nodes[Root], rect, result);
                return(result);
            }
        }
示例#6
0
        public List <VMObstacle> AllIntersect(VMObstacle rect)
        {
            var result = new List <VMObstacle>();

            if (Root == null)
            {
                return(result);
            }
            else
            {
                Root.AllIntersect(rect, result);
                return(result);
            }
        }
示例#7
0
        public List <VMObstacle> AllIntersect(VMObstacle rect)
        {
            var result = new List <VMObstacle>();

            if (Root == -1)
            {
                return(result);
            }
            else
            {
                AllIntersect(ref Nodes[Root], rect, result);
                return(result);
            }
        }
示例#8
0
        public List <VMObstacle> OnEdge(VMObstacle rect)
        {
            var result = new List <VMObstacle>();

            if (Root == null)
            {
                return(result);
            }
            else
            {
                Root.OnEdge(rect, result);
                return(result);
            }
        }
示例#9
0
        public void AddAsChild(VMObstacle rect)
        {
            bool rightSide = false;

            switch (Dimension)
            {
            case IntersectRectDimension.Top:
                rightSide = rect.y1 > Rect.y1; break;

            case IntersectRectDimension.Left:
                rightSide = rect.x1 > Rect.x1; break;

            case IntersectRectDimension.Bottom:
                rightSide = rect.y2 > Rect.y2; break;

            case IntersectRectDimension.Right:
                rightSide = rect.x2 > Rect.x2; break;
            }
            if (rightSide)
            {
                if (RightChild != null)
                {
                    RightChild.AddAsChild(rect);
                }
                else
                {
                    RightChild = new VMObstacleSetNodeOld
                    {
                        Dimension = (IntersectRectDimension)(((int)Dimension + 1) % 4),
                        Rect      = rect
                    };
                }
            }
            else
            {
                if (LeftChild != null)
                {
                    LeftChild.AddAsChild(rect);
                }
                else
                {
                    LeftChild = new VMObstacleSetNodeOld
                    {
                        Dimension = (IntersectRectDimension)(((int)Dimension + 1) % 4),
                        Rect      = rect
                    };
                }
            }
        }
示例#10
0
 public void Add(VMObstacle rect)
 {
     if (PoolInd >= Nodes.Length && FreeList.Count == 0)
     {
         InitNodes(Nodes.Length * 2);
     }
     Count++;
     if (Root == -1)
     {
         Root = GetNode(IntersectRectDimension.Left, rect);
     }
     else
     {
         AddAsChild(ref Nodes[Root], rect);
     }
 }
示例#11
0
 public void Add(VMObstacle rect)
 {
     Count++;
     if (Root == null)
     {
         Root = new VMObstacleSetNodeOld
         {
             Dimension = IntersectRectDimension.Left,
             Rect      = rect
         };
     }
     else
     {
         Root.AddAsChild(rect);
     }
 }
示例#12
0
        private int GetNode(IntersectRectDimension dir, VMObstacle rect)
        {
            var ind = GetNode();

            Nodes[ind] = new VMObstacleSetNode()
            {
                Dimension  = dir,
                Rect       = rect,
                LeftChild  = -1,
                RightChild = -1,
                Index      = ind,

                x1 = rect.x1,
                x2 = rect.x2,
                y1 = rect.y1,
                y2 = rect.y2
            };
            return(ind);
        }
示例#13
0
        private void AddAsChild(ref VMObstacleSetNode node, VMObstacle rect)
        {
            bool rightSide = false;

            switch (node.Dimension)
            {
            case IntersectRectDimension.Top:
                rightSide = rect.y1 > node.Rect.y1; break;

            case IntersectRectDimension.Left:
                rightSide = rect.x1 > node.Rect.x1; break;

            case IntersectRectDimension.Bottom:
                rightSide = rect.y2 > node.Rect.y2; break;

            case IntersectRectDimension.Right:
                rightSide = rect.x2 > node.Rect.x2; break;
            }
            if (rightSide)
            {
                if (node.RightChild != -1)
                {
                    AddAsChild(ref Nodes[node.RightChild], rect);
                }
                else
                {
                    node.RightChild = GetNode((IntersectRectDimension)(((int)node.Dimension + 1) % 4), rect);
                }
            }
            else
            {
                if (node.LeftChild != -1)
                {
                    AddAsChild(ref Nodes[node.LeftChild], rect);
                }
                else
                {
                    node.LeftChild = GetNode((IntersectRectDimension)(((int)node.Dimension + 1) % 4), rect);
                }
            }
        }
示例#14
0
        public void OnEdge(VMObstacle rect, List <VMObstacle> result)
        {
            if (rect.OnEdge(Rect))
            {
                result.Add(Rect);
            }
            //search in child nodes.
            //binary search to find equal opposing edges.
            int dontSearch = 0;

            switch (Dimension)
            {
            case IntersectRectDimension.Top:
                dontSearch = (rect.y2 < Rect.y1) ? 2 : 0; break;     //if true, do not have to search right (where top greater)

            case IntersectRectDimension.Left:
                dontSearch = (rect.x2 < Rect.x1) ? 2 : 0; break;     //if true, do not have to search right (where left greater)

            case IntersectRectDimension.Bottom:
                dontSearch = (rect.y1 > Rect.y2) ? 1 : 0; break;     //if true, do not have to search left (where bottom less)

            case IntersectRectDimension.Right:
                dontSearch = (rect.x1 > Rect.x2) ? 1 : 0; break;     //if true, do not have to search left (where right less)
            }

            //may need to search both :'( won't happen often with our small rectangles over large space though.
            //if (LeftChild != null) LeftChild.AllIntersect(rect, result);
            //if (RightChild != null) RightChild.AllIntersect(rect, result);

            if (dontSearch != 1 && LeftChild != null)
            {
                LeftChild.OnEdge(rect, result);
            }
            if (dontSearch != 2 && RightChild != null)
            {
                RightChild.OnEdge(rect, result);
            }
        }
示例#15
0
        public void AllIntersect(ref VMObstacleSetNode node, VMObstacle rect, List <VMObstacle> result)
        {
            if (node.Intersects(rect))
            {
                result.Add(node.Rect);
            }
            //search in child nodes.
            int dontSearch = 0;

            switch (node.Dimension)
            {
            case IntersectRectDimension.Top:
                dontSearch = (rect.y2 <= node.y1) ? 2 : 0; break;     //if true, do not have to search right (where top greater)

            case IntersectRectDimension.Left:
                dontSearch = (rect.x2 <= node.x1) ? 2 : 0; break;     //if true, do not have to search right (where left greater)

            case IntersectRectDimension.Bottom:
                dontSearch = (rect.y1 >= node.y2) ? 1 : 0; break;     //if true, do not have to search left (where bottom less)

            case IntersectRectDimension.Right:
                dontSearch = (rect.x1 >= node.x2) ? 1 : 0; break;     //if true, do not have to search left (where right less)
            }

            //may need to search both :'( won't happen often with our small rectangles over large space though.
            //if (node.LeftChild != -1) AllIntersect(ref Nodes[node.LeftChild], rect, result);
            //if (node.RightChild != -1) AllIntersect(ref Nodes[node.RightChild], rect, result);

            if (dontSearch != 1 && node.LeftChild != -1)
            {
                AllIntersect(ref Nodes[node.LeftChild], rect, result);
            }
            if (dontSearch != 2 && node.RightChild != -1)
            {
                AllIntersect(ref Nodes[node.RightChild], rect, result);
            }
        }
示例#16
0
 public bool OnEdge(VMObstacle other)
 {
     return((x2 == other.x1) || (x1 == other.x2) || (y1 == other.y2) || (y2 == other.y1));
 }
示例#17
0
 public bool Intersects(VMObstacle other)
 {
     return(!((other.x1 >= x2 || other.x2 <= x1) || (other.y1 >= y2 || other.y2 <= y1)));
 }
示例#18
0
        public List<VMObstacle> GenerateRoomObs(ushort room, Rectangle bounds)
        {
            var result = new List<VMObstacle>();
            var x1 = Math.Max(0, bounds.X - 1);
            var x2 = Math.Min(Width, bounds.Right + 1);
            var y1 = Math.Max(0, bounds.Y - 1);
            var y2 = Math.Min(Height, bounds.Bottom + 1);

            for (int y = y1; y < y2; y++)
            {
                VMObstacle next = null;
                for (int x = x1; x < x2; x++)
                {
                    int tRoom = (ushort)Map[x + y * Width];
                    if (tRoom != room)
                    {
                        if (next != null) next.x2 += 16;
                        else
                        {
                            next = new VMObstacle((x << 4) - 3, (y << 4) - 3, (x << 4) + 19, (y << 4) + 19);
                            result.Add(next);
                        }
                    }
                    else
                    {
                        if (next != null) next = null;
                    }
                }
            }
            return result;
        }
示例#19
0
 public VMExtendRegion(int a, int b, VMObstacle rect)
 {
     this.a = a;
     this.b = b;
     this.rect = rect;
 }
示例#20
0
        private Point RectIntersect(VMObstacle r1, VMObstacle r2, Point destPoint)
        {
            bool vert = true;
            int d1, d2, p=0;
            if (r1.x1 == r2.x2) { vert = false; p = r1.x1; }
            if (r1.x2 == r2.x1) { vert = false; p = r1.x2; }

            if (r1.y1 == r2.y2) { vert = true; p = r1.y1; }
            if (r1.y2 == r2.y1) { vert = true; p = r1.y2; }

            if (vert)
            {
                d1 = Math.Max(r1.x1, r2.x1); d2 = Math.Min(r1.x2, r2.x2);
                return new Point(Math.Max(d1, Math.Min(d2, destPoint.X)), p);
            }
            else
            {
                d1 = Math.Max(r1.y1, r2.y1); d2 = Math.Min(r1.y2, r2.y2);
                return new Point(p, Math.Max(d1, Math.Min(d2, destPoint.Y)));
            }
        }
示例#21
0
 public virtual void PositionChange(VMContext context, bool noEntryPoint)
 {
     Footprint = GetObstacle(Position, Direction);
     if (!(GhostImage || noEntryPoint)) ExecuteEntryPoint(9, context, true); //Placement
 }
示例#22
0
        public void SetFlag(VMEntityFlags flag, bool set)
        {
            if (set) ObjectData[(int)VMStackObjectVariable.Flags] |= (short)(flag);
            else ObjectData[(int)VMStackObjectVariable.Flags] &= ((short)~(flag));

            if (flag == VMEntityFlags.HasZeroExtent) Footprint = GetObstacle(Position, Direction);
            return;
        }
示例#23
0
 public bool Intersects(VMObstacle other)
 {
     return !((other.x1 >= x2 || other.x2 <= x1) || (other.y1 >= y2 || other.y2 <= y1));
 }