예제 #1
0
    // Builds Chunk's VoxelData using Decompression algorithm
    public static void DecompressBlocks(Chunk c, byte[] buffer)
    {
        // Preparation Variables
        Pallete       p           = Compression.BiomeToPallete(c.biomeName);
        List <ushort> palleteList = Compression.GetPallete(p);

        NativeArray <ushort> data     = new NativeArray <ushort>(Chunk.chunkWidth * Chunk.chunkWidth * Chunk.chunkDepth, Allocator.TempJob);
        NativeArray <byte>   readData = new NativeArray <byte>(buffer, Allocator.TempJob);
        NativeArray <ushort> pallete  = new NativeArray <ushort>(palleteList.ToArray(), Allocator.TempJob);

        DecompressJob dbJob = new DecompressJob {
            data     = data,
            readData = readData,
            pallete  = pallete
        };
        JobHandle job = dbJob.Schedule();

        job.Complete();

        c.data.SetData(data.ToArray());


        data.Dispose();
        readData.Dispose();
        pallete.Dispose();
    }
예제 #2
0
    // Writes Chunk c's data using a Pallete's compression into given buffer
    // and returns the amount of bytes written
    public static int CompressBlocks(Chunk c, byte[] buffer)
    {
        int           bytes;
        Pallete       p           = Compression.BiomeToPallete(c.biomeName);
        List <ushort> palleteList = Compression.GetPallete(p);


        NativeArray <int> writtenBytes = new NativeArray <int>(new int[1] {
            0
        }, Allocator.TempJob);
        NativeArray <ushort> chunkData    = new NativeArray <ushort>(c.data.GetData(), Allocator.TempJob);
        NativeArray <byte>   buff         = new NativeArray <byte>(buffer, Allocator.TempJob);
        NativeArray <ushort> palleteArray = new NativeArray <ushort>(palleteList.ToArray(), Allocator.TempJob);

        CompressionJob cbJob = new CompressionJob {
            chunkData    = chunkData,
            buffer       = buff,
            palleteArray = palleteArray,
            writtenBytes = writtenBytes
        };

        JobHandle handle = cbJob.Schedule();

        handle.Complete();

        // NativeArray to Array convertion
        buff.CopyTo(buffer);

        bytes = writtenBytes[0];

        chunkData.Dispose();
        palleteArray.Dispose();
        buff.Dispose();
        writtenBytes.Dispose();

        return(bytes);
    }