Ejemplo n.º 1
0
    /// <summary>
    /// Saves all chunks currently loaded, if UseMultiThreading is enabled it saves the chunks
    ///  asynchronously and the SaveProgress object returned will show the progress
    /// </summary>
    /// <param name="world">Optional parameter for the world to save chunks for, if left
    /// empty it will use the world Singleton instead</param>
    /// <returns>A SaveProgress object to monitor the save.</returns>
    public static SaveProgress SaveAll(World world = null)
    {
        if (!world)
        {
            world = World.instance;
        }

        //Create a saveprogress object with positions of all the chunks in the world
        //Then save each chunk and update the saveprogress's percentage for each save
        SaveProgress saveProgress = new SaveProgress(world.chunks.Keys);
        List <Chunk> chunksToSave = new List <Chunk>();

        chunksToSave.AddRange(world.chunks.Values);

        if (Config.Toggle.UseMultiThreading)
        {
            Thread thread = new Thread(() =>
            {
                foreach (var chunk in chunksToSave)
                {
                    while (!chunk.GetFlag(Chunk.Flag.terrainGenerated) || chunk.GetFlag(Chunk.Flag.busy))
                    {
                        Thread.Sleep(0);
                    }

                    Serialization.SaveChunk(chunk);

                    saveProgress.SaveCompleteForChunk(chunk.pos);
                }
            });
            thread.Start();
        }
        else
        {
            foreach (var chunk in chunksToSave)
            {
                Serialization.SaveChunk(chunk);
                saveProgress.SaveCompleteForChunk(chunk.pos);
            }
        }

        return(saveProgress);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Saves all chunks currently loaded, if UseMultiThreading is enabled it saves the chunks
    ///  asynchronously and the SaveProgress object returned will show the progress
    /// </summary>
    /// <param name="world">Optional parameter for the world to save chunks for, if left
    /// empty it will use the world Singleton instead</param>
    /// <returns>A SaveProgress object to monitor the save.</returns>
    public static SaveProgress SaveAll(World world = null)
    {
        if (!world)
            world = World.instance;

        //Create a saveprogress object with positions of all the chunks in the world
        //Then save each chunk and update the saveprogress's percentage for each save
        SaveProgress saveProgress = new SaveProgress(world.chunks.Keys);
        List<Chunk> chunksToSave = new List<Chunk>();
        chunksToSave.AddRange(world.chunks.Values);

        if (Config.Toggle.UseMultiThreading)
        {
            Thread thread = new Thread(() =>
           {

               foreach (var chunk in chunksToSave)
               {

                   while (!chunk.terrainGenerated || chunk.busy)
                   {
                       Thread.Sleep(0);
                   }

                   Serialization.SaveChunk(chunk);

                   saveProgress.SaveCompleteForChunk(chunk.pos);
               }
           });
            thread.Start();
        }
        else
        {
            foreach (var chunk in chunksToSave)
            {
                Serialization.SaveChunk(chunk);
                saveProgress.SaveCompleteForChunk(chunk.pos);
            }
        }

        return saveProgress;
    }
Ejemplo n.º 3
0
    public static SaveProgress SaveAll(World world = null)
    {
        if (!world)
        {
            world = World.instance;
        }

        SaveProgress saveProgress = new SaveProgress(world.chunks.Keys);
        List <Chunk> chunksToSave = new List <Chunk>();

        chunksToSave.AddRange(world.chunks.Values);

        if (Config.Toggle.UseMultiThreading)
        {
            Thread thread = new Thread(() =>
            {
                foreach (var chunk in chunksToSave)
                {
                    while (!chunk.terrainGenerated || chunk.busy)
                    {
                        Thread.Sleep(0);
                    }

                    Serialization.SaveChunk(chunk);

                    saveProgress.SaveCompleteForChunk(chunk.pos);
                }
            });
            thread.Start();
        }
        else
        {
            foreach (var chunk in chunksToSave)
            {
                Serialization.SaveChunk(chunk);
                saveProgress.SaveCompleteForChunk(chunk.pos);
            }
        }

        return(saveProgress);
    }
Ejemplo n.º 4
0
    public static SaveProgress SaveAll(World world = null)
    {
        if (!world)
            world = World.instance;

        SaveProgress saveProgress = new SaveProgress(world.chunks.Keys);
        List<Chunk> chunksToSave = new List<Chunk>();
        chunksToSave.AddRange(world.chunks.Values);

        if (Config.Toggle.UseMultiThreading)
        {
            Thread thread = new Thread(() =>
           {

               foreach (var chunk in chunksToSave)
               {

                   while (!chunk.terrainGenerated || chunk.busy)
                   {
                       Thread.Sleep(0);
                   }

                   Serialization.SaveChunk(chunk);

                   saveProgress.SaveCompleteForChunk(chunk.pos);
               }
           });
            thread.Start();
        }
        else
        {
            foreach (var chunk in chunksToSave)
            {
                Serialization.SaveChunk(chunk);
                saveProgress.SaveCompleteForChunk(chunk.pos);
            }
        }

        return saveProgress;
    }