Skip to content

Commit

Permalink
Merge branch 'master' into stella
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMartin86 committed Sep 10, 2024
2 parents 8c10a0c + 08bd14e commit 1e831e8
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .global.editorconfig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dotnet_diagnostic.BHI1005.severity = error
# Do not discard local variables
dotnet_diagnostic.BHI1006.severity = error
# Don't use target-typed new for throw expressions
dotnet_diagnostic.BHI1007.severity = suggestion
dotnet_diagnostic.BHI1007.severity = error
# Don't call this.GetType() in sealed type, use typeof operator
dotnet_diagnostic.BHI1100.severity = error
# Don't call this.GetType(), use typeof operator (or replace subtype check with better encapsulation)
Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Bizware.Audio/SDL2WavStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

using static SDL2.SDL;

#pragma warning disable BHI1007 // target-typed Exception TODO don't

namespace BizHawk.Bizware.Audio
{
internal sealed class SDL2WavStream : Stream, ISpanStream
Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Bizware.Graphics/OpenGL/IGL_OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using Silk.NET.OpenGL;

#pragma warning disable BHI1007 // target-typed Exception TODO don't

namespace BizHawk.Bizware.Graphics
{
/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/BizHawk.Bizware.Graphics/OpenGL/SDL2OpenGLContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// #define DEBUG_OPENGL

using System.IO;

#if DEBUG_OPENGL
using System.Runtime.InteropServices;
using Silk.NET.OpenGL;
Expand All @@ -9,6 +11,8 @@

using static SDL2.SDL;

#pragma warning disable BHI1007 // target-typed Exception TODO don't

namespace BizHawk.Bizware.Graphics
{
/// <summary>
Expand All @@ -27,7 +31,7 @@ static SDL2OpenGLContext()
// try to use EGL if it is available
// GLX is the old API, and is the more or less "deprecated" at this point, and potentially more buggy with some drivers
// we do need to a bit more work, in case EGL is not actually available or potentially doesn't have desktop GL support
SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL, "1");
if (!Directory.Exists("/nix")/* this is just for me --yoshi */) SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL, "1");
}

// init SDL video
Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Bizware.Graphics/Renderers/SDLImGui2DRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

using static SDL2.SDL;

#pragma warning disable BHI1007 // target-typed Exception TODO don't

namespace BizHawk.Bizware.Graphics
{
/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion src/BizHawk.Bizware.Input/KeyInput/X11KeyInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public X11KeyInput()

if (Display == IntPtr.Zero)
{
throw new("Could not open XDisplay");
// There doesn't seem to be a convention for what exception type to throw in these situations. Can't use NRE. Well...
// _ = Unsafe.AsRef<X11.Display>()!; // hmm
// InvalidOperationException doesn't match. Exception it is. --yoshi
throw new Exception("Could not open XDisplay");
}

using (new XLock(Display))
Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Bizware.Input/SDL2/SDL2InputAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

using static SDL2.SDL;

#pragma warning disable BHI1007 // target-typed Exception TODO don't

namespace BizHawk.Bizware.Input
{
public sealed class SDL2InputAdapter : OSTailoredKeyInputAdapter
Expand Down
4 changes: 2 additions & 2 deletions src/BizHawk.Client.Common/XmlGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static XmlGame Create(HawkFile f)
}
else
{
throw new($"Couldn't load XMLGame Asset \"{filename}\"");
throw new Exception($"Couldn't load XMLGame Asset \"{filename}\"");
}
}
else
Expand Down Expand Up @@ -96,7 +96,7 @@ public static XmlGame Create(HawkFile f)
}
catch (Exception e)
{
throw new($"Couldn't load XMLGame LoadAsset \"{filename}\"", e);
throw new Exception($"Couldn't load XMLGame LoadAsset \"{filename}\"", e);
}
}

