Beispiel #1
0
        /// <summary>
        /// <see cref="IGZipStrategy.Read"/>
        /// </summary>
        public void Read(FileStream inputStream, ChunkQueue queueReader)
        {
            var diff      = inputStream.Length - inputStream.Position;
            var bytesRead = diff <= Config.ChunkSize ? (int)diff : Config.ChunkSize;

            var lastBuffer = new byte[bytesRead];

            inputStream.Read(lastBuffer, 0, bytesRead);
            queueReader.Enqueue(lastBuffer);
        }
Beispiel #2
0
        public void AddToUnload(Chunk chunk)
        {
            if (!LoadQueue.Contains(chunk))
            {
                UnloadQueue.Enqueue(chunk);
            }

            LoadQueue.Remove(chunk);
            GenerationQueue.Remove(chunk);
            VegetationQueue.Remove(chunk);
        }
 void QueueChunk(int cx, int cy, int cz, ChunkQueue queue)
 {
     if (cx >= 0 && cy >= 0 && cz >= 0 && cx < chunksX && cy < chunksY && cz < chunksZ)
     {
         ChunkInfo info = unsortedChunks[cx + chunksX * (cy + cz * chunksY)];
         if (!info.Visited)
         {
             queue.Enqueue(info);
         }
         info.Visited = true;
     }
 }
Beispiel #4
0
        /// <summary>
        /// <see cref="IGZipStrategy.Handle"/>
        /// </summary>
        public void Handle(KeyValuePair <int, byte[]> chunk, ChunkQueue queueWriter)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (GZipStream cs = new GZipStream(memoryStream, CompressionMode.Compress))
                {
                    cs.Write(chunk.Value, 0, chunk.Value.Length);
                    cs.Flush();
                }

                byte[] compresData = memoryStream.ToArray();
                var    _out        = new KeyValuePair <int, byte[]>(chunk.Key, compresData);
                queueWriter.Enqueue(_out);
            }
        }
Beispiel #5
0
        public void AddToUnload(Chunk chunk)
        {
            if (!LoadQueue.Contains(chunk))
            {
                UnloadQueue.Enqueue(chunk);
            }

            LoadQueue.Remove(chunk);
            GenerationQueue.Remove(chunk);
            VegetationQueue.Remove(chunk);
            BuildQueue.Remove(chunk);
            SetupQueue.Remove(chunk);

            chunk.WillBeUnloaded = true;
        }
Beispiel #6
0
        /// <summary>
        /// <see cref="IGZipStrategy.Read"/>
        /// </summary>
        public void Read(FileStream inputStream, ChunkQueue queueReader)
        {
            var bufLenght = new byte[8];

            inputStream.Read(bufLenght, 0, bufLenght.Length);
            var chunkLenght = BitConverter.ToInt32(bufLenght, 4);

            byte[] compresData = new byte[chunkLenght];
            bufLenght.CopyTo(compresData, 0);
            inputStream.Read(compresData, 8, chunkLenght - 8);

            var chunk = new KeyValuePair <int, byte[]>(counter, compresData);

            queueReader.Enqueue(chunk);
            counter++;
        }
Beispiel #7
0
        /// <summary>
        /// <see cref="IGZipStrategy.Handle"/>
        /// </summary>
        public void Handle(KeyValuePair <int, byte[]> chunk, ChunkQueue queueWriter)
        {
            var dataSize   = BitConverter.ToInt32(chunk.Value, chunk.Value.Length - 4);
            var lastBuffer = new byte[dataSize];

            using (MemoryStream ms = new MemoryStream(chunk.Value))
            {
                using (GZipStream _gz = new GZipStream(ms, CompressionMode.Decompress))
                {
                    var keyVal = new KeyValuePair <int, byte[]>(chunk.Key, lastBuffer);
                    _gz.Read(keyVal.Value, 0, keyVal.Value.Length);
                    var decompressedData = keyVal.Value.ToArray();
                    var chunkDec         = new KeyValuePair <int, byte[]>(keyVal.Key, decompressedData);
                    queueWriter.Enqueue(chunkDec);
                }
            }
        }
 void QueueChunk( int cx, int cy, int cz, ChunkQueue queue )
 {
     if( cx >= 0 && cy >= 0 && cz >= 0 && cx < chunksX && cy < chunksY && cz < chunksZ ) {
         ChunkInfo info = unsortedChunks[cx + chunksX * (cy + cz * chunksY)];
         if( !info.Visited )
             queue.Enqueue( info );
         info.Visited = true;
     }
 }
