From 2a12b5925086f45c6c1b10d2cbaca37d05187080 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 2 Jan 2015 22:16:07 +0000 Subject: [PATCH] Ram Search - limit to 5 undo levels --- BizHawk.Common/UndoHistory.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/BizHawk.Common/UndoHistory.cs b/BizHawk.Common/UndoHistory.cs index 05be8e689b..eef6b72104 100644 --- a/BizHawk.Common/UndoHistory.cs +++ b/BizHawk.Common/UndoHistory.cs @@ -8,8 +8,11 @@ namespace BizHawk.Common private List> _history = new List>(); private int _curPos; // 1-based + public int MaxUndoLevels { get; set; } + public UndoHistory(bool enabled) { + MaxUndoLevels = 5; Enabled = enabled; } @@ -54,6 +57,15 @@ namespace BizHawk.Common } } + // TODO: don't assume we are one over, since MaxUndoLevels is public, it could be set to a small number after a large list has occured + if (_history.Count > MaxUndoLevels) + { + foreach (var item in _history.Take(_history.Count - MaxUndoLevels)) + { + _history.Remove(item); + } + } + _history.Add(newState.ToList()); _curPos = _history.Count; }