From a751412c1fe28cd3b929adb92a887504e9982bfa Mon Sep 17 00:00:00 2001 From: Suuper Date: Sat, 20 Feb 2016 13:43:24 -0600 Subject: [PATCH] TasStateManager.cs -> fixed stateHasDuplicate --- .../movie/tasproj/TasStateManager.cs | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs index dc17d3f248..01b427f44b 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs @@ -138,7 +138,8 @@ namespace BizHawk.Client.Common { get { - if (frame == 0) { + if (frame == 0) + { return new KeyValuePair(0, InitialState); } @@ -391,7 +392,7 @@ namespace BizHawk.Client.Common else Used -= (ulong)BranchStates[frame][branch].Length; BranchStates[frame].RemoveAt(BranchStates[frame].IndexOfKey(branch)); - + if (BranchStates[frame].Count == 0) BranchStates.Remove(frame); } @@ -716,7 +717,7 @@ namespace BizHawk.Client.Common { StateManagerState stateToMatch; - // figure out what state we're checking + // Get the state instance if (branchHash == -1) stateToMatch = States[frame]; else @@ -724,26 +725,28 @@ namespace BizHawk.Client.Common if (!BranchStates[frame].ContainsKey(branchHash)) return -2; stateToMatch = BranchStates[frame][branchHash]; - //if (States.ContainsKey(frame) && States[frame] == stateToMatch) - // return -1; + // Check the current branch for duplicate. + if (States.ContainsKey(frame) && States[frame] == stateToMatch) + return -1; } - // there's no state for that frame at all - if (!BranchStates.ContainsKey(frame)) + // Check if there are any branch states for the given frame. + if (!BranchStates.ContainsKey(frame) || BranchStates[frame] == null) return -2; - // find the branches whose state for that frame is the same + // Loop through branch states for the given frame. SortedList stateList = BranchStates[frame]; for (int i = 0; i < _movie.BranchCount; i++) { + // Don't check the branch containing the state to match. if (i == _movie.BranchIndexByHash(branchHash)) continue; - if (stateList != null && stateList.ContainsKey(i) && stateList[i] == stateToMatch) + if (stateList.Values[i] == stateToMatch) return i; } - return -2; + return -2; // No match. } private Point findState(StateManagerState s) @@ -795,13 +798,11 @@ namespace BizHawk.Client.Common if (stateList == null) continue; - if (stateHasDuplicate(kvp.Key, branchHash) == -2) + if (stateList.ContainsKey(branchHash)) { - if (stateList.ContainsKey(branchHash)) + if (stateHasDuplicate(kvp.Key, branchHash) == -2) { - if (stateList[branchHash].IsOnDisk) - { } - else + if (!stateList[branchHash].IsOnDisk) Used -= (ulong)stateList[branchHash].Length; } } @@ -823,13 +824,11 @@ namespace BizHawk.Client.Common if (stateList == null) continue; - if (stateHasDuplicate(kvp.Key, branchHash) == -2) + if (stateList.ContainsKey(branchHash)) { - if (stateList.ContainsKey(branchHash)) + if (stateHasDuplicate(kvp.Key, branchHash) == -2) { - if (stateList[branchHash].IsOnDisk) - { } - else + if (!stateList[branchHash].IsOnDisk) Used -= (ulong)stateList[branchHash].Length; } }