예제 #1
0
 public static IEnumerable <LSBody> RaycastAll(Vector2d start, Vector2d end)
 {
     _Version++;
     LSBody.PrepareAxisCheck(start, end);
     foreach (FractionalLineAlgorithm.Coordinate coor in
              GetRelevantNodeCoordinates(start, end))
     {
         int indexX = coor.X;
         int indexY = coor.Y;
         if (!Partition.CheckValid(coor.X, coor.Y))
         {
             break;
         }
         PartitionNode node = Partition.GetNode(indexX, indexY);
         for (int i = node.ContainedDynamicObjects.Count - 1; i >= 0; i--)
         {
             LSBody body = PhysicsManager.SimObjects[node.ContainedDynamicObjects[i]];
             if (body.IsNotNull() && body.RaycastVersion != _Version)
             {
                 if (Conditional.IsNull() || Conditional())
                 {
                     body.RaycastVersion = _Version;
                     if (body.Overlaps(bufferIntersectionPoints))
                     {
                         yield return(body);
                     }
                 }
             }
         }
     }
     Conditional = null;
     yield break;
 }
예제 #2
0
        public void Deactivate()
        {
            Partition.UpdateObject(this, false);

            foreach (var collisionPair in CollisionPairs.Values)
            {
                collisionPair.Body2.CollisionPairHolders.Remove(ID);
                DeactivatePair(collisionPair);
            }
            CollisionPairs.Clear();
            foreach (var id in CollisionPairHolders)
            {
                LSBody other = PhysicsManager.SimObjects[id];
                if (other.IsNotNull())
                {
                    CollisionPair collisionPair;
                    if (other.CollisionPairs.TryGetValue(ID, out collisionPair))
                    {
                        other.CollisionPairs.Remove(this.ID);
                        DeactivatePair(collisionPair);
                    }
                    else
                    {
                        Debug.Log("nope " + ID);
                    }
                }
            }
            CollisionPairHolders.Clear();

            PhysicsManager.Dessimilate(this);
            Active = false;
        }
        public static void LateVisualize()
        {
            //			bool doSetVisuals = false;
            //			if (AccumulatedTime >= PhysicsManager.FixedDeltaTime && Simulated) {
            //				AccumulatedTime = Time.deltaTime + (LerpTime % PhysicsManager.FixedDeltaTime);
            //				doSetVisuals = true;
            //				Simulated = false;
            //			} else {
            //				AccumulatedTime += Time.deltaTime;
            //			}
            //			LerpTime = (float)(AccumulatedTime / PhysicsManager.FixedDeltaTime);
            //			if (LerpTime > 1f) LerpTime = 1f;
            //			for (int i = 0; i < DynamicSimObjects.PeakCount; i++) {
            //				LSBody b1 = DynamicSimObjects.innerArray[i];
            //
            //				if (b1.IsNotNull()) {
            //					if (doSetVisuals) {
            //						b1.SetVisuals();
            //					}
            //					b1.Visualize();
            //				}
            //			}

            LerpTime = (float)PhysicsManager.FixedDeltaTime / (float)Time.timeScale;
            for (int i = 0; i < DynamicSimObjects.PeakCount; i++)
            {
                LSBody b1 = DynamicSimObjects.innerArray[i];
                if (b1.IsNotNull())
                {
                    b1.SetVisuals();
                }
            }
        }
예제 #4
0
        public static void LateVisualize()
        {
            if (Simulated)
            {
                AccumulatedTime = Time.deltaTime;
            }
            else
            {
                AccumulatedTime += Time.deltaTime;
            }
            LerpTime = (float)(AccumulatedTime / PhysicsManager.FixedDeltaTime);
            for (int i = 0; i < DynamicSimObjects.PeakCount; i++)
            {
                LSBody b1 = DynamicSimObjects.innerArray[i];

                if (b1.IsNotNull())
                {
                    if (Simulated)
                    {
                        b1.SetVisuals();
                    }
                    b1.Visualize();
                }
            }

            if (Simulated)
            {
                Simulated = false;
            }
        }
