Ejemplo n.º 1
0
        public virtual void DeserializeWorldSaveData(BinaryReader r)
        {
            string        key;
            ISerializable obj;

            int version = r.ReadInt32();

            m_DeactivationTime = r.ReadDouble();
            int metaCount = r.ReadInt32();

            Meta.Clear();
            for ( ; metaCount > 0; metaCount--)
            {
                key = r.ReadString();
                obj = (ISerializable)GlobalActivator.CreateInstance(r.ReadString());
                obj.Deserialize(r);
                Meta.Add(key, obj);
            }
        }
Ejemplo n.º 2
0
        public static void Load(string path)
        {
            int                count, index, objMap;
            string             key;
            ISerializable      metaObj;
            bool               isActive;
            uint               uid;
            List <BaseGameMap> mapIndex   = new List <BaseGameMap>();
            List <string>      classIndex = new List <string>();
            BaseGameObject     obj;
            BaseGameMap        map;

            m_IsLoading = true;
            try {
                using (BinaryReader r = new BinaryReader(new FileStream(path, FileMode.Open))) {
                    lock (Objects) {
                        if (r.ReadInt32() != 0x1F3EA7D2)
                        {
                            throw new UserFriendlyException("World save file is either corupt or is of unsupported format", "Failed to load world");
                        }

                        Clear();
                        // ActiveMaps = new List<BaseGameMap>(); // map activation is not implemented yet

                        int version = r.ReadInt32();
                        Time.Deserialize(r);
                        Rnd.Deserialize(r);
                        // NextUID = r.ReadUInt32();

                        // load world meta data
                        count = r.ReadInt32();
                        for ( ; count > 0; count--)
                        {
                            key     = r.ReadString();
                            metaObj = (ISerializable)GlobalActivator.CreateInstance(r.ReadString());
                            metaObj.Deserialize(r);
                            Meta.Add(key, metaObj);
                        }

                        // load map specific data and map index
                        // this will crash if any map changed class or was removed from the map database.
                        count = r.ReadInt32();
                        for ( ; count > 0; count--)
                        {
                            key      = r.ReadString();
                            isActive = r.ReadBoolean();
                            map      = m_Maps[key];
                            mapIndex.Add(map);
                            // if( isActive )
                            // ActiveMaps.Add(map); // we might need to deactivate since new maps that are not in save will get deactivated because array is recreated
                            map.DeserializeWorldSaveData(r);
                        }

                        // load object class index
                        count = r.ReadInt32();
                        for ( ; count > 0; count--)
                        {
                            key = r.ReadString();
                            classIndex.Add(key);
                            // GameDebugger.Log("{0}", key);
                        }

                        // load object index
                        count = r.ReadInt32();
                        // GameDebugger.Log("Objects: {0}", count);
                        for ( ; count > 0; count--)
                        {
                            uid    = r.ReadUInt32();
                            index  = r.ReadInt32();
                            objMap = r.ReadInt32();
                            obj    = (BaseGameObject)GlobalActivator.CreateInstance(classIndex[index], uid);
                            obj.OnBeforeLoadInternal();
                            obj.m_BaseGameMap = (objMap == 0) ? null : mapIndex[objMap - 1];
                            AddObject(obj);
                        }

                        count = Objects.Count;
                        for ( ; count > 0; count--)
                        {
                            uid      = r.ReadUInt32();
                            isActive = r.ReadBoolean();
                            obj      = Objects[uid];
                            obj.Deserialize(r);
                            if (isActive)
                            {
                                ActivateObject(obj);
                            }
                        }
                    }
                }

                foreach (BaseGameObject eobj in Objects.Values)
                {
                    eobj.OnAfterLoadInternal();
                }
            }
            finally {
                m_IsLoading = false;
            }
        }