Beispiel #1
0
        public void Synchronize(bool resetChangeRecord)
        {
            if (resetChangeRecord)
            {
                if (added.Count != 0)
                {
                    throw new BurntimeLogicException(); // DEBUG
                }
                // swap change record
                changeRecord.Dequeue();

                // garbage collection
                changeRecord.Add(objects.CollectGarbage(root, externalReferences));

                // save back up
                syncCopy = objects.Clone();
            }

            objects.Add(added, externalReferences);
            added.Clear();

            if (!resetChangeRecord)
            {
                changeRecord.Add(objects.Compare(syncCopy));
            }

            UpdateDebugInfo();
        }
Beispiel #2
0
        public T Create <T>(StateObjectOptions options, params object[] parameter) where T : StateObject
        {
            if ((options & StateObjectOptions.Temporary) == StateObjectOptions.Temporary &&
                (options & StateObjectOptions.PlayerRelative) == StateObjectOptions.PlayerRelative)
            {
                throw new BurntimeLogicException();
            }

            if ((options & StateObjectOptions.PlayerRelative) == StateObjectOptions.PlayerRelative)
            {
                PlayerRelativeStateLink <T> state = new PlayerRelativeStateLink <T>();
                added.Add(state);

                for (int i = 0; i < Root.Player.Length; i++)
                {
                    T obj = (T)Activator.CreateInstance(typeof(T));
                    obj.container = this;
                    added.Add(obj);
                    state.Add(obj);
                }

                UpdateDebugInfo();

                return(state);
            }
            else
            {
                StateObject obj = (StateObject)Activator.CreateInstance(typeof(T));
                obj.container = this;
                if ((options & StateObjectOptions.Temporary) != StateObjectOptions.Temporary && !temporaryMode)
                {
                    added.Add(obj);
                    UpdateDebugInfo();
                }

                bool old = temporaryMode;
                temporaryMode |= (options & StateObjectOptions.Temporary) == StateObjectOptions.Temporary;
                obj.InitInstance(parameter);
                temporaryMode = old;
                return((T)obj);
            }
        }