public bool Add(ref T particle) { if (CapacityLimit.HasValue && _Count >= CapacityLimit.Value) { _ParticlesRemovedByLimit += 1; if (!RemoveParticlesWhenCapacityReached || !RemoveRandomParticle(null)) { return(false); } } var position = GetPosition(ref particle); var sectorIndex = Particles.GetIndexFromPoint(position); var sector = Particles.GetSectorFromIndex(sectorIndex, true); if (SectorCapacityLimit.HasValue && sector.Count >= SectorCapacityLimit.Value) { _ParticlesRemovedByLimit += 1; if (!RemoveParticlesWhenCapacityReached || !RemoveRandomParticle(sector)) { return(false); } } sector.Add(ref particle); _Count += 1; return(true); }
public void Update() { _DeadSectors.Clear(); foreach (var sector in _Partition.Sectors) { _DeadSectors.Add(sector.Index); } foreach (var sector in System.Particles.Sectors) { _DeadSectors.Remove(sector.Index); var mySector = _Partition.GetSectorFromIndex(sector.Index, true); UpdateLight(sector, mySector); } foreach (var deadSector in _DeadSectors) { _Partition[deadSector].Dispose(); _Partition.RemoveAt(deadSector); } }