private void UpdateContacts(ArbiterMap selectedArbiterMap) { foreach (Arbiter current in selectedArbiterMap.Arbiters) { this.UpdateArbiterContacts(current); } while (this.removedArbiterStack.Count > 0) { Arbiter arbiter = this.removedArbiterStack.Pop(); Arbiter.Pool.GiveBack(arbiter); selectedArbiterMap.Remove(arbiter); bool flag = selectedArbiterMap == this.arbiterMap; if (flag) { this.removedArbiterQueue.Enqueue(arbiter); this.events.RaiseBodiesEndCollide(arbiter.body1, arbiter.body2); this.cacheOverPairContact.SetBodies(arbiter.body1, arbiter.body2); this.initialCollisions.Remove(this.cacheOverPairContact); } else { bool isColliderOnly = arbiter.body1.isColliderOnly; if (isColliderOnly) { this.events.RaiseTriggerEndCollide(arbiter.body1, arbiter.body2); } else { this.events.RaiseTriggerEndCollide(arbiter.body2, arbiter.body1); } this.cacheOverPairContact.SetBodies(arbiter.body1, arbiter.body2); this.initialTriggers.Remove(this.cacheOverPairContact); } } }
public World(CollisionSystem collision) { bool flag = collision == null; if (flag) { throw new ArgumentNullException("The CollisionSystem can't be null.", "collision"); } RigidBody.instanceCount = 0; Constraint.instanceCount = 0; this.arbiterCallback = new Action <object>(this.ArbiterCallback); this.integrateCallback = new Action <object>(this.IntegrateCallback); this.RigidBodies = new ReadOnlyHashset <RigidBody>(this.rigidBodies); this.Constraints = new ReadOnlyHashset <Constraint>(this.constraints); this.SoftBodies = new ReadOnlyHashset <SoftBody>(this.softbodies); this.CollisionSystem = collision; this.collisionDetectionHandler = new CollisionDetectedHandler(this.CollisionDetected); this.CollisionSystem.CollisionDetected += this.collisionDetectionHandler; this.arbiterMap = new ArbiterMap(); this.arbiterTriggerMap = new ArbiterMap(); this.AllowDeactivation = false; }
private void CollisionDetected(RigidBody body1, RigidBody body2, TSVector point1, TSVector point2, TSVector normal, FP penetration) { bool flag = body1.IsColliderOnly || body2.IsColliderOnly; Arbiter arbiter = null; bool flag2 = flag; ArbiterMap arbiterMap; if (flag2) { arbiterMap = this.arbiterTriggerMap; } else { arbiterMap = this.arbiterMap; } bool flag3 = false; ArbiterMap obj = arbiterMap; lock (obj) { arbiterMap.LookUpArbiter(body1, body2, out arbiter); bool flag4 = arbiter == null; if (flag4) { arbiter = Arbiter.Pool.GetNew(); arbiter.body1 = body1; arbiter.body2 = body2; arbiterMap.Add(new ArbiterKey(body1, body2), arbiter); flag3 = true; } } bool flag5 = arbiter.body1 == body1; Contact contact; if (flag5) { TSVector.Negate(ref normal, out normal); contact = arbiter.AddContact(point1, point2, normal, penetration, this.contactSettings); } else { contact = arbiter.AddContact(point2, point1, normal, penetration, this.contactSettings); } bool flag6 = flag3; if (flag6) { bool flag7 = flag; if (flag7) { this.events.RaiseTriggerBeginCollide(contact); body1.arbitersTrigger.Add(arbiter); body2.arbitersTrigger.Add(arbiter); OverlapPairContact overlapPairContact = new OverlapPairContact(body1, body2); overlapPairContact.contact = contact; this.initialTriggers.Add(overlapPairContact); } else { this.events.RaiseBodiesBeginCollide(contact); this.addedArbiterQueue.Enqueue(arbiter); OverlapPairContact overlapPairContact2 = new OverlapPairContact(body1, body2); overlapPairContact2.contact = contact; this.initialCollisions.Add(overlapPairContact2); } } bool flag8 = !flag && contact != null; if (flag8) { this.events.RaiseContactCreated(contact); } }