Esempio n. 1
0
        protected override void TransferChunk(MegaChunk chunk, Action transferCompleteFn)
        {
            if (chunk.Handle.SkipChunks)
            {
                transferCompleteFn(); return;
            }
            var wc = new WebClient();

            wc.Proxy = transport.Proxy;
            chunk.Handle.ChunkTransferStarted(wc);
            wc.UploadDataCompleted += (s, e) =>
            {
                chunk.Handle.ChunkTransferEnded(wc);
                transferCompleteFn();
                if (e.Cancelled)
                {
                    return;
                }
                if (e.Error != null)
                {
                    chunk.Handle.BytesTransferred(0 - chunk.transferredBytes);
                    EnqueueTransfer(new List <MegaChunk> {
                        chunk
                    }, true);
                }
                else
                {
                    OnUploadedChunk(chunk, e);
                }
            };
            wc.UploadProgressChanged += (s, e) => OnUploadedBytes(chunk, e.BytesSent);
            var url = String.Format(((UploadHandle)chunk.Handle).UploadUrl + "/{0}", chunk.Offset);

            wc.UploadDataAsync(new Uri(url), chunk.Data);
        }
Esempio n. 2
0
        protected void OnUploadedBytes(MegaChunk chunk, long bytes)
        {
            var delta = bytes - chunk.transferredBytes;

            chunk.transferredBytes = bytes;
            chunk.Handle.BytesTransferred(delta);
        }
Esempio n. 3
0
        private void OnUploadedChunk(MegaChunk chunk, UploadDataCompletedEventArgs e)
        {
            chunk.ClearData();

            chunk.Handle.chunksProcessed++;
            if (chunk.Handle.chunksProcessed == chunk.Handle.Chunks.Count)
            {
                Util.StartThread(() =>
                {
                    var uploadHandle = Encoding.UTF8.GetString(e.Result);
                    FinishFile((UploadHandle)chunk.Handle, uploadHandle);
                }, "transfer_finish_file");
            }
        }
Esempio n. 4
0
    private Mesh HexChunk(Vector3 position, MegaChunk chunk)
    {
        List <Mesh> hexChunk = new List <Mesh>();

        for (int i = 0; i < MeshComponents.chunkSize * MeshComponents.chunkSize; i++)
        {
            Mesh hex = new Mesh();

            Vector3[] vertices = originMesh.vertices;

            float2 position2D = Get2DPositionFromIndex(i, MeshComponents.chunkSize);

            float y = GenerateHeight(position2D.x - (MeshComponents.chunkSize / 2) + chunk.center.x, position2D.y - (MeshComponents.chunkSize / 2) + chunk.center.z); //chunk.y is always zero

            Vector3 buildPosition = new Vector3(position2D.x - (MeshComponents.chunkSize / 2), math.floor(y - chunk.center.y), position2D.y - (MeshComponents.chunkSize / 2));

            for (int j = 0; j < vertices.Length; j++)
            {
                vertices[j] += buildPosition;
            }

            hex.vertices  = vertices;
            hex.uv        = originMesh.uv;
            hex.normals   = originMesh.normals;
            hex.triangles = originMesh.triangles;
            hex.RecalculateBounds();

            hexChunk.Add(hex);
        }

        CombineInstance[] array = new CombineInstance[hexChunk.Count];


        for (int i = 0; i < array.Length; i++)
        {
            array[i].mesh = hexChunk[i];
        }

        Mesh hexTile = new Mesh();

        //since our cubes are created on the correct spot already, we dont need a matrix, and so far, no light data
        hexTile.CombineMeshes(array, true, false, false);
        hexTile.Optimize();
        return(hexTile);
    }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //SpawnCubes spawncubesJob = new SpawnCubes
        //{
        //    archetype = archetype,
        //    chunk = MeshComponents.chunkSize,
        //    commandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(),
        //    output =
        //};
        //inputDeps = spawncubesJob.Schedule(this, inputDeps);

        NativeArray <MegaChunk> megaChunks = m_Query.ToComponentDataArray <MegaChunk>(Allocator.TempJob);

        for (int i = 0; i < megaChunks.Length; i++)
        {
            MegaChunk chunk = megaChunks[i];
            if (megaChunks[i].spawnCubes)
            {
                SpawnCubesParallel spawnCubesParallel = new SpawnCubesParallel
                {
                    archetype     = archetype,
                    chunk         = MeshComponents.chunkSize,
                    commandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(),
                    input         = chunk,
                    chunkSize     = MeshComponents.chunkSize
                };

                inputDeps = spawnCubesParallel.Schedule(MeshComponents.chunkSize * MeshComponents.chunkSize, 8, inputDeps);

                endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(inputDeps);
            }
        }
        SetUpdateCubes setCubeUpdateJob = new SetUpdateCubes
        {
            shouldDraw = false
        };

        inputDeps = setCubeUpdateJob.Schedule(this, inputDeps);

        megaChunks.Dispose();

        return(inputDeps);
    }
