Beispiel #1
0
        /// <summary>
        /// Updates central chunk to a new chunk, regenerating LoDs and loaded chunks appropriately
        /// </summary>
        /// <param name="newCenter">New center chunk</param>
        public void UpdateCenter(Chunk newCenter)
        {
            if (center == newCenter)
            {
                return;
            }
            var oldCenter = center;

            center = newCenter;

            if (!IntCube.WithinCube(
                    loadedCenter,
                    MaxLoadedDistance,
                    newCenter.Coords,
                    MaxViewDistance
                    ))
            {
                // Player needs to render chunks that were not yet loaded
                // Move the IntCube of loaded chunks to fit the player

                ClearFarChunks();
                GenerateNewChunks(
                    new IntCube(loadedCenter, MaxLoadedDistance),
                    new IntCube(newCenter.Coords, MaxLoadedDistance)
                    );

                loadedCenter = newCenter.Coords;
            }

            UpdateLODs();
        }
Beispiel #2
0
        /// <summary>
        /// Disposes chunks that are too far from player
        /// (farther then MaxLoadedDistance)
        /// </summary>
        private void ClearFarChunks()
        {
            int totalDeleted = 0;

            for (int i = 0; i < activeChunks.Count; i++)
            {
                var chunk = activeChunks[i];
                if (!IntCube.WithinCube(center.Coords, MaxLoadedDistance, chunk.Coords))
                {
                    activeChunks.RemoveAt(i);
                    chunk.Dispose();
                    --i;
                    ++totalDeleted;
                }
            }
            Debug.Log("Removing far chunks: " + totalDeleted.ToString());
        }