예제 #5
0
		public static void Visualize () {
			LerpTime = Time.fixedDeltaTime;
			if (ResetAccumulation) {
				AccumulatedTime = 0;
			}
			AccumulatedTime += Time.deltaTime;
			ExpectedAccumulation = AccumulatedTime / LerpTime;
			for (int i = 0; i < DynamicSimObjects.PeakCount; i++) {
				LSBody b1 = DynamicSimObjects.innerArray[i];
				if (b1.IsNotNull()) {
					b1.SetVisuals();
				}
			}

			ResetAccumulation = false;

		}
예제 #6
0
        public static void LateSimulate()
        {
            //TODO: Look into this
            int inactiveFrameThreshold = LockstepManager.FrameRate * 8;


            for (int i = 0; i < RanCollisionPairs.PeakCount; i++)
            {
                if (RanCollisionPairs.arrayAllocation[i])
                {
                    var instancePair = RanCollisionPairs[i];
                    var pair         = RanCollisionPairs[i].Pair;

                    if (instancePair.Version != instancePair.Pair._Version)
                    {
                        //pair is removed at Deactivate so no longer possible
                    }
                    else
                    {
                        if (pair._ranIndex >= 0)
                        {
                            RanCollisionPairs.RemoveAt(pair._ranIndex);
                            pair._ranIndex = -1;
                            InactiveCollisionPairs.Add(instancePair);
                        }
                    }
                }
            }

            //Clear the buffer of collision pairs to turn off and pool
            while (InactiveCollisionPairs.Count > 0)
            {
                var instancePair = InactiveCollisionPairs.Peek();
                var pair         = instancePair.Pair;

                if (pair.Active)
                {
                    //It's active again! Get it out of inactives and move on to the next guy.
                    InactiveCollisionPairs.Remove();
                }

                var passedFrames = LockstepManager.FrameCount - pair.LastFrame;
                if (passedFrames >= inactiveFrameThreshold)
                {
                    InactiveCollisionPairs.Remove();
                    FullDeactivateCollisionPair(pair);
                }
                else
                {
                    break;
                }
            }

            for (int i = 0; i < DynamicSimObjects.PeakCount; i++)
            {
                LSBody b1 = DynamicSimObjects.innerArray[i];
                if (b1.IsNotNull())
                {
                    b1.Simulate();
                }
            }
            ResetAccumulation = true;
        }
        public static void LateSimulate()
        {
            //2 seconds before turning off
            int inactiveFrameThreshold = 0;

            for (int i = 0; i < RanCollisionPairs.PeakCount; i++)
            {
                if (RanCollisionPairs.arrayAllocation[i])
                {
                    var instancePair = RanCollisionPairs[i];
                    var pair         = RanCollisionPairs[i].Pair;

                    if (instancePair.Version != instancePair.Pair._Version)
                    {
                        RanCollisionPairs.RemoveAt(i);
                        pair._ranIndex = -1;
                    }
                    else
                    {
                        if (pair.LastFrame == LockstepManager.FrameCount)
                        {
                        }
                        else if (pair._ranIndex >= 0)
                        {
#if false
                            if (!RanCollisionPairs.SafeRemoveAt(pair._ranIndex, instancePair))
                            {
                                Debug.Log("Removal Failed");
                            }
#else
                            RanCollisionPairs.RemoveAt(pair._ranIndex);
#endif

                            pair._ranIndex = -1;

                            InactiveCollisionPairs.Add(instancePair);
                        }
                    }
                }
            }

            while (InactiveCollisionPairs.Count > 0)
            {
                var instancePair = InactiveCollisionPairs.Peek();
                var pair         = instancePair.Pair;
                if (instancePair.Version != pair._Version)
                {
                    InactiveCollisionPairs.Remove();
                }
                else
                {
                    int dif = LockstepManager.FrameCount - pair.LastFrame;
                    if (dif == 0)
                    {
                        InactiveCollisionPairs.Remove();
                    }
                    else
                    {
                        if (dif >= inactiveFrameThreshold)
                        {
                            FullDeactivateCollisionPair(pair);
                            InactiveCollisionPairs.Remove();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            for (int i = 0; i < DynamicSimObjects.PeakCount; i++)
            {
                LSBody b1 = DynamicSimObjects.innerArray[i];
                if (b1.IsNotNull())
                {
                    b1.Simulate();
                }
            }
        }