///Discard all cmd between [0,maxVerifiedTick] (Include maxVerifiedTick)
        public void Clean(uint maxVerifiedTick)
        {
#if DEBUG_SIMPLE_CHECK
#else
            return;

            if (_head == null || _head.Tick > maxVerifiedTick)
            {
                return;
            }

            var newHead = _head;
            while (newHead.next != null && newHead.next.Tick <= maxVerifiedTick)
            {
                newHead = newHead.next;
            }

            if (newHead.next == null)
            {
                _tail = null;
                _head = null;
            }
            else
            {
                _head = newHead.next;
                //断开链接
                _head.pre    = null;
                newHead.next = null;
            }
#endif
        }
 public CommandNode(uint tick, ICommand <T> cmd, CommandNode pre = null, CommandNode next = null)
 {
     this.Tick = tick;
     this.cmd  = cmd;
     this.pre  = pre;
     this.next = next;
 }
        public void Execute(uint tick, ICommand <T> cmd)
        {
#if DEBUG_SIMPLE_CHECK
            var iTick = (int)tick;
            for (int i = allCmds.Count; i <= iTick; i++)
            {
                allCmds.Add(null);
            }

            cmd.Do(_param);
            var node = new CommandNode(tick, cmd, _tail, null);
            allCmds[iTick] = node;
#else
            if (cmd == null)
            {
                return;
            }
            cmd.Do(_param);
            var node = new CommandNode(tick, cmd, _tail, null);
            if (_head == null)
            {
                _head = node;
                _tail = node;
                return;
            }

            _tail.next = node;
            _tail      = node;
#endif
        }
Example #4
0
        // Token: 0x0600006D RID: 109 RVA: 0x00003DD8 File Offset: 0x00001FD8
        public void Jump(int curTick, int dstTick)
        {
            bool flag = this._tail == null || this._tail.Tick <= dstTick;

            if (!flag)
            {
                CommandNode commandNode = this._tail;
                while (commandNode.pre != null && commandNode.pre.Tick >= dstTick)
                {
                    commandNode = commandNode.pre;
                }
                Debug.Assert(commandNode.Tick >= dstTick, string.Format("newTail must be the first cmd executed after that tick : tick:{0}  newTail.Tick:{1}", dstTick, commandNode.Tick));
                bool        val    = commandNode.pre == null || commandNode.pre.Tick < dstTick;
                string      str    = string.Format("newTail must be the first cmd executed in that tick : tick:{0}  ", dstTick);
                string      format = "newTail.pre.Tick:{0}";
                CommandNode pre    = commandNode.pre;
                Debug.Assert(val, str + string.Format(format, (pre != null) ? pre.Tick : dstTick));
                CommandNode minTickNode = commandNode;
                CommandNode tail        = this._tail;
                bool        flag2       = commandNode.pre == null;
                if (flag2)
                {
                    this._head = null;
                    this._tail = null;
                }
                else
                {
                    this._tail      = commandNode.pre;
                    this._tail.next = null;
                    commandNode.pre = null;
                }
                this._funcUndoCommand(minTickNode, tail, this._param);
            }
        }
        /// 只需执行undo 不需要顾虑指针的维护  //如果有性能需要可以考虑合并Cmd
        protected void UndoCommands(CommandNode minTickNode, CommandNode maxTickNode, object param)
        {
            if (maxTickNode == null)
            {
                return;
            }
            while (maxTickNode != minTickNode)
            {
                maxTickNode.cmd.Undo(_param);
                maxTickNode = maxTickNode.pre;
            }

            maxTickNode.cmd.Undo(_param);
        }
