Skip to content

Commit c11d410

Browse files
committed
Remove IEmuClientApi.Get/SetInput and supporting types, and cleanup
what's a deprecation cycle also -1k LOC whoo
1 parent ef0b380 commit c11d410

File tree

8 files changed

+49
-951
lines changed

8 files changed

+49
-951
lines changed

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

Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Drawing;
43
using System.IO;
5-
using System.Linq;
6-
using System.Threading.Tasks;
74

85
using BizHawk.Common;
96
using BizHawk.Emulation.Common;
10-
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
11-
using BizHawk.Emulation.Cores.PCEngine;
12-
using BizHawk.Emulation.Cores.Sega.MasterSystem;
137

148
namespace BizHawk.Client.Common
159
{
1610
public sealed class EmuClientApi : IEmuClientApi
1711
{
18-
private readonly List<Joypad> _allJoyPads;
19-
2012
private readonly Config _config;
2113

2214
private readonly IWindowCoordsTransformer _displayManager;
2315

24-
private readonly InputManager _inputManager;
25-
2616
private readonly IMainFormForApi _mainForm;
2717

2818
private readonly Action<string> _logCallback;
@@ -31,43 +21,6 @@ public sealed class EmuClientApi : IEmuClientApi
3121

3222
private readonly IGameInfo Game;
3323

34-
private readonly IReadOnlyCollection<JoypadButton> JoypadButtonsArray = Enum.GetValues(typeof(JoypadButton)).Cast<JoypadButton>().ToList(); //TODO can the return of GetValues be cast to JoypadButton[]? --yoshi
35-
36-
private readonly JoypadStringToEnumConverter JoypadConverter = new JoypadStringToEnumConverter();
37-
38-
/// <remarks>future humans: if this is broken, rewrite the caller instead if fixing it</remarks>
39-
private SystemInfo RunningSystem
40-
{
41-
get
42-
{
43-
switch (Emulator.SystemId)
44-
{
45-
case "PCE" when Emulator is PCEngine pceHawk:
46-
return pceHawk.Type switch
47-
{
48-
NecSystemType.TurboGrafx => SystemInfo.PCE,
49-
NecSystemType.TurboCD => SystemInfo.PCECD,
50-
NecSystemType.SuperGrafx => SystemInfo.SGX,
51-
_ => throw new ArgumentOutOfRangeException()
52-
};
53-
case "PCE":
54-
return SystemInfo.PCE;
55-
case "SMS":
56-
var sms = (SMS) Emulator;
57-
return sms.IsSG1000
58-
? SystemInfo.SG
59-
: sms.IsGameGear
60-
? SystemInfo.GG
61-
: SystemInfo.SMS;
62-
case "GB":
63-
if (Emulator is Gameboy gb) return gb.IsCGBMode() ? SystemInfo.GBC : SystemInfo.GB;
64-
return SystemInfo.DualGB;
65-
default:
66-
return SystemInfo.FindByCoreSystem(SystemIdConverter.Convert(Emulator.SystemId));
67-
}
68-
}
69-
}
70-
7124
public static readonly BizHawkSystemIdToEnumConverter SystemIdConverter = new BizHawkSystemIdToEnumConverter();
7225

7326
private readonly IVideoProvider VideoProvider;
@@ -82,27 +35,14 @@ private SystemInfo RunningSystem
8235

8336
public event StateSavedEventHandler StateSaved;
8437

85-
public EmuClientApi(Action<string> logCallback, IMainFormForApi mainForm, IWindowCoordsTransformer displayManager, InputManager inputManager, Config config, IEmulator emulator, IGameInfo game)
38+
public EmuClientApi(Action<string> logCallback, IMainFormForApi mainForm, IWindowCoordsTransformer displayManager, Config config, IEmulator emulator, IGameInfo game)
8639
{
8740
_config = config;
8841
_displayManager = displayManager;
8942
Emulator = emulator;
9043
Game = game;
91-
_inputManager = inputManager;
9244
_logCallback = logCallback;
9345
_mainForm = mainForm;
94-
95-
try
96-
{
97-
_allJoyPads = new List<Joypad>(RunningSystem.MaxControllers);
98-
for (var i = 1; i <= RunningSystem.MaxControllers; i++)
99-
_allJoyPads.Add(new Joypad(RunningSystem, i));
100-
}
101-
catch (Exception e)
102-
{
103-
Console.Error.WriteLine("Apihawk is garbage and may not work this session.");
104-
Console.Error.WriteLine(e);
105-
}
10646
VideoProvider = Emulator.AsVideoProviderOrDefault();
10747
}
10848

@@ -149,38 +89,6 @@ public void FrameSkip(int numFrames)
14989
_mainForm.FrameSkipMessage();
15090
}
15191

152-
private void GetAllInputs()
153-
{
154-
var joypadAdapter = _inputManager.AutofireStickyXorAdapter;
155-
156-
var pressedButtons = joypadAdapter.Definition.BoolButtons.Where(b => joypadAdapter.IsPressed(b));
157-
158-
foreach (var j in _allJoyPads) j.ClearInputs();
159-
160-
Parallel.ForEach(pressedButtons, button =>
161-
{
162-
if (RunningSystem == SystemInfo.GB) _allJoyPads[0].AddInput(JoypadConverter.Convert(button));
163-
else if (int.TryParse(button.Substring(1, 2), out var player)) _allJoyPads[player - 1].AddInput(JoypadConverter.Convert(button.Substring(3)));
164-
});
165-
166-
if ((RunningSystem.AvailableButtons & JoypadButton.AnalogStick) == JoypadButton.AnalogStick)
167-
{
168-
for (var i = 1; i <= RunningSystem.MaxControllers; i++)
169-
{
170-
_allJoyPads[i - 1].AnalogX = joypadAdapter.AxisValue($"P{i} X Axis");
171-
_allJoyPads[i - 1].AnalogY = joypadAdapter.AxisValue($"P{i} Y Axis");
172-
}
173-
}
174-
}
175-
176-
public Joypad GetInput(int player)
177-
{
178-
if (!1.RangeTo(RunningSystem.MaxControllers).Contains(player))
179-
throw new IndexOutOfRangeException($"{RunningSystem.DisplayName} does not support {player} controller(s)");
180-
GetAllInputs();
181-
return _allJoyPads[player - 1];
182-
}
183-
18492
public bool GetSoundOn() => _config.SoundEnabled;
18593

18694
public int GetTargetScanlineIntensity() => _config.TargetScanlineFilterIntensity;
@@ -273,39 +181,6 @@ public void SetGameExtraPadding(int left, int top, int right, int bottom)
273181
_mainForm.FrameBufferResized();
274182
}
275183

