Beispiel #1
0
        public Chunk GetChunk(int x, int z)
        {
            bool haveData = false;

            if (db == null)
            {
                throw new InvalidOperationException("Open Db first");
            }

            var subChunks = new Dictionary <byte, byte[]>();

            var key = CreateKey(x, z);

            for (byte subChunkIdx = 0; subChunkIdx < 15; subChunkIdx++)
            {
                key[9] = subChunkIdx;
                UIntPtr length;
                var     data = db.Get(key, out length);
                if (data != null)
                {
                    subChunks[subChunkIdx] = data;
                    haveData = true;
                }
            }

            if (!haveData)
            {
                return(null);
            }

            Chunk c;

            if (ChunkPool != null)
            {
                c   = ChunkPool.Get();
                c.X = x;
                c.Z = z;
            }
            else
            {
                c = new Chunk(x, z);
            }

            foreach (var subChunkRaw in subChunks)
            {
                CopySubChunkToChunk(c, subChunkRaw);
            }

            return(c);
        }
Beispiel #2
0
        public Chunk GetChunk(int x, int z, ChunkData data)
        {
            Chunk c;

            if (ChunkPool != null)
            {
                c   = ChunkPool.Get();
                c.X = x;
                c.Z = z;
            }
            else
            {
                c = new Chunk(x, z);
            }

            foreach (var subChunkRaw in data.SubChunks)
            {
                CopySubChunkToChunk(c, subChunkRaw.Index, subChunkRaw.Data);
            }

            return(c);
        }