예제 #1
0
 public ScChunk(ScChunkPosition argChunkPosition, byte[] argChunkInfo)
 {
     // new Thread(() =>
     //{
     LoadChunk(argChunkPosition, argChunkInfo);
     //}).Start();
 }
예제 #2
0
        public void AddChunk(ScChunkPosition argChunkPosition, ScChunk chunk)
        {
            ChunkDictionary.Add(argChunkPosition, chunk);

            //if (_minX == 0)
            //    _minX = chunk.ChunkX;

            //if (_minZ == 0)
            //    _minZ = chunk.ChunkZ;
            //_minX = Math.Min(chunk.ChunkX, _minX);
            //_minZ = Math.Min(chunk.ChunkZ, _minZ);
            //_maxX = Math.Max(chunk.ChunkX, _maxX);
            //_maxZ = Math.Max(chunk.ChunkZ, _maxZ);
        }
예제 #3
0
        private void ImageMapChunk(ScChunkPosition argChunkPosition)
        {
            int backBufferStride = _worldImage.BackBufferStride;
            int localRange       = _maxX * _maxZ * backBufferStride;

            byte[] worldBytes = new byte[localRange];

            //foreach (var pair in ChunkDictionary)
            //{
            //offset = (argY * stride) + (argX * bpp) + colorByte
            int localByteOffset = (argChunkPosition.ChunkZ * backBufferStride) + (argChunkPosition.ChunkX * _bpp) + 0; //We're just using RED right now.

            worldBytes[localByteOffset]     = 254;
            worldBytes[localByteOffset + 1] = 254;
            //}

            _worldImage.WritePixels(new Int32Rect(0, 0, _maxX, _maxZ), worldBytes, backBufferStride, 0, 0);
        }
예제 #4
0
        private void LoadChunk(ScChunkPosition argChunkPosition, byte[] argChunkInfo)
        {
            //TODO: Thread this (now that the fileread is done).
            Blocks = new ScBlock[SizeX * SizeY * SizeZ];
            /**/

            //Read the next two 32-byte pieces.
            UInt32 magic1 = BitConverter.ToUInt32(argChunkInfo, 0);
            UInt32 magic2 = BitConverter.ToUInt32(argChunkInfo, 4);

            //Check that the Magic bytes are valid
            if (magic1 != 0xDEADBEEF || magic2 != 0xFFFFFFFF)
            {
                throw new FormatException("Not a Chunks.dat file.");
            }

            //Read the next two 32-byte pieces as the chunk X and Z (there is no Y because the entire height is always described)
            Int32 chunkX = BitConverter.ToInt32(argChunkInfo, 8);

            //Int32 chunkZ = file.ReadInt32();
            Int32 chunkZ = BitConverter.ToInt32(argChunkInfo, 12);

            //Validate that the chunk being read is the same as the chunk at the offset.
            if (chunkX != argChunkPosition.ChunkX || chunkZ != argChunkPosition.ChunkZ)
            {
                throw new InvalidDataException("Chunk header does not match chunk directory.");
            }

            ChunkX = chunkX;
            ChunkZ = chunkZ;

            /**/
            int infoIndex = 16;

            for (var blockYPosition = 0; blockYPosition < Blocks.Length; ++blockYPosition)
            {
                //Need to calc each block position.
                //Start at ChunkX, 0, ChunkZ
                //For every 128 ChunkY we increment ChunkZ
                //For every 16 ChunkZ we reset ChunkZ and increment ChunkX

                Blocks[blockYPosition] = new ScBlock(new Point3D(ChunkX, 0, ChunkZ), argChunkInfo[infoIndex++], argChunkInfo[infoIndex++]);  //Block Type, Block Data
            }
        }