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; }
bool CheckRange(LSBody targetBody) { fastRangeToTarget = cachedAttack.Range + (targetBody.IsNotNull() ? targetBody.Radius : 0) + Agent.Body.Radius; fastRangeToTarget *= fastRangeToTarget; Vector2d targetDirection = targetBody._position - CachedBody._position; long fastMag = targetDirection.FastMagnitude(); return(fastMag <= fastRangeToTarget); }
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; }
/// <summary> /// Call this to deactivate this body and remove from simulation. /// </summary> public void Deactivate() { //Don't double deactivate if (this.Active == false) { return; } 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 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; }