-Fix: Loading a TasProj caued it to be saved immediately after. (Some old TasProj files are now broken.)

(Saving process for movies still needs some cleaning.)
-Fixed setting input log by reference when loading a branch
-Fix: TasStateManager wouldn't decrease Used when deleting a RAM state from a branch.
-Removed a useless call to Movie.Save()
-Fixed a bug with creating a savestate anchored tasproj.
This commit is contained in:
Suuper 2015-08-17 09:13:44 -05:00
parent 19a1f6cbef
commit f76c49ce1b
5 changed files with 43 additions and 59 deletions

View File

@ -464,6 +464,7 @@ namespace BizHawk.Client.Common
if (!record) // The semantics of record is that we are starting a new movie, and even wiping a pre-existing movie with the same path, but non-record means we are loading an existing movie into playback mode
{
movie.Load(false);
if (movie.SystemID != emulator.SystemId)
{
throw new MoviePlatformMismatchException(
@ -475,11 +476,11 @@ namespace BizHawk.Client.Common
}
// TODO: Delete this, this save is utterly useless.
//If a movie is already loaded, save it before starting a new movie
if (Movie.IsActive && !string.IsNullOrEmpty(Movie.Filename))
{
Movie.Save();
}
// Movie was saved immediately before calling QueeuNewMovie. (StartNewMovie)
//if (Movie.IsActive && !string.IsNullOrEmpty(Movie.Filename))
//{
// Movie.Save();
//}
// Note: this populates MovieControllerAdapter's Type with the approparite controller
// Don't set it to a movie instance of the adapter or you will lose the definition!

View File

@ -92,7 +92,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
}
bk2.HeaderEntries.Clear();
foreach(var kvp in old.HeaderEntries)
foreach (var kvp in old.HeaderEntries)
{
bk2.HeaderEntries[kvp.Key] = kvp.Value;
}
@ -100,13 +100,13 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
bk2.SyncSettingsJson = old.SyncSettingsJson;
bk2.Comments.Clear();
foreach(var comment in old.Comments)
foreach (var comment in old.Comments)
{
bk2.Comments.Add(comment);
}
bk2.Subtitles.Clear();
foreach(var sub in old.Subtitles)
foreach (var sub in old.Subtitles)
{
bk2.Subtitles.Add(sub);
}
@ -143,7 +143,6 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
TasMovie tas = new TasMovie(newFilename, true);
tas.BinarySavestate = savestate;
tas.TasStateManager.Clear();
tas.ClearLagLog();
List<string> entries = old.GetLogEntries();
@ -154,7 +153,9 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
// States can't be easily moved over, because they contain the frame number.
// TODO? I'm not sure how this would be done.
tas.TasStateManager.MountWriteAccess();
old.TasStateManager.Clear();
// Lag Log
tas.TasLagLog.FromLagLog(old.TasLagLog);
tas.TasLagLog.StartFromFrame(frame);
@ -180,7 +181,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
tas.Subtitles.Add(sub);
}
foreach(TasMovieMarker marker in old.Markers)
foreach (TasMovieMarker marker in old.Markers)
{
if (marker.Frame > frame)
tas.Markers.Add(new TasMovieMarker(marker.Frame - frame, marker.Message));
@ -304,7 +305,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
movie.HeaderEntries.Add(key, firmware.Hash);
}
}
}
if (Global.Emulator is Gameboy && (Global.Emulator as Gameboy).IsCGBMode())

View File