Esempio n. 6
0
        protected override void TransferChunk(MegaChunk chunk, Action transferCompleteFn)
        {
            if (chunk.Handle.SkipChunks)
            {
                transferCompleteFn(); return;
            }
            var wc = new WebClient();

            wc.Proxy = transport.Proxy;
            chunk.Handle.ChunkTransferStarted(wc);
            wc.DownloadDataCompleted += (s, e) =>
            {
                transferCompleteFn();
                chunk.Handle.ChunkTransferEnded(wc);
                if (e.Cancelled)
                {
                    return;
                }
                if (e.Error != null)
                {
                    chunk.Handle.BytesTransferred(0 - chunk.transferredBytes);
                    chunk.transferredBytes = 0;
                    EnqueueTransfer(new List <MegaChunk> {
                        chunk
                    }, true);
                }
                else
                {
                    chunk.Data = e.Result;
                    EnqueueCrypt(new List <MegaChunk> {
                        chunk
                    });
                }
            };
            wc.DownloadProgressChanged += (s, e) => OnDownloadedBytes(chunk, e.BytesReceived);
            var url = ((DownloadHandle)chunk.Handle).DownloadUrl;

            url += String.Format("/{0}-{1}", chunk.Offset, chunk.Offset + chunk.Size - 1);
            wc.DownloadDataAsync(new Uri(url));
        }
Esempio n. 7
0
        protected override void CryptChunk(MegaChunk chunk)
        {
            var data = chunk.Data;
            var hndl = chunk.Handle;

            chunk.Mac = Crypto.DecryptCtr(chunk.Handle.AesAlg, data, chunk.Handle.Nonce, chunk.Offset);
            lock (streamLock)
            {
                hndl.Stream.Seek(chunk.Offset, SeekOrigin.Begin);
                hndl.Stream.Write(data, 0, chunk.Size);
            }
            hndl.chunksProcessed++;
            chunk.ClearData();

            if (chunk.Handle.chunksProcessed == chunk.Handle.Chunks.Count)
            {
                Util.StartThread(() =>
                {
                    FinishFile((DownloadHandle)chunk.Handle);
                }, "transfer_finish_file");
            }
        }
Esempio n. 8
0
        protected override void CryptChunk(MegaChunk chunk)
        {
            byte[] data = new byte[chunk.Size];
            var    hndl = chunk.Handle;

            try
            {
                lock (streamLock)
                {
                    hndl.Stream.Seek(chunk.Offset, SeekOrigin.Begin);
                    hndl.Stream.Read(data, 0, data.Length);
                }
            }
            catch
            {
                hndl.CancelTransfer(MegaApiError.ESYSTEM);
                return;
            }
            chunk.Mac  = Crypto.EncryptCtr(chunk.Handle.AesAlg, data, chunk.Handle.Nonce, chunk.Offset);
            chunk.Data = data;
            EnqueueTransfer(new List <MegaChunk> {
                chunk
            });
        }
Esempio n. 9
0
 protected abstract void CryptChunk(MegaChunk chunk);
Esempio n. 10
0
 protected abstract void TransferChunk(MegaChunk megaChunk, Action transferCompleteFn);