public void dispatch(TerrainCommand cmd) { if (cmd.execute(this) == true) { addUndo(cmd); myTerrainSource.chunkCache.updateChunk(cmd.myChunk); } }
public void undoLastCommand() { if (myUndoStack.Count == 0) { return; } TerrainCommand cmd = myUndoStack.Last.Value; myUndoStack.RemoveLast(); if (cmd.undo(this) == true) { myTerrainSource.chunkCache.updateChunk(cmd.myChunk); } }
public void addUndo(TerrainCommand cmd) { /* TODO: figure out a better way of commands to figure out if they actually need to be stored * if (myUndoStack.Count > 0) * { * //check if this command has actually changes the chunk * TerrainCommand prevCmd = myUndoStack.Last.Value; * * //could be the same * if (cmd.myPreviousState.Length == prevCmd.myPreviousState.Length) * { * bool different = false; * for (int i = 0; i < cmd.myPreviousState.Length; i++) * { * if (cmd.myPreviousState[i] != prevCmd.myPreviousState[i]) * { * different = true; * break; * } * } * * if (different == false) * { * //no sense in storing the same exact state twice * return; * } * } * } */ myUndoStack.AddLast(cmd); while (undoUsage > 1024 * 1024 * 100) //more than 100 mb of undo memory used { myUndoStack.RemoveFirst(); } }