private void CoordsChanged(ChunkCoords newCoords, ChunkCoords oldCoords) { HashSet <ChunkCoords> activeCoords = new HashSet <ChunkCoords>(); HashSet <ChunkCoords> removedCoords = new HashSet <ChunkCoords>(); //send some active objects to the transition pool for (int i = active.Count - 1; i >= 0; i--) { StarFieldMaterialPropertyManager sfmpm = active[i]; activeCoords.Add(sfmpm.coord); if (ChunkCoords.SquareDistance(sfmpm.coord, newCoords) > ViewDistance) { removedCoords.Add(sfmpm.coord); active.RemoveAt(i); transitionActive.Add(sfmpm); } } //activate or create new items to fill in the scenery EntityNetwork.IterateCoordsInRange(newCoords, ViewDistance, cc => { int dist = ChunkCoords.SquareDistance(cc, oldCoords); if (dist <= ViewDistance && dist != -1) { return(false); } ChunkCoords loopedCoords = cc; if (hasLoopPoint) { loopedCoords.x = Mathf.Abs(cc.x) % loopSize; loopedCoords.y = Mathf.Abs(cc.y) % loopSize; } FillSpace(loopedCoords); //create new cosmic items if (Chunk(loopedCoords).Count == 0) { FillChunk(loopedCoords); } SetUpScenery(cc, loopedCoords); return(false); }, true); }
private bool IsInRange(ChunkCoords center, ChunkCoords check, int range) { return(ChunkCoords.SquareDistance(center, check) <= range); }