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) { foreach (List <Body> list in hash.Values) { 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.GetHash(body1.ID, body2.ID); if (!filter.ContainsKey(key)) { filter.Add(key, null); OnCollision(step, body1, body2); } } } } list.Clear(); } filter.Clear(); }
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]); } }
private void FillHash() { Scalar average = 0; for (int index = 0; index < Bodies.Count; index++) { Body body = this.Bodies[index]; if (!body.IsCollidable) { continue; } BoundingRectangle rect = body.Rectangle; average += Math.Max(rect.Max.X - rect.Min.X, rect.Max.Y - rect.Min.Y); int minX = (int)(rect.Min.X * cellSizeInv); int maxX = (int)(rect.Max.X * cellSizeInv) + 1; int minY = (int)(rect.Min.Y * cellSizeInv); int maxY = (int)(rect.Max.Y * cellSizeInv) + 1; for (int x = minX; x < maxX; x++) { for (int y = minY; y < maxY; y++) { long key = PairID.GetHash(x, y); List <Body> list; if (!hash.TryGetValue(key, out list)) { list = new List <Body>(); hash.Add(key, list); } list.Add(body); } } } if (autoAdjustCellSize) { CellSize = 2 * average / (Bodies.Count); } }
/// <summary> /// cherche et attribue un adversaire a un joueur /// </summary> /// <param name="Player">le joueur a qui on doit attribué un adversaire</param> /// <param name="PlayerOpponentList"> la liste des adversaire que le joueur a déjà affronté</param> /// <param name="AllRemainingPlayer"> la liste de tout les joueur restant a appareillé</param> /// <param name="pairPlayer"> le paramettre qui servirait a donné la paire de joueur crée</param> /// <returns>dit si un paire de joueur a pu être crée</returns> private static bool PairAPlayer(int Player, Dictionary <int, List <int> > PlayerOpponentList, List <int> AllRemainingPlayer, out PairID pairPlayer) { pairPlayer = new PairID(); //initilaisation de la varible out. var PossibleOpponent = AllRemainingPlayer.Except(PlayerOpponentList[Player]).ToList(); //création de la liste de tout les adversaire que le jeoueur n'as pas encore rencontré PossibleOpponent.Remove(Player); // on retire le joueur de la liste des ces adversaire possible. if (PossibleOpponent.Count == 0) //si il n'y as pas d'adversaire dans la liste d'adversaire possible le pairing est impossible { return(false); //on signal que le pairinga échoué } else { pairPlayer.ID1 = Player;//on attribue le joueur comme le playerone var rng = new Random(); pairPlayer.ID2 = PossibleOpponent.ElementAt(rng.Next(0, PossibleOpponent.Count)); // on atribue un adversaire de la liste au hazard comme le joueur 2; return(true); // on signal que le pairing a fonctionner } }