Skip to content

Commit 28fddb7

Browse files
committed
Make invisible emulation behave more as expected.
1 parent 4807bbd commit 28fddb7

File tree

6 files changed

+35
-23
lines changed

6 files changed

+35
-23
lines changed

Assets/Lua/GBA/SonicAdvance_CamHack.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ local function seek_frame(frame)
2525
if pause then client.pause() end
2626
end
2727

28+
event.onexit(function() client.invisibleemulation(false) end)
29+
2830
while true do
2931
client.invisibleemulation(true)
3032
local memorystate = memorysavestate.savecorestate()
@@ -46,6 +48,5 @@ while true do
4648
client.invisibleemulation(true)
4749
memorysavestate.loadcorestate(memorystate)
4850
memorysavestate.removestate(memorystate)
49-
-- client.invisibleemulation(false)
5051
emu.frameadvance()
5152
end

src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void FrameSkip(int numFrames)
135135
public int GetWindowSize()
136136
=> _config.GetWindowScaleFor(Emulator.SystemId);
137137

138-
public void InvisibleEmulation(bool invisible) => _mainForm.InvisibleEmulation = invisible;
138+
public void InvisibleEmulation(bool invisible) => _mainForm.InvisibleEmulateNextFrame = invisible;
139139

140140
public bool IsPaused() => _mainForm.EmulatorPaused;
141141

src/BizHawk.Client.Common/IMainFormForApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IMainFormForApi
1717
bool EmulatorPaused { get; }
1818

1919
/// <remarks>only referenced from <see cref="EmuClientApi"/></remarks>
20-
bool InvisibleEmulation { get; set; }
20+
bool InvisibleEmulateNextFrame { get; set; }
2121

2222
/// <remarks>only referenced from <see cref="EmuClientApi"/></remarks>
2323
bool IsSeeking { get; }

src/BizHawk.Client.EmuHawk/IMainFormForTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface IMainFormForTools : IDialogController
2525
bool HoldFrameAdvance { get; set; }
2626

2727
/// <remarks>only referenced from <see cref="BasicBot"/></remarks>
28-
bool InvisibleEmulation { get; set; }
28+
bool InvisibleEmulateNextFrame { get; set; }
2929

3030
/// <remarks>only referenced from <see cref="TAStudio"/></remarks>
3131
bool IsFastForwarding { get; }

src/BizHawk.Client.EmuHawk/MainForm.cs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,12 @@ public int ProgramRunLoop()
10021002
Tools.GeneralUpdateActiveExtTools();
10031003

10041004
StepRunLoop_Core();
1005-
Render();
1006-
StepRunLoop_Throttle();
1005+
1006+
if (!_invisibleEmulation)
1007+
{
1008+
Render();
1009+
StepRunLoop_Throttle();
1010+
}
10071011

10081012
// HACK: RAIntegration might peek at memory during messages
10091013
// we need this to allow memory access here, otherwise it will deadlock
@@ -1145,7 +1149,9 @@ private void OnPauseToggle(bool newPauseState)
11451149
/// <item><description><see cref="ClientLuaLibrary.InvisibleEmulation(bool)"/></description></item>
11461150
/// </list>
11471151
/// </summary>
1148-
public bool InvisibleEmulation { get; set; }
1152+
public bool InvisibleEmulateNextFrame { get; set; }
1153+
1154+
private bool _invisibleEmulation;
11491155

11501156
private long MouseWheelTracker;
11511157

@@ -1170,7 +1176,7 @@ private void OnPauseToggle(bool newPauseState)
11701176

11711177
public bool IsSeeking => PauseOnFrame.HasValue;
11721178
private bool IsTurboSeeking => PauseOnFrame.HasValue && Config.TurboSeek;
1173-
public bool IsTurboing => InputManager.ClientControls["Turbo"] || IsTurboSeeking || InvisibleEmulation;
1179+
public bool IsTurboing => InputManager.ClientControls["Turbo"] || IsTurboSeeking || _invisibleEmulation;
11741180
public bool IsFastForwarding => InputManager.ClientControls["Fast Forward"] || IsTurboing;
11751181
public bool IsRewinding { get; private set; }
11761182

@@ -2976,11 +2982,11 @@ private void StepRunLoop_Core(bool force = false)
29762982

29772983
_runloopFrameAdvance = frameAdvance;
29782984

