Exemple #1
0
        public void Load(Stream stream)
        {
            objects.Clear();
            Dictionary <int, int> localToGlobal = new Dictionary <int, int>();

            StateFormatter bf     = new StateFormatter();
            int            rootId = (int)bf.Deserialize(stream);

            while (stream.Position < stream.Length - 1)
            {
                StateObject obj = (StateObject)bf.Deserialize(stream);
                StateContainer.SetManager(obj, this);
                obj.AfterDeserialization();

                if (obj.ID == -1)
                {
                    localToGlobal.Add(obj.localID, objects.Add(obj));
                }
                else
                {
                    objects.Add(obj);
                }
            }

            root = objects[rootId] as WorldState;
            objects.Resolve(localToGlobal);

            UpdateDebugInfo();
        }
Exemple #2
0
        public StateObject Clone()
        {
            // simple clone value type members
            StateObject obj = this.MemberwiseClone() as StateObject;

            Type type = obj.GetType();

            // state link lists need to be cloned manually
            FieldInfo[] infos = type.GetFields(BindingFlags.Default | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            foreach (FieldInfo info in infos)
            {
                if (typeof(IStateLinkList).IsAssignableFrom(info.FieldType) &&
                    typeof(ICloneable).IsAssignableFrom(info.FieldType))
                {
                    ICloneable list = (ICloneable)info.GetValue(obj);
                    // clone if non-null
                    if (list != null)
                    {
                        info.SetValue(obj, list.Clone());
                    }
                }
            }

            StateContainer.SetManager(obj, container);
            // run custom after deserialization/clone initializing
            obj.AfterDeserialization();

            return(obj);
        }
Exemple #3
0
 void SetContainerLinks(StateObject obj)
 {
     StateContainer.SetManager(obj, this);
 }