Beispiel #9
0
        public void Run()
        {
            Chunk currentChunk;

            while (true)
            {
                if (!Variables.Game.IsInitialized)
                {
                    continue;
                }

                if (UnloadQueue.Count > 0)
                {
                    currentChunk = UnloadQueue.Dequeue();

                    if (currentChunk == null)
                    {
                        continue;
                    }

                    // Unload Chunk
                    if (Constants.World.SaveDynamicWorld)
                    {
                        ChunkManager.StoreChunkImmediate(currentChunk);
                    }
                    else
                    {
                        currentChunk = null;
                    }
                    Console.Write("UnloadQueue: " + UnloadQueue.Count);

                    // End Unload Chunk

                    LoadQueue.Remove(currentChunk);
                    GenerationQueue.Remove(currentChunk);
                    SetupQueue.Remove(currentChunk);
                }
                else if (LoadQueue.Count > 0)
                {
                    currentChunk = LoadQueue.Dequeue();

                    if (currentChunk == null)
                    {
                        continue;
                    }

                    // Load Chunk

                    ChunkManager.LoadChunkImmediate(currentChunk);
                    currentChunk.BuildOctree();
                    currentChunk.HasData = true;

                    Console.Write("LoadQueue: " + LoadQueue.Count);

                    // End Load Chunk

                    if (SetupQueue.Contains(currentChunk))
                    {
                        SetupQueue.Remove(currentChunk);
                        SetupQueue.Enqueue(currentChunk);
                    }
                    else
                    {
                        SetupQueue.Enqueue(currentChunk);
                    }
                }
                else if (GenerationQueue.Count > 0)
                {
                    currentChunk = GenerationQueue.Dequeue();

                    if (currentChunk == null)
                    {
                        continue;
                    }

                    // Generate Chunk

                    TerrainGenerator.SetChunkTerrain(currentChunk);

                    Console.Write("GenerationQueue: " + GenerationQueue.Count);

                    // End Generate Chunk

                    if (VegetationQueue.Contains(currentChunk))
                    {
                        VegetationQueue.Remove(currentChunk);
                        VegetationQueue.Enqueue(currentChunk);
                    }
                    else
                    {
                        AddToVegetation(currentChunk);
                    }
                }
                else if (VegetationQueue.Count > 0)
                {
                    currentChunk = VegetationQueue.Dequeue();

                    if (currentChunk == null)
                    {
                        continue;
                    }

                    // Vegetate Chunk

                    Vegetation.Vegetate(currentChunk);

                    Console.Write("VegetationQueue: " + VegetationQueue.Count);

                    // End Vegetate Chunk

                    if (BuildQueue.Contains(currentChunk))
                    {
                        BuildQueue.Remove(currentChunk);
                        BuildQueue.Enqueue(currentChunk);
                    }
                    else
                    {
                        AddToBuild(currentChunk);
                    }

                    if (VegetationQueue.Count == 0 && !Constants.Engines.Physics.Player.IsReleased)
                    {
                        Constants.Engines.Physics.Player.Release();
                    }
                }
                else if (BuildQueue.Count > 0)
                {
                    currentChunk = BuildQueue.Dequeue();

                    if (currentChunk == null)
                    {
                        continue;
                    }

                    // Build Chunk

                    currentChunk.BuildOctree();
                    currentChunk.HasData = true;

                    Console.Write("BuildQueue: " + BuildQueue.Count);

                    // End Build Chunk

                    if (SetupQueue.Contains(currentChunk))
                    {
                        SetupQueue.Remove(currentChunk);
                        SetupQueue.Enqueue(currentChunk);
                    }
                    else
                    {
                        AddToSetup(currentChunk);
                    }
                }
                else if (SetupQueue.Count > 0)
                {
                    currentChunk = SetupQueue.Dequeue();

                    if (currentChunk == null)
                    {
                        continue;
                    }
                    currentChunk.SetupState = 4;

                    // Setup Chunk

                    currentChunk.BuildGeometry(false);
                    currentChunk.SetupState = 1;

                    Console.Write("SetupQueue: " + SetupQueue.Count);
                    // End Setup Chunk
                }
            }
        }
Beispiel #10
0
 public void AddToBuild(Chunk chunk)
 {
     BuildQueue.Enqueue(chunk);
 }
Beispiel #11
0
 public void AddToVegetation(Chunk chunk)
 {
     VegetationQueue.Enqueue(chunk);
 }
Beispiel #12
0
 public void AddToGeneration(Chunk chunk)
 {
     GenerationQueue.Enqueue(chunk);
 }
Beispiel #13
0
 public void AddToLoad(Chunk chunk)
 {
     LoadQueue.Enqueue(chunk);
 }