2014-10-17 17:58:48 +00:00
using System.Linq ;
using System.IO ;
using BizHawk.Client.Common ;
namespace BizHawk.Client.EmuHawk
{
public partial class TAStudio
{
/// <summary>
/// Only goes to go to the frame if it is an event before current emulation, otherwise it is just a future event that can freely be edited
/// </summary>
private void GoToLastEmulatedFrameIfNecessary ( int frame )
{
2014-12-14 01:20:19 +00:00
if ( frame ! = Emulator . Frame ) // Don't go to a frame if you are already on it!
2014-10-17 17:58:48 +00:00
{
2015-03-20 16:53:42 +00:00
int restoreFrame = Emulator . Frame ;
2014-10-17 17:58:48 +00:00
2014-12-14 01:20:19 +00:00
if ( frame < = Emulator . Frame )
2014-10-17 17:58:48 +00:00
{
GoToFrame ( frame ) ;
}
2015-07-15 19:26:56 +00:00
if ( ! _autoRestoreFrame . HasValue | | _autoRestoreFrame . Value < restoreFrame )
_autoRestoreFrame = restoreFrame ;
2014-10-17 17:58:48 +00:00
}
}
2015-02-26 21:12:12 +00:00
// SuuperW: I changed this to public so that it could be used by MarkerControl.cs
2015-02-24 03:06:57 +00:00
public void GoToFrame ( int frame )
2014-10-17 17:58:48 +00:00
{
2015-07-13 18:03:59 +00:00
// If seeking to a frame before or at the end of the movie, use StartAtNearestFrameAndEmulate
// Otherwise, load the latest state (if not already there) and seek while recording.
2014-10-17 17:58:48 +00:00
2015-07-13 18:03:59 +00:00
if ( frame < = CurrentTasMovie . InputLogLength )
2014-10-17 17:58:48 +00:00
{
2015-07-13 18:03:59 +00:00
// Get as close as we can then emulate there
StartAtNearestFrameAndEmulate ( frame ) ;
2015-07-13 19:02:21 +00:00
2015-07-26 00:55:52 +00:00
MaybeFollowCursor ( ) ;
2014-10-17 17:58:48 +00:00
}
else // Emulate to a future frame
{
2014-12-14 01:20:19 +00:00
if ( frame = = Emulator . Frame + 1 ) // We are at the end of the movie and advancing one frame, therefore we are recording, simply emulate a frame
2014-10-17 17:58:48 +00:00
{
2015-03-23 20:15:35 +00:00
bool wasPaused = GlobalWin . MainForm . EmulatorPaused ;
2014-10-23 21:21:43 +00:00
GlobalWin . MainForm . FrameAdvance ( ) ;
2015-03-23 20:15:35 +00:00
if ( ! wasPaused )
GlobalWin . MainForm . UnpauseEmulator ( ) ;
2014-10-17 17:58:48 +00:00
}
2014-10-23 21:21:43 +00:00
else
2014-10-17 17:58:48 +00:00
{
2014-10-23 21:21:43 +00:00
CurrentTasMovie . SwitchToPlay ( ) ;
2015-07-13 18:03:59 +00:00
int lastState = CurrentTasMovie . TasStateManager . GetStateClosestToFrame ( frame ) . Key ; // Simply getting the last state doesn't work if that state is the frame. [dispaly isn't saved in the state, need to emulate to frame]
if ( lastState > Emulator . Frame )
LoadState ( CurrentTasMovie . TasStateManager [ lastState ] ) ; // STATE ACCESS
2014-10-23 21:21:43 +00:00
2015-12-12 20:59:55 +00:00
StartSeeking ( frame ) ;
2014-10-17 17:58:48 +00:00
}
}
RefreshDialog ( ) ;
UpdateOtherTools ( ) ;
}
public void GoToPreviousFrame ( )
{
2014-12-14 01:20:19 +00:00
if ( Emulator . Frame > 0 )
2014-10-17 17:58:48 +00:00
{
2014-12-14 01:20:19 +00:00
GoToFrame ( Emulator . Frame - 1 ) ;
2014-10-17 17:58:48 +00:00
}
}
public void GoToNextFrame ( )
{
2014-12-14 01:20:19 +00:00
GoToFrame ( Emulator . Frame + 1 ) ;
2014-10-17 17:58:48 +00:00
}
public void GoToPreviousMarker ( )
{
2014-12-14 01:20:19 +00:00
if ( Emulator . Frame > 0 )
2014-10-17 17:58:48 +00:00
{
2014-12-14 01:20:19 +00:00
var prevMarker = CurrentTasMovie . Markers . Previous ( Emulator . Frame ) ;
2014-10-17 17:58:48 +00:00
var prev = prevMarker ! = null ? prevMarker . Frame : 0 ;
GoToFrame ( prev ) ;
}
}
public void GoToNextMarker ( )
{
2014-12-14 01:20:19 +00:00
var nextMarker = CurrentTasMovie . Markers . Next ( Emulator . Frame ) ;
2014-10-20 19:04:59 +00:00
var next = nextMarker ! = null ? nextMarker . Frame : CurrentTasMovie . InputLogLength - 1 ;
2014-10-17 17:58:48 +00:00
GoToFrame ( next ) ;
}
public void GoToMarker ( TasMovieMarker marker )
{
GoToFrame ( marker . Frame ) ;
2015-02-26 21:12:12 +00:00
}
2015-03-14 16:38:07 +00:00
2015-07-26 00:55:52 +00:00
/// <summary>
/// Makes the given frame visible. If no frame is given, makes the current frame visible.
/// </summary>
2015-07-13 18:03:59 +00:00
public void SetVisibleIndex ( int? indexThatMustBeVisible = null )
2015-03-14 16:38:07 +00:00
{
if ( ! indexThatMustBeVisible . HasValue )
2015-07-26 00:55:52 +00:00
indexThatMustBeVisible = Emulator . Frame ;
2015-03-14 16:38:07 +00:00
TasView . ScrollToIndex ( indexThatMustBeVisible . Value ) ;
}
2015-07-26 00:55:52 +00:00
private void MaybeFollowCursor ( )
{
2015-07-26 01:15:35 +00:00
if ( TasPlaybackBox . FollowCursor & & ! mouseButtonHeld )
2015-07-26 00:55:52 +00:00
SetVisibleIndex ( ) ;
}
2015-02-26 21:12:12 +00:00
}
2014-10-17 17:58:48 +00:00
}