Ejemplo n.º 1
0
        public void Add(UR_ICommand p_cmd, bool p_isAlreadyExecuted)
        {
            if (p_cmd != null)
            {
                if (!p_isAlreadyExecuted)
                {
                    p_cmd.Execute();
                }

                if (m_undoCommands.Count > 0)
                {
                    UR_ICommand lastCmd      = m_undoCommands[m_undoCommands.Count - 1];
                    long        lastCmdBytes = lastCmd.GetStoredBytes();
                    if (lastCmd.CombineWithNext(p_cmd))
                    {
                        ClearRedoCommands();
                        m_commandsStoredBytes += lastCmd.GetStoredBytes() - lastCmdBytes;
                        LimitMemoryUsage();
                        return;                         // commands are combined now
                    }
                }
                m_undoCommands.Add(p_cmd);
                ClearRedoCommands();
                m_commandsStoredBytes += p_cmd.GetStoredBytes();
                LimitMemoryUsage();
            }
            else
            {
                Debug.LogError("UR_CommandMgr: Add: p_cmd is null!");
            }
        }
Ejemplo n.º 2
0
 public bool Undo()
 {
     if (IsUndoable)
     {
         UR_ICommand cmd = m_undoCommands[m_undoCommands.Count - 1];
         m_undoCommands.RemoveAt(m_undoCommands.Count - 1);
         m_commandsStoredBytes -= cmd.GetStoredBytes();
         cmd.Rollback();
         m_commandsStoredBytes += cmd.GetStoredBytes();
         m_redoCommands.Add(cmd);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
 private void LimitMemoryUsage()
 {
     while (m_commandsStoredBytes > m_commandsStoredBytesLimit && m_undoCommands.Count > 0)
     {
         // remove oldest command
         UR_ICommand oldestCmd = m_undoCommands[0];
         m_undoCommands.RemoveAt(0);
         m_commandsStoredBytes -= oldestCmd.GetStoredBytes();
     }
     // in theory the redo list could use a lot storage space, but since the redo list is cleared after every new command, we do not check it here
     // => this means, that reducing the StoredBytesLimit on runtime will not delete the redo stack, it will be deleted when a new command is executed
 }