Example #6
0
        // Token: 0x06000070 RID: 112 RVA: 0x00003F9C File Offset: 0x0000219C
        protected void UndoCommands(CommandNode minTickNode, CommandNode maxTickNode, object param)
        {
            bool flag = maxTickNode == null;

            if (!flag)
            {
                while (maxTickNode != minTickNode)
                {
                    maxTickNode.cmd.Undo(this._param);
                    maxTickNode = maxTickNode.pre;
                }
                maxTickNode.cmd.Undo(this._param);
            }
        }
        public void Execute(int tick, ICommand cmd)
        {
            if (cmd == null)
            {
                return;
            }
            cmd.Do(_param);
            var node = new CommandNode(tick, cmd, _tail, null);

            if (_head == null)
            {
                _head = node;
                _tail = node;
                return;
            }

            _tail.next = node;
            _tail      = node;
        }
        ///RevertTo tick , so all cmd between [tick,~)(Include tick) should undo
        public void RevertTo(uint tick)
        {
#if DEBUG_SIMPLE_CHECK
            if (allCmds.Count == 0)
            {
                return;
            }
            allCmds[(int)tick].cmd.Undo(_param);
#else
            if (_tail == null || _tail.Tick < tick)
            {
                return;
            }

            var newTail = _tail;
            while (newTail.pre != null && newTail.pre.Tick >= tick)
            {
                newTail = newTail.pre;
            }

            Debug.Assert(newTail.Tick == tick, $"newTail must be the first cmd executed in that tick : tick:{tick}  newTail.Tick:{newTail.Tick}");
            Debug.Assert(newTail.pre == null || newTail.pre.Tick < tick, $"newTail must be the first cmd executed in that tick : tick:{tick}  newTail.pre.Tick:{newTail.pre.Tick}");

            var minTickNode = newTail;
            var maxTickNode = _tail;

            if (newTail.pre == null)
            {
                _head = null;
                _tail = null;
            }
            else
            {
                _tail = newTail.pre;
                //断开链接
                _tail.next  = null;
                newTail.pre = null;
            }
            _funcUndoCommand(minTickNode, maxTickNode, _param);
#endif
        }
Example #9
0
        // Token: 0x0600006F RID: 111 RVA: 0x00003F34 File Offset: 0x00002134
        public void Execute(int tick, ICommand cmd)
        {
            bool flag = cmd == null;

            if (!flag)
            {
                cmd.Do(this._param);
                CommandNode commandNode = new CommandNode(tick, cmd, this._tail, null);
                bool        flag2       = this._head == null;
                if (flag2)
                {
                    this._head = commandNode;
                    this._tail = commandNode;
                }
                else
                {
                    this._tail.next = commandNode;
                    this._tail      = commandNode;
                }
            }
        }
        ///RevertTo tick , so all cmd between [tick,~)(Include tick) should undo
        public void Jump(int curTick, int dstTick)
        {
            //Debug.Assert(curTick > dstTick, $"Not video mode should not roll forward curTick{curTick} dstTick{dstTick}");
            if (_tail == null || _tail.Tick <= dstTick)
            {
                return;
            }

            var newTail = _tail;

            while (newTail.pre != null && newTail.pre.Tick >= dstTick)
            {
                newTail = newTail.pre;
            }

            Debug.Assert(newTail.Tick >= dstTick,
                         $"newTail must be the first cmd executed after that tick : tick:{dstTick}  newTail.Tick:{newTail.Tick}");
            Debug.Assert(newTail.pre == null ||
                         newTail.pre.Tick < dstTick,
                         $"newTail must be the first cmd executed in that tick : tick:{dstTick}  " +
                         $"newTail.pre.Tick:{newTail.pre?.Tick ?? dstTick}");

            var minTickNode = newTail;
            var maxTickNode = _tail;

            if (newTail.pre == null)
            {
                _head = null;
                _tail = null;
            }
            else
            {
                _tail = newTail.pre;
                //断开链接
                _tail.next  = null;
                newTail.pre = null;
            }

            _funcUndoCommand(minTickNode, maxTickNode, _param);
        }
Example #11
0
 protected void UndoCommands(CommandNode minTickNode, CommandNode maxTickNode, object param)
 {
 }