Screw around with networking helper init

This commit is contained in:
YoshiRulz 2020-07-26 05:15:56 +10:00
parent 1912851186
commit 1fa7395e20
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
5 changed files with 27 additions and 10 deletions

View File

@ -1,16 +1,25 @@
#nullable enable #nullable enable
using System;
using BizHawk.Client.Common; using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public sealed class CommApi : ICommApi public sealed class CommApi : ICommApi
{ {
public HttpCommunication? HTTP => GlobalWin.httpCommunication; private readonly (HttpCommunication HTTP, MemoryMappedFiles MMF, SocketServer Sockets) _networkingHelpers;
public MemoryMappedFiles? MMF => GlobalWin.memoryMappedFiles; public HttpCommunication? HTTP => _networkingHelpers.HTTP;
public SocketServer? Sockets => GlobalWin.socketServer; public MemoryMappedFiles? MMF => _networkingHelpers.MMF;
public SocketServer? Sockets => _networkingHelpers.Sockets;
public CommApi(Action<string> logCallback, DisplayManager displayManager, InputManager inputManager, IMainFormForApi mainForm)
{
_networkingHelpers = mainForm.NetworkingHelpers;
}
public string? HttpTest() => HTTP == null ? null : string.Join("\n", HttpTestGet(), HTTP.SendScreenshot(), "done testing"); public string? HttpTest() => HTTP == null ? null : string.Join("\n", HttpTestGet(), HTTP.SendScreenshot(), "done testing");

View File

@ -36,6 +36,9 @@ namespace BizHawk.Client.EmuHawk
public string URL_get = null; public string URL_get = null;
public string URL_post = null; public string URL_post = null;
public bool? audiosync = null; public bool? audiosync = null;
public HttpCommunication httpCommunication = null;
public SocketServer socketServer = null;
public MemoryMappedFiles memoryMappedFiles = null;
/// <exception cref="ArgParserException"><c>--socket_ip</c> passed without specifying <c>--socket_port</c> or vice-versa</exception> /// <exception cref="ArgParserException"><c>--socket_ip</c> passed without specifying <c>--socket_port</c> or vice-versa</exception>
public void ParseArguments(string[] args, Func<byte[]> takeScreenshotCallback) public void ParseArguments(string[] args, Func<byte[]> takeScreenshotCallback)
@ -149,15 +152,15 @@ namespace BizHawk.Client.EmuHawk
} }
} }
GlobalWin.httpCommunication = URL_get == null && URL_post == null httpCommunication = URL_get == null && URL_post == null
? null // don't bother ? null // don't bother
: new HttpCommunication(takeScreenshotCallback, URL_get, URL_post); : new HttpCommunication(takeScreenshotCallback, URL_get, URL_post);
GlobalWin.memoryMappedFiles = mmf_filename == null memoryMappedFiles = mmf_filename == null
? null // don't bother ? null // don't bother
: new MemoryMappedFiles(takeScreenshotCallback, mmf_filename); : new MemoryMappedFiles(takeScreenshotCallback, mmf_filename);
if (socket_ip == null && socket_port <= 0) if (socket_ip == null && socket_port <= 0)
{ {
GlobalWin.socketServer = null; // don't bother socketServer = null; // don't bother
} }
else if (socket_ip == null || socket_port <= 0) else if (socket_ip == null || socket_port <= 0)
{ {
@ -165,7 +168,7 @@ namespace BizHawk.Client.EmuHawk
} }
else else
{ {
GlobalWin.socketServer = new SocketServer(takeScreenshotCallback, socket_ip, socket_port); socketServer = new SocketServer(takeScreenshotCallback, socket_ip, socket_port);
} }
} }

View File

@ -28,9 +28,6 @@ namespace BizHawk.Client.EmuHawk
public static GLManager GLManager; public static GLManager GLManager;
public static int ExitCode; public static int ExitCode;
public static HttpCommunication httpCommunication = null;
public static SocketServer socketServer = null;
public static MemoryMappedFiles memoryMappedFiles = null;
/// <summary> /// <summary>
/// Used to disable secondary throttling (e.g. vsync, audio) for unthrottled modes or when the primary (clock) throttle is taking over (e.g. during fast forward/rewind). /// Used to disable secondary throttling (e.g. vsync, audio) for unthrottled modes or when the primary (clock) throttle is taking over (e.g. during fast forward/rewind).

View File

@ -30,6 +30,9 @@ namespace BizHawk.Client.EmuHawk
/// <remarks>only referenced from <see cref="InputApi"/></remarks> /// <remarks>only referenced from <see cref="InputApi"/></remarks>
long MouseWheelTracker { get; } long MouseWheelTracker { get; }
/// <remarks>only referenced from <see cref="CommApi"/></remarks>
(HttpCommunication HTTP, MemoryMappedFiles MMF, SocketServer Sockets) NetworkingHelpers { get; }
/// <remarks>only referenced from <see cref="EmuClientApi"/></remarks> /// <remarks>only referenced from <see cref="EmuClientApi"/></remarks>
bool PauseAvi { set; } bool PauseAvi { set; }

View File

@ -568,6 +568,9 @@ namespace BizHawk.Client.EmuHawk
} }
} }
// set up networking before Lua
NetworkingHelpers = (_argParser.httpCommunication, _argParser.memoryMappedFiles, _argParser.socketServer);
//start Lua Console if requested in the command line arguments //start Lua Console if requested in the command line arguments
if (_argParser.luaConsole) if (_argParser.luaConsole)
{ {
@ -878,6 +881,8 @@ namespace BizHawk.Client.EmuHawk
private Sound Sound => GlobalWin.Sound; private Sound Sound => GlobalWin.Sound;
public CheatCollection CheatList { get; } public CheatCollection CheatList { get; }
public (HttpCommunication HTTP, MemoryMappedFiles MMF, SocketServer Sockets) NetworkingHelpers { get; }
public IRewinder Rewinder { get; private set; } public IRewinder Rewinder { get; private set; }
public void CreateRewinder() public void CreateRewinder()