Пример #1
0
 public static void GenerateData(Chunk2 chunk)
 {
     // status 0 to 1
     queue.EngueueItem(() =>
     {
         PerlinWorldGenerator.CreateChunk(chunk);
         chunk.status = 1;
     });
 }
        public void LoadChunk(int x, int z, bool useQueue)
        {
            System.DateTime genStart = System.DateTime.Now;

            Chunk2 chunk = new Chunk2(this, x, z);

            chunkCollection.Add(x + ":" + z, chunk);

            chunk.pendingStatus = 1;

            Chunk2 n  = GetChunk(chunk.xPosition, chunk.zPosition + 1);
            Chunk2 ne = GetChunk(chunk.xPosition + 1, chunk.zPosition + 1);
            Chunk2 e  = GetChunk(chunk.xPosition + 1, chunk.zPosition);
            Chunk2 se = GetChunk(chunk.xPosition + 1, chunk.zPosition - 1);
            Chunk2 s  = GetChunk(chunk.xPosition, chunk.zPosition - 1);
            Chunk2 sw = GetChunk(chunk.xPosition - 1, chunk.zPosition - 1);
            Chunk2 w  = GetChunk(chunk.xPosition - 1, chunk.zPosition);
            Chunk2 nw = GetChunk(chunk.xPosition - 1, chunk.zPosition + 1);

            if (n != null)
            {
                chunk.ChunkNorth = n;
                n.ChunkSouth     = chunk;
            }

            if (ne != null)
            {
                chunk.ChunkNorthEast = ne;
                ne.ChunkSouthWest    = chunk;
            }

            if (e != null)
            {
                chunk.ChunkEast = e;
                e.ChunkWest     = chunk;
            }

            if (se != null)
            {
                chunk.ChunkSouthEast = se;
                se.ChunkNorthWest    = chunk;
            }

            if (s != null)
            {
                chunk.ChunkSouth = s;
                s.ChunkNorth     = chunk;
            }

            if (sw != null)
            {
                chunk.ChunkSouthWest = sw;
                sw.ChunkNorthEast    = chunk;
            }

            if (w != null)
            {
                chunk.ChunkWest = w;
                w.ChunkEast     = chunk;
            }

            if (nw != null)
            {
                chunk.ChunkNorthWest = nw;
                nw.ChunkSouthEast    = chunk;
            }


            if (useQueue)
            {
                ChunkLoader.GenerateData(chunk);
            }
            else
            {
                PerlinWorldGenerator.CreateChunk(chunk);
                chunk.status = 1;
            }



            chunk.isDataLoaded        = true;
            StatsEngine.ChunkGenTime += (float)System.DateTime.Now.Subtract(genStart).TotalSeconds;
        }