コード例 #1
0
        private ServerChunk CreateServerChunk(
            IChunkSizePolicy chunkSizePolicy, 
            long x, 
            long y, 
            long z, 
            Func<long, long, int> heightMapFunc)
        {
            var size = chunkSizePolicy.ChunkCellWidth * chunkSizePolicy.ChunkCellHeight * chunkSizePolicy.ChunkCellDepth;
            var chunk = new ServerChunk(x, y, z) { Cells = new Cell[size] };
            for (var xx = 0; xx < chunkSizePolicy.ChunkCellWidth; xx++)
            {
                for (var yy = 0; yy < chunkSizePolicy.ChunkCellHeight; yy++)
                {
                    for (var zz = 0; zz < chunkSizePolicy.ChunkCellDepth; zz++)
                    {
                        var i = xx + (yy * chunkSizePolicy.ChunkCellWidth)
                                + (zz * chunkSizePolicy.ChunkCellWidth * chunkSizePolicy.ChunkCellHeight);
                        chunk.Cells[i].HeightMap = heightMapFunc(xx, zz);
                    }
                }
            }

            return chunk;
        }
コード例 #2
0
        private void ThreadedUpdate()
        {
            this.m_ChunkGenerator.InputConnect();

            this.Octree = this.m_ChunkOctreeFactory.CreateChunkOctree<ServerChunk>();

            while (true)
            {
                ChunkRequest request;
                if (!this.m_RequestedChunks.TryDequeue(out request))
                {
                    Thread.Sleep(10);
                    continue;
                }

                var existing = this.Octree.Get(request.X, request.Y, request.Z);
                if (existing == null)
                {
                    var chunk = new ServerChunk(request.X, request.Y, request.Z);
                    this.Octree.Set(chunk);
                    this.m_ChunkGenerator.Generate(
                        chunk,
                        () =>
                        {
                        });
                }
            }
        }