/// <summary> /// Get a free asteroid sector. /// </summary> /// <param name="sectorType">The sector type</param> /// <param name="lod">The sector LOD (level of detail)</param> /// <returns>A free asteroid sector</returns> private AsteroidSectorDecorator GetFreeSteroidSector(int sectorType, int lod) { lod = Math.Min(lod, this.MaxLodLevel); var freeList = this.freeAsteroidSectorList[sectorType, lod]; var busyList = this.busyAsteroidSectorList[sectorType, lod]; AsteroidSectorDecorator result; if (freeList.Count == 0) { result = new AsteroidSectorDecorator("asteroidCounter_" + (asteroidCounter++), sectorType, lod); this.Owner.AddChild(result.Entity); this.asteroidSectorList.Add(result); } else { result = freeList[0]; freeList.RemoveAt(0); } busyList.Add(result); result.Entity.Enabled = true; return(result); }
/// <summary> /// Refresh the asteroid field. /// </summary> private void Refresh() { this.CleanSectorList(); for (int i = -Border; i <= Border; i++) { for (int j = -Border; j <= Border; j++) { int asteroidSectorX = this.sectorX + i; int asteroidSectorY = this.sectorY + j; int sectorType = this.GetSectorTypeByCoords(asteroidSectorX, asteroidSectorY); Vector3 position = this.GetPositionByCoordinates(asteroidSectorX, asteroidSectorY); // Fix a wrong asteroid field position in 3DS MAX if (position.X == -2000) { position.X = -1933.599f; } AsteroidSectorDecorator asteroidSector = this.GetFreeSteroidSector(sectorType, Math.Max(Math.Abs(i), Math.Abs(j))); asteroidSector.Transform.Position = position; } } }