2985+
bool unpaused = !EmulatorPaused || _invisibleEmulation;
29792986
#if BIZHAWKBUILD_SUPERHAWK
2980-
if (!EmulatorPaused && (!Config.SuperHawkThrottle || InputManager.ClientControls.AnyInputHeld))
2981-
#else
2982-
if (!EmulatorPaused)
2987+
unpaused = unpaused && (!Config.SuperHawkThrottle || InputManager.ClientControls.AnyInputHeld);
29832988
#endif
2989+
if (unpaused)
29842990
{
29852991
runFrame = true;
29862992
}
@@ -2994,15 +3000,20 @@ private void StepRunLoop_Core(bool force = false)
29943000
// BlockFrameAdvance (true when input it being editted in TAStudio) supercedes all other frame advance conditions
29953001
if ((runFrame || force) && !BlockFrameAdvance)
29963002
{
3003+
_invisibleEmulation = InvisibleEmulateNextFrame;
3004+
29973005
var isFastForwarding = IsFastForwarding;
29983006
var isFastForwardingOrRewinding = isFastForwarding || isRewinding || Config.Unthrottled;
29993007

3000-
if (isFastForwardingOrRewinding != _lastFastForwardingOrRewinding)
3008+
if (!_invisibleEmulation)
30013009
{
3002-
InitializeFpsData();
3003-
}
3010+
if (isFastForwardingOrRewinding != _lastFastForwardingOrRewinding)
3011+
{
3012+
InitializeFpsData();
3013+
}
30043014

3005-
_lastFastForwardingOrRewinding = isFastForwardingOrRewinding;
3015+
_lastFastForwardingOrRewinding = isFastForwardingOrRewinding;
3016+
}
30063017

30073018
// client input-related duties
30083019
OSD.ClearGuiText();
@@ -3022,13 +3033,13 @@ private void StepRunLoop_Core(bool force = false)
30223033
Tools.UpdateToolsBefore();
30233034
}
30243035

3025-
if (!InvisibleEmulation)
3036+
if (!_invisibleEmulation)
30263037
{
30273038
CaptureRewind(isRewinding);
30283039
}
30293040

30303041
// Set volume, if enabled
3031-
if (Config.SoundEnabledNormal && !InvisibleEmulation)
3042+
if (Config.SoundEnabledNormal && !_invisibleEmulation)
30323043
{
30333044
atten = Config.SoundVolume / 100.0f;
30343045

@@ -3073,7 +3084,7 @@ private void StepRunLoop_Core(bool force = false)
30733084
}
30743085

30753086
bool atTurboSeekEnd = IsTurboSeeking && Emulator.Frame == PauseOnFrame.Value - 1;
3076-
bool render = !InvisibleEmulation && (!_throttle.skipNextFrame || _currAviWriter?.UsesVideo is true || atTurboSeekEnd);
3087+
bool render = !_invisibleEmulation && (!_throttle.skipNextFrame || _currAviWriter?.UsesVideo is true || atTurboSeekEnd);
30773088
bool newFrame = Emulator.FrameAdvance(InputManager.ControllerOutput, render, renderSound);
30783089

30793090
MovieSession.HandleFrameAfter(ToolBypassingMovieEndAction is not null);
@@ -3114,12 +3125,12 @@ private void StepRunLoop_Core(bool force = false)
31143125
}
31153126
}
31163127

3117-
if (!PauseAvi && newFrame && !InvisibleEmulation)
3128+
if (!PauseAvi && newFrame && !_invisibleEmulation)
31183129
{
31193130
AvFrameAdvance();
31203131
}
31213132

3122-
if (newFrame)
3133+
if (newFrame && !_invisibleEmulation)
31233134
{
31243135
_framesSinceLastFpsUpdate++;
31253136

src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,8 +1047,8 @@ private void StartBot()
10471047

10481048
if (InvisibleEmulationCheckBox.Checked)
10491049
{
1050-
_previousInvisibleEmulation = MainForm.InvisibleEmulation;
1051-
MainForm.InvisibleEmulation = true;
1050+
_previousInvisibleEmulation = MainForm.InvisibleEmulateNextFrame;
1051+
MainForm.InvisibleEmulateNextFrame = true;
10521052
}
10531053

10541054
UpdateBotStatusIcon();
@@ -1103,7 +1103,7 @@ private void StopBot()
11031103
private void RestoreConfigFlags()
11041104
{
11051105
Config.DisplayMessages = _previousDisplayMessage;
1106-
MainForm.InvisibleEmulation = _previousInvisibleEmulation;
1106+
MainForm.InvisibleEmulateNextFrame = _previousInvisibleEmulation;
11071107
var movie = MovieSession.Movie;
11081108
if (movie.IsRecording()) movie.IsCountingRerecords = _oldCountingSetting;
11091109
}

0 commit comments

Comments
 (0)