// Loads a chunk information from RDF file using Pallete-based Decompression
    public void LoadChunk(Chunk c)
    {
        byte biome     = 0;
        byte gen       = 0;
        int  blockdata = 0;
        int  hpdata    = 0;
        int  statedata = 0;

        GetCorrectRegion(c.pos);

        ReadHeader(c.pos);
        InterpretHeader(ref biome, ref gen, ref blockdata, ref hpdata, ref statedata);

        c.biomeName       = BiomeHandler.ByteToBiome(biome);
        c.lastVisitedTime = globalTime.DateBytes(timeArray);
        c.needsGeneration = gen;

        this.pool[ConvertToRegion(c.pos)].file.Read(blockBuffer, 0, blockdata);
        this.pool[ConvertToRegion(c.pos)].file.Read(hpBuffer, 0, hpdata);
        this.pool[ConvertToRegion(c.pos)].file.Read(stateBuffer, 0, statedata);

        Compression.DecompressBlocks(c, blockBuffer);
        Compression.DecompressMetadataHP(c, hpBuffer);
        Compression.DecompressMetadataState(c, stateBuffer);
    }
Beispiel #2
0
    // Loads the chunk into the Chunkloader
    private void LoadChunk()
    {
        if (toLoad.Count > 0)
        {
            int min;

            // Sets the current iteration amount
            if (3 <= toLoad.Count)
            {
                min = 3;
            }
            else
            {
                min = toLoad.Count;
            }

            for (int i = 0; i < min; i++)
            {
                byte[] data = toLoad[0];

                int headerSize = RegionFileHandler.chunkHeaderSize;

                ChunkPos cp = NetDecoder.ReadChunkPos(data, 1);

                // Prevention
                if (this.chunks.ContainsKey(cp))
                {
                    this.chunks[cp].Destroy();
                    this.chunks.Remove(cp);
                }


                int blockDataSize = NetDecoder.ReadInt(data, 9);
                int hpDataSize    = NetDecoder.ReadInt(data, 13);
                int stateDataSize = NetDecoder.ReadInt(data, 17);

                this.chunks[cp]           = new Chunk(cp, this.rend, this.blockBook, this);
                this.chunks[cp].biomeName = BiomeHandler.ByteToBiome(data[21]);

                Compression.DecompressBlocksClient(this.chunks[cp], data, initialPos: 21 + headerSize);
                Compression.DecompressMetadataHPClient(this.chunks[cp], data, initialPos: 21 + headerSize + blockDataSize);
                Compression.DecompressMetadataStateClient(this.chunks[cp], data, initialPos: 21 + headerSize + blockDataSize + hpDataSize);

                if (this.vfx.data.ContainsKey(cp))
                {
                    this.vfx.RemoveChunk(cp);
                }

                this.vfx.NewChunk(cp);

                if (!this.toDraw.Contains(cp))
                {
                    this.toDraw.Add(cp);
                }

                toLoad.RemoveAt(0);
                toLoadChunk.RemoveAt(0);
            }
        }
    }