Skip to content

Commit

Permalink
Fix "double rendering" in Lua/ApiHawk gui stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
CasualPokePlayer committed Jun 1, 2024
1 parent dcfe553 commit 1a9176e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/BizHawk.Bizware.Graphics/Interfaces/I2DRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public interface I2DRenderer : IDisposable
/// </summary>
void Clear();

/// <summary>
/// Discards any pending draw calls.
/// Similar to Clear(), except this won't insert a command to clear the target texture
/// </summary>
void Discard();

CompositingMode CompositingMode { set; }

void DrawBezier(Color color, Point pt1, Point pt2, Point pt3, Point pt4);
Expand Down
3 changes: 3 additions & 0 deletions src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ public void Clear()
_hasClearPending = true;
}

public void Discard()
=> ResetDrawList();

protected bool EnableBlending { get; private set; }
private bool _pendingBlendEnable;

Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void Dispose()

public void DoFrameAdvance()
{
_mainForm.FrameAdvance();
_mainForm.FrameAdvance(discardApiHawkSurfaces: false); // we're rendering, so we don't want to discard
_mainForm.StepRunLoop_Throttle();
_mainForm.Render();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,5 +933,13 @@ public void ClearApiHawkSurfaces()
renderer.Clear();
}
}

public void DiscardApiHawkSurfaces()
{
foreach (var renderer in _apiHawkIDTo2DRenderer.Values)
{
renderer.Discard();
}
}
}
}
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/IMainFormForApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface IMainFormForApi
bool FlushSaveRAM(bool autosave = false);

/// <remarks>only referenced from <c>EmuClientApi</c></remarks>
void FrameAdvance();
void FrameAdvance(bool discardApiHawkSurfaces = true);

void FrameBufferResized();

Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.EmuHawk/IMainFormForTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public interface IMainFormForTools : IDialogController
bool EnsureCoreIsAccurate();

/// <remarks>only referenced from <see cref="TAStudio"/></remarks>
void FrameAdvance();
void FrameAdvance(bool discardApiHawkSurfaces = true);

/// <remarks>only referenced from <see cref="LuaConsole"/></remarks>
void FrameBufferResized();
Expand Down
8 changes: 7 additions & 1 deletion src/BizHawk.Client.EmuHawk/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2477,6 +2477,7 @@ private void SaveSlotSelectedMessage()
{
if (Config.DispSpeedupFeatures == 0)
{
DisplayManager.DiscardApiHawkSurfaces();
return;
}

Expand Down Expand Up @@ -3069,16 +3070,21 @@ private void LoadConfigFile(string iniPath)
_throttle.Step(Config, Sound, allowSleep: true, forceFrameSkip: -1);
}

public void FrameAdvance()
public void FrameAdvance(bool discardApiHawkSurfaces)
{
PressFrameAdvance = true;
StepRunLoop_Core(true);
if (discardApiHawkSurfaces)
{
DisplayManager.DiscardApiHawkSurfaces();
}
}

public void SeekFrameAdvance()
{
PressFrameAdvance = true;
StepRunLoop_Core(true);
DisplayManager.DiscardApiHawkSurfaces();
PressFrameAdvance = false;
}

Expand Down

0 comments on commit 1a9176e

Please sign in to comment.