Ejemplo n.º 1
0
    public static ChunkSaver Open(string path)
    {
        ChunkSaver saver = new ChunkSaver()
        {
            savePath   = path,
            fileStream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite),
        };

        saver.fileStream.Seek(0, SeekOrigin.Begin);
        byte[] buffer = new byte[16];
        saver.fileStream.Read(buffer, 0, 4);
        int v = System.BitConverter.ToInt32(buffer, 0);

        if (v != version)
        {
            Debug.LogError("incorrect save file");
            return(null);
        }
        saver.fileStream.Read(buffer, 0, 12);
        saver.sizeX = System.BitConverter.ToInt32(buffer, 0);
        saver.sizeY = System.BitConverter.ToInt32(buffer, 4);
        saver.sizeZ = System.BitConverter.ToInt32(buffer, 8);
        Debug.Log("Open save file " + path);
        return(saver);
    }
Ejemplo n.º 2
0
    public static ChunkSaver Create(string path, int sizeX, int sizeY, int sizeZ)
    {
        ChunkSaver saver = new ChunkSaver
        {
            savePath   = path,
            fileStream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite),
            sizeX      = sizeX,
            sizeY      = sizeY,
            sizeZ      = sizeZ,
        };

        saver.fileStream.Write(System.BitConverter.GetBytes(ChunkSaver.version), 0, 4);
        saver.fileStream.Write(System.BitConverter.GetBytes(sizeX), 0, 4);
        saver.fileStream.Write(System.BitConverter.GetBytes(sizeY), 0, 4);
        saver.fileStream.Write(System.BitConverter.GetBytes(sizeZ), 0, 4);
        saver.fileStream.Seek(saver.headerSize0, SeekOrigin.Begin);
        for (int x = 0; x < sizeX; ++x)
        {
            for (int y = 0; y < sizeY; ++y)
            {
                for (int z = 0; z < sizeZ; ++z)
                {
                    saver.fileStream.Write(System.BitConverter.GetBytes(0), 0, 4);
                    saver.fileStream.Write(System.BitConverter.GetBytes(0), 0, 4);
                }
            }
        }
        Debug.Log("Create new save file " + path);
        return(saver);
    }
Ejemplo n.º 3
0
        public async Task SaveChunk(IChunk chunk)
        {
            await ChunkSaver.SaveFile(Destination, chunk.Start, chunk.Data);

            if (ChunkSaved != null)
            {
                ChunkSaved.Invoke(this, chunk);
            }
        }
Ejemplo n.º 4
0
        public FileDownload(string sourceLink, string destination)
        {
            SourceLink = sourceLink;
            Destination = CleanFilename(destination);
            

            ChunkDownloader = new HttpChunkedDownloader() { Url = sourceLink };
            ChunkSaver = new ChunkSaver();

            Complete = false;
        }
Ejemplo n.º 5
0
        public async Task <IChunk> DownloadChunk()
        {
            var chunkInfo = await ChunkSaver.GetNextEmptyChunk(Destination);

            var checkedChunkInfo = new ChunkInfo(
                chunkInfo.Start,
                Math.Min(ChunkLength, chunkInfo.Length)
                );
            var chunk = await ChunkDownloader.DownloadChunk(checkedChunkInfo);

            return(chunk);
        }
Ejemplo n.º 6
0
        public FileDownload(string sourceLink, string destination)
        {
            SourceLink  = sourceLink;
            Destination = CleanFilename(destination);


            ChunkDownloader = new HttpChunkedDownloader()
            {
                Url = sourceLink
            };
            ChunkSaver = new ChunkSaver();

            Complete = false;
        }
Ejemplo n.º 7
0
 public void Load(ChunkSaver chunkSaver)
 {
     blocks = new Block[chunkSizeX, chunkSizeY, chunkSizeZ];
     for (int i = 0; i < chunkSizeX; i++)
     {
         for (int j = 0; j < chunkSizeY; j++)
         {
             for (int k = 0; k < chunkSizeZ; k++)
             {
                 if (j <= (i + k) / 5 && worldY == 0)
                 {
                     blocks[i, j, k] = Block.CreateBlockByID(1);
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
 void Start()
 {
     BlockProtoTypeAssigner.Assign();
     chunkSaver = ChunkSaver.Create("test.save", worldSizeX, worldSizeY, worldSizeZ);
     chunks     = new Chunk[worldSizeX, worldSizeY, worldSizeZ];
     for (int i = 0; i < worldSizeX; ++i)
     {
         for (int j = 0; j < worldSizeY; ++j)
         {
             for (int k = 0; k < worldSizeZ; ++k)
             {
                 chunks[i, j, k] = Chunk.CreateChunkInstance(this, i, j, k);
                 chunks[i, j, k].Load(chunkSaver);
             }
         }
     }
 }
Ejemplo n.º 9
0
 public async void Initialise()
 {
     ChunkSaver = new ChunkSaver();
     CreateResource();
     await CleanupDirectory();
 }
Ejemplo n.º 10
0
        public async Task <int> GetBytesSavedCount()
        {
            var count = await ChunkSaver.GetBytesSavedCount(Destination);

            return(count);
        }
Ejemplo n.º 11
0
        public async Task <Stream> GetCompleteFileStream()
        {
            var stream = await ChunkSaver.CreateCombinedStream(Destination);

            return(stream);
        }
Ejemplo n.º 12
0
 public void Save(ChunkSaver chunkSaver)
 {
 }