Ejemplo n.º 1
0
 private void Deserialize(byte mask, FileStream stream)
 {
     for (int i = 0; i < 4; ++i)
     {
         byte childMask = (byte)(1 << i);
         if ((mask & childMask) > 0)
         {
             Children[i] = new QuadTreeNodeSerializable(stream);
         }
         else
         {
             Children[i] = new QuadTreeLeafSerializable(stream);
         }
     }
 }
Ejemplo n.º 2
0
        public static bool SaveData(string path, PillarSetting setting, QuadTreeBase[] trees)
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            FileStream stream = File.Open(path, FileMode.Create);

            byte[] stbuff = setting.ToArray();
            stream.Write(stbuff, 0, stbuff.Length);
            //trees
            byte[] bRootLeafBuff = new byte[1] {
                1 << 4
            };
            for (int x = 0; x < setting.maxX; ++x)
            {
                for (int z = 0; z < setting.maxZ; ++z)
                {
                    QuadTreeBase subTree = trees[x * setting.maxZ + z];
                    if (subTree is QuadTreeLeafSerializable)
                    {
                        stream.Write(bRootLeafBuff, 0, 1);
                        QuadTreeLeafSerializable leaf = (QuadTreeLeafSerializable)subTree;
                        leaf.Serialize(stream);
                    }
                    else
                    {
                        QuadTreeNodeSerializable node = (QuadTreeNodeSerializable)subTree;
                        node.Serialize(stream);
                    }
                }
            }
            stream.Close();
            MPLog.Log("create data successed!");
            return(true);
        }