tastudio: some dirty fixes to how undo/redo works with recording frames

This commit is contained in:
feos 2016-08-22 21:17:08 +03:00
parent ccc2ee1ba9
commit 215f9b9959
3 changed files with 21 additions and 8 deletions

View File

@ -152,7 +152,7 @@ namespace BizHawk.Client.Common
ChangeLog.EndBatch(); ChangeLog.EndBatch();
} }
} }
public void RemoveFrames(int removeStart, int removeUpTo) public void RemoveFrames(int removeStart, int removeUpTo, bool fromHistory = false)
{ {
bool endBatch = ChangeLog.BeginNewBatch("Remove Frames: " + removeStart + "-" + removeUpTo, true); bool endBatch = ChangeLog.BeginNewBatch("Remove Frames: " + removeStart + "-" + removeUpTo, true);
ChangeLog.AddGeneralUndo(removeStart, InputLogLength - 1); ChangeLog.AddGeneralUndo(removeStart, InputLogLength - 1);
@ -173,7 +173,7 @@ namespace BizHawk.Client.Common
if (m.Frame < removeUpTo) if (m.Frame < removeUpTo)
Markers.Remove(m); Markers.Remove(m);
else else
Markers.Move(m.Frame, m.Frame - (removeUpTo - removeStart)); Markers.Move(m.Frame, m.Frame - (removeUpTo - removeStart), fromHistory);
} }
} }
ChangeLog.IsRecording = wasRecording; ChangeLog.IsRecording = wasRecording;
@ -281,7 +281,7 @@ namespace BizHawk.Client.Common
ChangeLog.SetGeneralRedo(); ChangeLog.SetGeneralRedo();
} }
public void InsertEmptyFrame(int frame, int count = 1) public void InsertEmptyFrame(int frame, int count = 1, bool fromHistory = false)
{ {
bool endBatch = ChangeLog.BeginNewBatch("Insert Empty Frame: " + frame, true); bool endBatch = ChangeLog.BeginNewBatch("Insert Empty Frame: " + frame, true);
ChangeLog.AddGeneralUndo(frame, InputLogLength + count - 1); ChangeLog.AddGeneralUndo(frame, InputLogLength + count - 1);
@ -289,6 +289,9 @@ namespace BizHawk.Client.Common
var lg = LogGeneratorInstance(); var lg = LogGeneratorInstance();
lg.SetSource(Global.MovieSession.MovieControllerInstance()); lg.SetSource(Global.MovieSession.MovieControllerInstance());
if (frame > _log.Count())
frame = _log.Count();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
_log.Insert(frame, lg.EmptyEntry); _log.Insert(frame, lg.EmptyEntry);
@ -302,7 +305,7 @@ namespace BizHawk.Client.Common
for (int i = firstIndex; i < Markers.Count; i++) for (int i = firstIndex; i < Markers.Count; i++)
{ {
TasMovieMarker m = Markers.ElementAt(i); TasMovieMarker m = Markers.ElementAt(i);
Markers.Move(m.Frame, m.Frame + count); Markers.Move(m.Frame, m.Frame + count, fromHistory);
} }
} }
ChangeLog.IsRecording = wasRecording; ChangeLog.IsRecording = wasRecording;

View File

@ -174,7 +174,7 @@ namespace BizHawk.Client.Common
{ {
get get
{ {
if (Names.Count == 0) if (Names.Count == 0 || UndoIndex < 0)
return null; return null;
else else
return Names[UndoIndex]; return Names[UndoIndex];
@ -332,7 +332,15 @@ namespace BizHawk.Client.Common
LastFrame = lastFrame; LastFrame = lastFrame;
oldLog = new List<string>(length); oldLog = new List<string>(length);
undoLength = Math.Min(lastFrame + 1, movie.InputLogLength) - firstFrame; var minuend = Math.Min(lastFrame + 1, movie.InputLogLength);
if (firstFrame > minuend)
undoLength = minuend;
else
undoLength = minuend - firstFrame;
if (FirstFrame > oldLog.Count())
FirstFrame = oldLog.Count();
for (int i = 0; i < undoLength; i++) for (int i = 0; i < undoLength; i++)
oldLog.Add(movie.GetLogEntries()[FirstFrame + i]); oldLog.Add(movie.GetLogEntries()[FirstFrame + i]);
@ -354,9 +362,9 @@ namespace BizHawk.Client.Common
movie.BindMarkersToInput = bindMarkers; movie.BindMarkersToInput = bindMarkers;
if (redoLength != length) if (redoLength != length)
movie.InsertEmptyFrame(FirstFrame, length - redoLength); movie.InsertEmptyFrame(FirstFrame, length - redoLength, true);
if (undoLength != length) if (undoLength != length)
movie.RemoveFrames(FirstFrame, movie.InputLogLength - undoLength); movie.RemoveFrames(FirstFrame, movie.InputLogLength - undoLength, true);
for (int i = 0; i < undoLength; i++) for (int i = 0; i < undoLength; i++)
movie.SetFrame(FirstFrame + i, oldLog[i]); movie.SetFrame(FirstFrame + i, oldLog[i]);

View File

@ -219,6 +219,8 @@ namespace BizHawk.Client.Common
public void Move(int fromFrame, int toFrame, bool fromHistory = false) public void Move(int fromFrame, int toFrame, bool fromHistory = false)
{ {
if (fromFrame == 0) // no thanks!
return;
TasMovieMarker m = Get(fromFrame); TasMovieMarker m = Get(fromFrame);
if (m == null) // TODO: Don't do this. if (m == null) // TODO: Don't do this.
return; return;