Expand Down
42 changes: 10 additions & 32 deletions src/BizHawk.Client.Common/movie/MovieSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,30 @@ public void HandleFrameBefore()
else if (Movie.IsPlaying())
{
LatchInputToLog();

if (Movie.IsRecording()) // The movie end situation can cause the switch to record mode, in that case we need to capture some input for this frame
// if we're at the movie's end and the MovieEndAction is record, just continue recording in play mode
// TODO change to TAStudio check
if (Movie is ITasMovie && Movie.Emulator.Frame == Movie.FrameCount && Settings.MovieEndAction == MovieEndAction.Record)
{
HandleFrameLoopForRecordMode();
Movie.RecordFrame(Movie.Emulator.Frame, MovieOut.Source);
}
}
else if (Movie.IsRecording())
{
HandleFrameLoopForRecordMode();
LatchInputToUser();
Movie.RecordFrame(Movie.Emulator.Frame, MovieOut.Source);
}
}

// TODO: this is a mess, simplify
public void HandleFrameAfter()
{
if (Movie is ITasMovie tasMovie)
{
tasMovie.GreenzoneCurrentFrame();
if (tasMovie.IsPlayingOrFinished() && Settings.MovieEndAction == MovieEndAction.Record && Movie.Emulator.Frame >= tasMovie.InputLogLength)
{
HandleFrameLoopForRecordMode();
return;
}
// TODO change to TAStudio check
if (Settings.MovieEndAction == MovieEndAction.Record) return;
}

if (Movie.IsPlaying() && Movie.Emulator.Frame >= Movie.InputLogLength)
if (Movie.IsPlaying() && Movie.Emulator.Frame >= Movie.FrameCount)
{
HandlePlaybackEnd();
}
Expand Down Expand Up @@ -329,13 +327,8 @@ private void LatchInputToUser()
private void LatchInputToLog()
{
var input = Movie.GetInputState(Movie.Emulator.Frame);
if (input == null)
{
HandleFrameAfter();
return;
}

MovieController.SetFrom(input);
MovieController.SetFrom(input ?? GenerateMovieController());
MovieOut.Source = MovieController;
}

Expand Down Expand Up @@ -414,20 +407,5 @@ private void HandlePlaybackEnd()

_modeChangedCallback();
}

private void HandleFrameLoopForRecordMode()
{
// we don't want TasMovie to latch user input outside its internal recording mode, so limit it to autohold
if (Movie is ITasMovie && Movie.IsPlayingOrFinished())
{
MovieController.SetFromSticky(StickySource);
}
else
{
MovieController.SetFrom(MovieIn);
}

Movie.RecordFrame(Movie.Emulator.Frame, MovieController);
}
}
}
6 changes: 3 additions & 3 deletions src/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void AddFrame(IVideoProvider source)
{
if (!_workerT.IsAlive)
{
throw new("AVI Worker thread died!");
throw new Exception("AVI Worker thread died!");
}
}
}
Expand All @@ -194,7 +194,7 @@ public void AddSamples(short[] samples)
{
if (!_workerT.IsAlive)
{
throw new("AVI Worker thread died!");
throw new Exception("AVI Worker thread died!");
}
}
}
Expand Down Expand Up @@ -977,7 +977,7 @@ public unsafe void AddFrame(IVideoProvider source)
public void SetDefaultVideoCodecToken(Config config)
{
var ct = CodecToken.DeSerialize(config.AviCodecToken);
_currVideoCodecToken = ct ?? throw new($"No default {nameof(config.AviCodecToken)} in config!");
_currVideoCodecToken = ct ?? throw new Exception($"No default {nameof(config.AviCodecToken)} in config!");
}

public string DesiredExtension()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using BizHawk.Emulation.Cores.Arcades.MAME;
using BizHawk.Emulation.DiscSystem;

#pragma warning disable BHI1007 // target-typed Exception TODO don't

