Example #1
0
        public static void UpdateObject(LSBody Body, bool repartition = true)
        {
            GetGridBounds(Body);

            if (
                repartition == false ||
                (Body.PastGridXMin != GridXMin ||
                 Body.PastGridXMax != GridXMax ||
                 Body.PastGridYMin != GridYMin ||
                 Body.PastGridYMax != GridYMax))
            {
                //Remove from all partitions no longer located on
                for (int o = Body.PastGridXMin; o <= Body.PastGridXMax; o++)
                {
                    for (int p = Body.PastGridYMin; p <= Body.PastGridYMax; p++)
                    {
                        PartitionNode node = GetNode(o, p);
                        if (Body.Immovable)
                        {
                            node.RemoveImmovable(Body.ID);
                        }
                        else
                        {
                            node.Remove(Body.ID);
                        }
                    }
                }
                if (repartition)
                {
                    PartitionObject(Body, true);
                }
            }
        }
Example #2
0
        public static void UpdateObject(LSBody Body)
        {
            GridXMin = (Body.XMin - OffsetX) >> ShiftSize;
            GridXMax = ((Body.XMax - OffsetX) >> ShiftSize);
            GridYMin = ((Body.YMin - OffsetY) >> ShiftSize);
            GridYMax = ((Body.YMax - OffsetY) >> ShiftSize);
                        #if UNITY_EDITOR
            if (GridXMin < 0 || GridXMax >= Count || GridYMin < 0 || GridYMax >= Count)
            {
                Debug.LogError("Body with ID " + Body.ID.ToString() + " is out of partition bounds.");
                return;
            }
                        #endif
            if (Body.PastGridXMin != GridXMin ||
                Body.PastGridXMax != GridXMax ||
                Body.PastGridYMin != GridYMin ||
                Body.PastGridYMax != GridYMax)
            {
                for (long o = Body.PastGridXMin; o <= Body.PastGridXMax; o++)
                {
                    for (long p = Body.PastGridYMin; p <= Body.PastGridYMax; p++)
                    {
                        PartitionNode node = Nodes [o * Count + p];

                        node.Remove(Body.ID);
                    }
                }

                for (long i = GridXMin; i <= GridXMax; i++)
                {
                    for (long j = GridYMin; j <= GridYMax; j++)
                    {
                        PartitionNode node = Nodes [i * Count + j];

                        node.Add(Body.ID);
                    }
                }


                Body.PastGridXMin = GridXMin;
                Body.PastGridXMax = GridXMax;
                Body.PastGridYMin = GridYMin;
                Body.PastGridYMax = GridYMax;
            }
        }
Example #3
0
 public static void UpdateObject(LSBody Body, bool repartition = true)
 {
     GetGridBounds(Body);
     if (Body.PastGridXMin != GridXMin ||
         Body.PastGridXMax != GridXMax ||
         Body.PastGridYMin != GridYMin ||
         Body.PastGridYMax != GridYMax)
     {
         for (int o = Body.PastGridXMin; o <= Body.PastGridXMax; o++)
         {
             for (int p = Body.PastGridYMin; p <= Body.PastGridYMax; p++)
             {
                 PartitionNode node = GetNode(o, p);
                 node.Remove(Body.ID);
             }
         }
         if (repartition)
         {
             PartitionObject(Body, true);
         }
     }
 }
Example #4
0
        public static void UpdateObject(LSBody Body)
        {
            GetGridBounds(Body);


            if (Body.PastGridXMin != GridXMin ||
                Body.PastGridXMax != GridXMax ||
                Body.PastGridYMin != GridYMin ||
                Body.PastGridYMax != GridYMax)
            {
                for (int o = Body.PastGridXMin; o <= Body.PastGridXMax; o++)
                {
                    for (int p = Body.PastGridYMin; p <= Body.PastGridYMax; p++)
                    {
                        PartitionNode node = GetNode(o, p);
                        node.Remove(Body.ID);
                    }
                }

                for (int i = GridXMin; i <= GridXMax; i++)
                {
                    for (int j = GridYMin; j <= GridYMax; j++)
                    {
                        PartitionNode node = GetNode(i, j);

                        node.Add(Body.ID);
                    }
                }


                Body.PastGridXMin = GridXMin;
                Body.PastGridXMax = GridXMax;
                Body.PastGridYMin = GridYMin;
                Body.PastGridYMax = GridYMax;
            }
        }
        public static void PartitionObject(LSBody Body)
        {
            GridXMin = Body.XMin <= Body.FutureXMin ? ((Body.XMin - OffsetX) >> ShiftSize) : ((Body.FutureXMin - OffsetX) >> ShiftSize);
            GridXMax = Body.XMax >= Body.FutureXMax ? ((Body.XMax - OffsetX) >> ShiftSize) : ((Body.FutureXMax - OffsetX) >> ShiftSize);
            GridYMin = Body.YMin <= Body.FutureXMin ? ((Body.YMin - OffsetY) >> ShiftSize) : ((Body.FutureYMin - OffsetY) >> ShiftSize);
            GridYMax = Body.YMax >= Body.FutureYMax ? ((Body.YMax - OffsetY) >> ShiftSize) : ((Body.FutureYMax - OffsetY) >> ShiftSize);
            #if UNITY_EDITOR
            if (GridXMin < 0 || GridXMax >= Count || GridYMin < 0 || GridYMax >= Count)
            {
                Debug.LogError ("Body with ID " + Body.ID.ToString () + " is out of partition bounds.");
                return;
            }
            #endif
            if (Body.PastGridXMin != GridXMin ||
                Body.PastGridXMax != GridXMax ||
                Body.PastGridYMin != GridYMin ||
                Body.PastGridYMax != GridYMax) {
                for (o = Body.PastGridXMin; o <= Body.PastGridXMax; o++) {
                    for (p = Body.PastGridYMin; p <= Body.PastGridYMax; p++) {
                        node = Nodes [o * Count + p];

                        node.Remove (Body.ID);
                    }
                }

                for (i = GridXMin; i <= GridXMax; i++) {
                    for (j = GridYMin; j <= GridYMax; j++) {
                        node = Nodes [i * Count + j];

                        node.Add (Body.ID);
                    }
                }

                Body.PastGridXMin = GridXMin;
                Body.PastGridXMax = GridXMax;
                Body.PastGridYMin = GridYMin;
                Body.PastGridYMax = GridYMax;
            }
        }