@ -472,14 +472,10 @@ namespace BizHawk.Client.Common
{
int? divergentPoint = DivergantPoint(_log, branch.InputLog);
_log = branch.InputLog;
_log = branch.InputLog.ToList();
_changes = true;
LagLog.FromLagLog(branch.LagLog);
//if (divergentPoint.HasValue)
// StateManager.Invalidate(divergentPoint.Value);
//else
// StateManager.Invalidate(branch.InputLog.Count);
StateManager.LoadBranch(Branches.IndexOf(branch));
StateManager.SetState(branch.Frame, branch.CoreData);

View File

@ -270,6 +270,7 @@ namespace BizHawk.Client.Common
}
}
private List<tsmState> lowPriorityStates = new List<tsmState>();
private void MaybeRemoveState()
{
int shouldRemove = -1;
@ -297,15 +298,8 @@ namespace BizHawk.Client.Common
{
shouldRemove++;
//// No need to have two savestates with only lag frames between them:
//for (int i = shouldRemove + 1; i < States.Count; i++)
//{
// if (AllLag(States.Keys[i - 1], States.Keys[i]))
// {
// shouldRemove = i - 1;
// break;
// }
//}
if (lowPriorityStates.Count != 0)
shouldRemove = States.IndexOfKey(lowPriorityStates[0].Frame);
//// Find states with the fewest frames between them
//for (int i = shouldRemove + 1; i < States.Count; i++)
@ -321,7 +315,7 @@ namespace BizHawk.Client.Common
markerSkips--;
if (markerSkips < 0)
shouldRemove = _movie.StartsFromSavestate ? 0 : 1;
} while (_movie.Markers.IsMarker(States.ElementAt(shouldRemove).Key + 1) && markerSkips > -1);
} while (_movie.Markers.IsMarker(States.Keys[shouldRemove] + 1) && markerSkips > -1);
return shouldRemove;
}
@ -370,6 +364,12 @@ namespace BizHawk.Client.Common
}
StateAccessed(frame);
int i = States.IndexOfKey(frame);
if (i > 0 && AllLag(States.Keys[i - 1], States.Keys[i]))
{
lowPriorityStates.Add(States[frame]);
}
}
private void RemoveState(int frame, int branch = -1)
{
@ -378,8 +378,10 @@ namespace BizHawk.Client.Common
else
accessed.Remove(BranchStates[frame][branch]);
tsmState state;
if (branch == -1)
{
state = States[frame];
if (States[frame].IsOnDisk)
States[frame].Dispose();
else
@ -388,8 +390,11 @@ namespace BizHawk.Client.Common
}
else
{
state = BranchStates[frame][branch];
if (BranchStates[frame][branch].IsOnDisk)
BranchStates[frame][branch].Dispose();
else
Used -= (ulong)BranchStates[frame][branch].Length;
BranchStates[frame].RemoveAt(BranchStates[frame].IndexOfKey(branch));
}
}
@ -445,15 +450,6 @@ namespace BizHawk.Client.Common
foreach (KeyValuePair<int, tsmState> state in statesToRemove)
RemoveState(state.Key);
// Why did I put this here? The branches aren't being edited/invalidated.
//var bStateLists = BranchStates.Where(x => x.Key >= frame).ToList();
//anyInvalidated = anyInvalidated | bStateLists.Any();
//foreach (KeyValuePair<int, SortedList<int, tsmState>> stateList in bStateLists)
//{
// for (int i = 0; i < stateList.Value.Count; i++)
// RemoveState(stateList.Key, stateList.Value.Keys[i]);
//}
CallInvalidateCallback(frame);
}

View File

@ -398,28 +398,13 @@ namespace BizHawk.Client.EmuHawk
return false;
}
if (CurrentTasMovie == null)
{
Global.MovieSession.Movie = new TasMovie(false, _saveBackgroundWorker);
(Global.MovieSession.Movie as TasMovie).TasStateManager.InvalidateCallback = GreenzoneInvalidated;
}
TasMovie newMovie = new TasMovie(false, _saveBackgroundWorker);
newMovie.TasStateManager.InvalidateCallback = GreenzoneInvalidated;
newMovie.Filename = file.FullName;
CurrentTasMovie.Filename = file.FullName;
try
{
CurrentTasMovie.Load(false);
}
catch
{
MessageBox.Show(
"Tastudio could not open the file. Due to the loading process, the emulator/Tastudio may be in a unspecified state depending on the error.",
"Tastudio",
MessageBoxButtons.OK);
return false;
}
Settings.RecentTas.Add(CurrentTasMovie.Filename);
Settings.RecentTas.Add(newMovie.Filename);
if (!HandleMovieLoadStuff())
if (!HandleMovieLoadStuff(newMovie))
return false;
BookMarkControl.UpdateValues();
@ -450,11 +435,16 @@ namespace BizHawk.Client.EmuHawk
private bool HandleMovieLoadStuff(TasMovie movie = null)
{
if (movie == null)
movie = CurrentTasMovie;
WantsToControlStopMovie = false;
bool result = StartNewMovieWrapper(movie.InputLogLength == 0, movie);
bool result;
if (movie == null)
{
movie = CurrentTasMovie;
result = StartNewMovieWrapper(movie.InputLogLength == 0, movie);
}
else
result = StartNewMovieWrapper(false, movie);
if (!result)
return false;
WantsToControlStopMovie = true;