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
{
2016-08-29 16:38:36 +00:00
bool wasPaused = Mainform . EmulatorPaused ;
Mainform . FrameAdvance ( ) ;
2015-03-23 20:15:35 +00:00
if ( ! wasPaused )
2016-08-29 16:38:36 +00:00
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
{
2016-08-03 19:29:27 +00:00
TastudioPlayMode ( ) ;
2014-10-23 21:21:43 +00:00
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 ( )
{
tastudio: fix editing while unpaused + left button held scenario.
now it replicates taseditor:
- editing input while unpaused, if autorestore is off, resumes emulation and ignores seek frame. if you keep holding the LMB, and follow cursor is on, it will keep scrolling, drawing and emulating
- editing input while unpaused, if autoresotre is on, fires autorestore and then just pauses on the seek frame
what's different from taseditor:
- with autorestore and follow cursor on, if you hold the button, and seek frame is below the view, it will keep scrolling down, drawing new input and emulating. taseditor does *not* follow cursor while seeking.
this all doesn't necessarily make sense, but we need people to figure out what is best for work.
2016-07-11 18:38:58 +00:00
if ( TasPlaybackBox . FollowCursor )
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
}