protected internal override bool TryGetIntersection(TimeStep step, Body first, Body second, out IContact contact) { long id = PairID.GetId(first.ID, second.ID); Arbiter arbiter; if (arbiters.TryGetValue(id, out arbiter)) { arbiter.Update(step); /* if (!arbiter.Collided) * { * arbiter.OnRemoved(); * arbiters.Remove(id); * }*/ } else { arbiter = new Arbiter(this, first, second); arbiter.Update(step); //if (arbiter.Collided) //{ arbiters.Add(id, arbiter); //} } contact = arbiter; return(arbiter.Collided); }
protected internal override bool TryGetIntersection(TimeStep step, Body first, Body second, out ReadOnlyCollection <IContactInfo> contacts) { long id = PairID.GetId(first.ID, second.ID); Arbiter arbiter; if (arbiters.TryGetValue(id, out arbiter)) { arbiter.Update(); if (!arbiter.Collided) { arbiters.Remove(id); } } else { arbiter = new Arbiter(this, first, second); arbiter.Update(); if (!first.IgnoresCollisionResponse && !second.IgnoresCollisionResponse && arbiter.Collided) { arbiters.Add(id, arbiter); } } contacts = arbiter.Contacts; return(arbiter.Collided); }
private void RunHash(TimeStep step) { List <long> keysToRemove = new List <long>(hash.Count); foreach (KeyValuePair <long, List <Body> > pair in hash) { List <Body> list = pair.Value; if (list.Count == 0) { keysToRemove.Add(pair.Key); } else { for (int index1 = 0; index1 < list.Count - 1; index1++) { Body body1 = list[index1]; for (int index2 = index1 + 1; index2 < list.Count; index2++) { Body body2 = list[index2]; if ((body1.Mass.MassInv != 0 || body2.Mass.MassInv != 0) && Body.CanCollide(body1, body2) && body1.Rectangle.Intersects(body2.Rectangle)) { long key = PairID.GetId(body1.ID, body2.ID); if (!filter.ContainsKey(key)) { filter.Add(key, null); OnCollision(step, body1, body2); } } } } list.Clear(); } } filter.Clear(); for (int index = 0; index < keysToRemove.Count; ++index) { hash.Remove(keysToRemove[index]); } }