Beispiel #1
0
        void UpdatePlayerVisibleChunks(PlayerChunkLoadState state)
        {
            if (state.Entity == null)
            {
                return;
            }
            state.ChunksToUnload.Clear();

            _tempVisList.Clear();
            var centerPos = ChunkHelper.GetChunkIdFromCoords(state.Entity.Position);

            var dim = (WorldOptions.MaxLoadRadius - 1) * 2;

            ChunkHelper.Spiral(dim, dim, (x, y) => { _tempVisList.Add(centerPos.Add(x, 0, y)); });
            foreach (var c in _tempVisList)
            {
                if (state.SentChunks.Contains(c) || state.SendQueue.Contains(c) || state.LoadGenQueue.Contains(c))
                {
                    continue;
                }
                state.LoadGenQueue.Enqueue(c);
            }

            var maxLoadDistance = WorldOptions.ChunkUnloadDistance * WorldOptions.ChunkUnloadDistance;

            foreach (var c in state.SentChunks)
            {
                var dist = Int3.SquareDistanceFlat(centerPos, c);
                if (dist > maxLoadDistance)
                {
                    state.ChunksToUnload.Add(c);
                }
            }
        }