276-
public void SetInput(int player, Joypad joypad)
277-
{
278-
if (!1.RangeTo(RunningSystem.MaxControllers).Contains(player)) throw new IndexOutOfRangeException($"{RunningSystem.DisplayName} does not support {player} controller(s)");
279-
280-
if (joypad.Inputs == 0)
281-
{
282-
_inputManager.AutofireStickyXorAdapter.ClearStickies();
283-
}
284-
else
285-
{
286-
foreach (var button in JoypadButtonsArray.Where(button => joypad.Inputs.HasFlag(button)))
287-
{
288-
_inputManager.AutofireStickyXorAdapter.SetSticky(
289-
RunningSystem == SystemInfo.GB
290-
? $"{JoypadConverter.ConvertBack(button, RunningSystem)}"
291-
: $"P{player} {JoypadConverter.ConvertBack(button, RunningSystem)}",
292-
isSticky: true
293-
);
294-
}
295-
}
296-
297-
#if false // Using this breaks joypad usage (even in UI); have to figure out why
298-
if ((RunningSystem.AvailableButtons & JoypadButton.AnalogStick) == JoypadButton.AnalogStick)
299-
{
300-
for (var i = 1; i <= RunningSystem.MaxControllers; i++)
301-
{
302-
_inputManager.AutofireStickyXorAdapter.SetAxis($"P{i} X Axis", _allJoyPads[i - 1].AnalogX);
303-
_inputManager.AutofireStickyXorAdapter.SetAxis($"P{i} Y Axis", _allJoyPads[i - 1].AnalogY);
304-
}
305-
}
306-
#endif
307-
}
308-
309184
public void SetScreenshotOSD(bool value) => _config.ScreenshotCaptureOsd = value;
310185

311186
public void SetSoundOn(bool enable)

src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ public interface IEmuClientApi : IExternalApi
6363

6464
void FrameSkip(int numFrames);
6565

66-
/// <summary>
67-
/// Gets a <see cref="Joypad"/> for specified player
68-
/// </summary>
69-
/// <param name="player">Player (one based) you want current inputs</param>
70-
/// <returns>A <see cref="Joypad"/> populated with current inputs</returns>
71-
/// <exception cref="IndexOutOfRangeException">Raised when you specify a player less than 1 or greater than maximum allows (see SystemInfo class to get this information)</exception>
72-
Joypad GetInput(int player);
73-
7466
bool GetSoundOn();
7567

7668
int GetTargetScanlineIntensity();
@@ -178,15 +170,6 @@ public interface IEmuClientApi : IExternalApi
178170
/// <param name="bottom">Bottom padding</param>
179171
void SetGameExtraPadding(int left, int top = 0, int right = 0, int bottom = 0);
180172

181-
/// <summary>
182-
/// Set inputs in specified <see cref="Joypad"/> to specified player
183-
/// </summary>
184-
/// <param name="player">Player (one based) whom inputs must be set</param>
185-
/// <param name="joypad"><see cref="Joypad"/> with inputs</param>
186-
/// <exception cref="IndexOutOfRangeException">Raised when you specify a player less than 1 or greater than maximum allows (see SystemInfo class to get this information)</exception>
187-
/// <remarks>Still have some strange behaviour with multiple inputs; so this feature is still in beta</remarks>
188-
void SetInput(int player, Joypad joypad);
189-
190173
void SetScreenshotOSD(bool value);
191174

192175
void SetSoundOn(bool enable);

src/BizHawk.Client.Common/Api/Joypad.cs

Lines changed: 0 additions & 101 deletions
This file was deleted.

src/BizHawk.Client.Common/Api/JoypadButton.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)