namespace BizHawk.Client.EmuHawk
{
public partial class RCheevos
Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Client.EmuHawk/RetroAchievements/RCheevos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;

#pragma warning disable BHI1007 // target-typed Exception TODO don't

namespace BizHawk.Client.EmuHawk
{
public partial class RCheevos : RetroAchievements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using BizHawk.Emulation.Common;
using BizHawk.Emulation.DiscSystem;

#pragma warning disable BHI1007 // target-typed Exception TODO don't

namespace BizHawk.Client.EmuHawk
{
public abstract partial class RetroAchievements
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.EmuHawk/tools/Lua/LuaLibraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void Restart(
lib.APIs = _apiContainer;
if (!ServiceInjector.UpdateServices(newServiceProvider, lib, mayCache: true))
{
throw new("Lua lib has required service(s) that can't be fulfilled");
throw new Exception("Lua lib has required service(s) that can't be fulfilled");
}

lib.Restarted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ private void SelectBetweenMarkersMenuItem_Click(object sender, EventArgs e)
int prev = prevMarker?.Frame ?? 0;
int next = nextMarker?.Frame ?? CurrentTasMovie.InputLogLength;

TasView.DeselectAll();
for (int i = prev; i < next; i++)
{
TasView.SelectRow(i, true);
Expand Down
4 changes: 3 additions & 1 deletion src/BizHawk.Common/Extensions/PathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ static PathUtils()
else
{
var dirPath = AppContext.BaseDirectory;
DataDirectoryPath = ExeDirectoryPath = string.IsNullOrEmpty(dirPath) ? throw new("failed to get location of executable, very bad things must have happened") : dirPath.RemoveSuffix('\\');
DataDirectoryPath = ExeDirectoryPath = string.IsNullOrEmpty(dirPath)
? throw new Exception("failed to get location of executable, very bad things must have happened")
: dirPath.RemoveSuffix('\\');
DllDirectoryPath = Path.Combine(ExeDirectoryPath, "dll");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Common/OSTailoredCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public static string SimpleSubshell(string cmd, string args, string noOutputMsg)
using var proc = ConstructSubshell(cmd, args);
proc.Start();
var stdout = proc.StandardOutput;
if (stdout.EndOfStream) throw new($"{noOutputMsg} ({cmd} wrote nothing to stdout)");
if (stdout.EndOfStream) throw new Exception($"{noOutputMsg} ({cmd} wrote nothing to stdout)");
return stdout.ReadLine()!;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Emulation.Common/Sound/SDLResampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using static SDL2.SDL;

#pragma warning disable BHI1007 // target-typed Exception TODO don't

namespace BizHawk.Emulation.Common
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public MAME(CoreLoadParameters<object, MAMESyncSettings> lp)
if (_loadFailure != string.Empty)
{
Dispose();
throw new("\n\n" + _loadFailure);
throw new Exception("\n\n" + _loadFailure);
}

// concat all SHA1 hashes together (unprefixed), then hash that
Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Emulation.Cores/Consoles/Nintendo/3DS/Encore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using BizHawk.Common;
using BizHawk.Emulation.Common;

#pragma warning disable BHI1007 // target-typed Exception TODO don't

namespace BizHawk.Emulation.Cores.Consoles.Nintendo.N3DS
{
[PortedCore(CoreNames.Encore, "", "nightly-2104", "https://github.com/CasualPokePlayer/encore", singleInstance: true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private static byte[] DecideNAND(ICoreFileProvider cfp, bool isDSiEnhanced, byte
private static byte[] GetTMDData(ulong titleId)
{
using var zip = new ZipArchive(Zstd.DecompressZstdStream(new MemoryStream(Resources.TMDS.Value)), ZipArchiveMode.Read, false);
using var tmd = zip.GetEntry($"{titleId:x16}.tmd")?.Open() ?? throw new($"Cannot find TMD for title ID {titleId:x16}, please report");
using var tmd = zip.GetEntry($"{titleId:x16}.tmd")?.Open() ?? throw new Exception($"Cannot find TMD for title ID {titleId:x16}, please report");
return tmd.ReadAllBytes();
}

Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public GPGX(CoreLoadParameters<GPGXSettings, GPGXSyncSettings> lp)
{
if (lp.Discs.Count > 128)
{
throw new("Too many discs loaded at once!");
throw new ArgumentException(paramName: nameof(lp), message: "Too many discs loaded at once!");
}

_cds = lp.Discs.Select(d => d.DiscData).ToArray();
Expand Down

0 comments on commit 1e831e8

Please sign in to comment.