Esempio n. 1
0
 public static void GenerateRegion()
 {
     Random random = new Random();
     ChunkWriter cw = new ChunkWriter();
     long pos = CHUNK_HEADER_LENGTH * Control.REGION_SIZE * Control.REGION_SIZE * Control.REGION_SIZE + sizeof(long);
     FileStream fs;
     fs = File.Create("0.0.0.rg");
     fs.Position = pos;
     for (int RegionX = 0; RegionX < Control.REGION_SIZE; RegionX++)
     {
         for (int RegionY = 0; RegionY < Control.REGION_SIZE; RegionY++)
         {
             for (int RegionZ = 0; RegionZ < Control.REGION_SIZE; RegionZ++)
             {
                 Chunk c;
                 if (RegionY < 4)
                 {
                     c = new Chunk((byte)BT.Stone);
                 }
                 else if (RegionY < 8)
                 {
                     c = new Chunk((byte)BT.Dirt);
                 }
                 else if (RegionY == 8)
                 {
                     int height = random.Next() % (Control.CHUNK_SIZE / 2);
                     c = new Chunk((byte)BT.Empty);
                     for (int x = 0; x < Control.CHUNK_SIZE; x++)
                     {
                         for (int y = 0; y < Control.CHUNK_SIZE; y++)
                         {
                             for (int z = 0; z < Control.CHUNK_SIZE; z++)
                             {
                                 if (y < height)
                                     c[x, y, z] = (byte)BT.Dirt;
                                 else if (y == height)
                                     c[x, y, z] = (byte)BT.Grass;
                             }
                         }
                     }
                 }
                 else
                 {
                     c = new Chunk((byte)BT.Empty);
                 }
                 fs.Position = CHUNK_HEADER_LENGTH *
                     (RegionX * Control.REGION_SIZE * Control.REGION_SIZE +
                     RegionY * Control.REGION_SIZE +
                     RegionZ);
                 cw.WriteChunk(fs, c, pos);
                 pos = fs.Position;
             }
         }
     }
     pos = fs.Position;
     fs.Position = 0;
     fs.Write(BitConverter.GetBytes(pos), 0, sizeof(long));
     fs.Close();
     fs.Dispose();
 }
Esempio n. 2
0
        public void WriteChunk(FileStream fs, Chunk c, long pos)
        {
            _header = fs.Position;
            _pos = pos;
            _filestream = fs;
            _chunk = c;

            if (!WriteNullChunk())
            {
                if (!WriteChunkSolid())
                {
                    if (!WriteChunkSubdiv())
                    {
                        WriteChunkArray();
                    }
                }
            }
        }
Esempio n. 3
0
 private static int CompareByDistance(Chunk x, Chunk y)
 {
     int dx = (_origin - x.Position).Square(),
         dy = (_origin - y.Position).Square();
     if (dx < dy)
         return -1;
     if (dx > dy)
         return 1;
     return 0;
 }
Esempio n. 4
0
 private static void AsyncLoadChunk(Chunk c)
 {
     ++_AsyncLoaders;
     AllChunks.Add(c);
     RegionReader reader = new RegionReader(ChunkToRegion(c.Position));
     LoadChunkDelegate del = reader.LoadChunk;
     del.BeginInvoke(c, FinishLoadChunk, del);
 }
Esempio n. 5
0
 private static void AsyncBuildChunk(Chunk c)
 {
     BuildChunkDelegate del = c.Build;
     del.BeginInvoke(FinishBuildChunk, del);
 }
Esempio n. 6
0
 public Voxel(Chunk chunk, VoxelType voxelType)
 {
     this.chunk = chunk;
     this.voxelType = voxelType;
 }