Beispiel #1
0
        bool loadDatabase()
        {
            Info.print("Loading game world: {0}", myFilename);
            if (File.Exists(myFilename) == false)
            {
                Error.print("Unable to find game world {0}", myFilename);
                return(true);
            }

            using (BinaryReader reader = new BinaryReader(File.Open(myFilename, FileMode.Open)))
            {
                //read the header
                Char[] fileType = reader.ReadChars(4);
                if (fileType[0] != 'O' ||
                    fileType[1] != 'C' ||
                    fileType[2] != 'T' ||
                    fileType[3] != 'A')
                {
                    return(false);
                }

                int version = reader.ReadInt32();
                if (version != 1)
                {
                    return(false);
                }

                int indexCount = reader.ReadInt32();
                Info.print("Reading {0} chunk records", indexCount);

                for (int i = 0; i < indexCount; i++)
                {
                    ChunkCache ti = new ChunkCache();
                    UInt64     id = reader.ReadUInt64();
                    ti.byteCount     = reader.ReadInt32();
                    ti.compresedData = reader.ReadBytes(ti.byteCount);
                    myCacheDb[id]    = ti;

                    //update metric
                    sizeInBytes += ti.byteCount;
                    chunkCount++;
                }

                Info.print("Done");
            }

            return(true);
        }
Beispiel #2
0
        public Chunk findChunk(UInt64 id)
        {
            Chunk chunk = null;

            ChunkCache ti = null;

            if (myCacheDb.TryGetValue(id, out ti) == false) // is it loaded, but compressed?
            {
                return(null);                               //this means that the generator needs to create it
            }
            else //decompress it
            {
                chunk          = new Chunk(Vector3.Zero);
                chunk.chunkKey = new ChunkKey(id);
                if (ti.byteCount != 0)
                {
                    byte[] data = decompressChunk(ti.compresedData);
                    chunk.deserialize(data);
                }
            }

            return(chunk);
        }