Skip to content

Commit eb94bd8

Browse files
committed
dsda: completely remake input system init
1 parent 498fabc commit eb94bd8

File tree

9 files changed

+141
-340
lines changed

9 files changed

+141
-340
lines changed

src/BizHawk.Client.Common/movie/import/DoomLmpImport.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected override void RunImport()
197197

198198
DSDA.DoomSyncSettings syncSettings = new()
199199
{
200-
InputFormat = DoomControllerTypes.Doom,
200+
InputFormat = DSDA.ControllerTypes.Doom,
201201
CompatibilityLevel = compLevel,
202202
SkillLevel = skill,
203203
InitialEpisode = episode,
@@ -226,15 +226,7 @@ protected override void RunImport()
226226
*/
227227
Result.Movie.SyncSettingsJson = ConfigService.SaveWithType(syncSettings);
228228

229-
var doomController = new DoomControllerDeck(
230-
DoomControllerTypes.Doom,
231-
syncSettings.Player1Present,
232-
syncSettings.Player2Present,
233-
syncSettings.Player3Present,
234-
syncSettings.Player4Present,
235-
turningResolution == DSDA.TurningResolution.Longtics);
236-
237-
var controller = new SimpleController(doomController.Definition);
229+
var controller = new SimpleController(DSDA.CreateControllerDefinition(syncSettings));
238230
controller.Definition.BuildMnemonicsCache(Result.Movie.SystemID);
239231
Result.Movie.LogKey = Bk2LogEntryGenerator.GenerateLogKey(controller.Definition);
240232

src/BizHawk.Client.Common/movie/import/HereticLmpImport.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected override void RunImport()
1818
Result.Movie.SystemID = VSystemID.Raw.Doom;
1919
DSDA.DoomSyncSettings syncSettings = new()
2020
{
21-
InputFormat = DoomControllerTypes.Heretic,
21+
InputFormat = DSDA.ControllerTypes.Heretic,
2222
MultiplayerMode = DSDA.MultiplayerMode.Single_Coop,
2323
MonstersRespawn = false,
2424
FastMonsters = false,
@@ -35,9 +35,8 @@ protected override void RunImport()
3535
RenderWipescreen = false,
3636
};
3737
Result.Movie.SyncSettingsJson = ConfigService.SaveWithType(syncSettings);
38-
39-
var hereticController = new HereticController(1, false);
40-
var controller = new SimpleController(hereticController.Definition);
38+
39+
var controller = new SimpleController(DSDA.CreateControllerDefinition(syncSettings));
4140
controller.Definition.BuildMnemonicsCache(Result.Movie.SystemID);
4241
void ParsePlayer(string playerPfx)
4342
{

src/BizHawk.Client.Common/movie/import/HexenLmpImport.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected override void RunImport()
1818
Result.Movie.SystemID = VSystemID.Raw.Doom;
1919
DSDA.DoomSyncSettings syncSettings = new()
2020
{
21-
InputFormat = DoomControllerTypes.Hexen,
21+
InputFormat = DSDA.ControllerTypes.Hexen,
2222
MultiplayerMode = DSDA.MultiplayerMode.Single_Coop,
2323
MonstersRespawn = false,
2424
FastMonsters = false,
@@ -47,9 +47,8 @@ protected override void RunImport()
4747
_ = input[i++]; // player 8 isPresent
4848
_ = input[i++]; // player 8 class
4949
Result.Movie.SyncSettingsJson = ConfigService.SaveWithType(syncSettings);
50-
51-
var hexenController = new HexenController(1, false);
52-
var controller = new SimpleController(hexenController.Definition);
50+
51+
var controller = new SimpleController(DSDA.CreateControllerDefinition(syncSettings));
5352
controller.Definition.BuildMnemonicsCache(Result.Movie.SystemID);
5453
void ParsePlayer(string playerPfx)
5554
{
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using System.Linq;
2+
3+
using BizHawk.Common;
4+
using BizHawk.Common.CollectionExtensions;
5+
using BizHawk.Emulation.Common;
6+
7+
namespace BizHawk.Emulation.Cores.Computers.Doom
8+
{
9+
public partial class DSDA
10+
{
11+
public static ControllerDefinition CreateControllerDefinition(DoomSyncSettings settings)
12+
{
13+
var controller = new ControllerDefinition($"{settings.InputFormat} Input Format");
14+
var longtics = settings.TurningResolution == TurningResolution.Longtics;
15+
int playersPresent = Convert.ToInt32(settings.Player1Present)
16+
| Convert.ToInt32(settings.Player2Present) << 1
17+
| Convert.ToInt32(settings.Player3Present) << 2
18+
| Convert.ToInt32(settings.Player4Present) << 3;
19+
20+
for (int i = 0; i < 4; i++)
21+
{
22+
if ((playersPresent & (1 << i)) is not 0)
23+
{
24+
var port = i + 1;
25+
26+
controller
27+
.AddAxis($"P{port} Run Speed", (-50).RangeTo(50), 0)
28+
.AddAxis($"P{port} Strafing Speed", (-50).RangeTo(50), 0)
29+
.AddAxis($"P{port} Turning Speed", (-128).RangeTo(127), 0);
30+
31+
// editing a short in tastudio would be a nightmare, so we split it:
32+
// high byte represents shorttics mode and whole angle values
33+
// low byte is fractional part only available with longtics
34+
if (longtics)
35+
{
36+
controller.AddAxis($"P{port} Turning Speed Frac.", (-255).RangeTo(255), 0);
37+
}
38+
39+
controller
40+
.AddAxis($"P{port} Weapon Select", (0).RangeTo(7), 0)
41+
.AddAxis($"P{port} Mouse Running", (-128).RangeTo(127), 0)
42+
// current max raw mouse delta is 180
43+
.AddAxis($"P{port} Mouse Turning", (longtics ? -180 : -128).RangeTo(longtics ? 180 : 127), 0);
44+
45+
if (settings.InputFormat is not ControllerTypes.Doom)
46+
{
47+
controller
48+
.AddAxis($"P{port} Fly / Look", (-7).RangeTo(7), 0)
49+
.AddAxis($"P{port} Use Artifact", (0).RangeTo(10), 0);
50+
}
51+
52+
controller.BoolButtons.AddRange([
53+
$"P{port} Fire",
54+
$"P{port} Use",
55+
$"P{port} Forward",
56+
$"P{port} Backward",
57+
$"P{port} Turn Left",
58+
$"P{port} Turn Right",
59+
$"P{port} Strafe Left",
60+
$"P{port} Strafe Right",
61+
$"P{port} Run",
62+
$"P{port} Strafe",
63+
$"P{port} Weapon Select 1",
64+
$"P{port} Weapon Select 2",
65+
$"P{port} Weapon Select 3",
66+
$"P{port} Weapon Select 4",
67+
]);
68+
69+
if (settings.InputFormat is ControllerTypes.Hexen)
70+
{
71+
controller.BoolButtons.AddRange([
72+
$"P{port} Jump",
73+
$"P{port} End Player",
74+
]);
75+
}
76+
else
77+
{
78+
controller.BoolButtons.AddRange([
79+
$"P{port} Weapon Select 5",
80+
$"P{port} Weapon Select 6",
81+
$"P{port} Weapon Select 7",
82+
]);
83+
}
84+
}
85+
}
86+
87+
controller.BoolButtons.AddRange([
88+
"Change Gamma",
89+
"Automap Toggle",
90+
"Automap +",
91+
"Automap -",
92+
"Automap Full/Zoom",
93+
"Automap Follow",
94+
"Automap Up",
95+
"Automap Down",
96+
"Automap Right",
97+
"Automap Left",
98+
"Automap Grid",
99+
"Automap Mark",
100+
"Automap Clear Marks"
101+
]);
102+
103+
return controller.MakeImmutable();
104+
}
105+
}
106+
}

src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.ControllerDeck.cs

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

src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IEmulator.cs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
66
public partial class DSDA : IEmulator
77
{
88
public IEmulatorServiceProvider ServiceProvider { get; }
9-
public ControllerDefinition ControllerDefinition => _controllerDeck.Definition;
9+
public ControllerDefinition ControllerDefinition { get; private set; }
1010
public int Frame { get; private set; }
1111
public string SystemId => VSystemID.Raw.Doom;
1212
public bool DeterministicEmulation => true;
@@ -22,14 +22,6 @@ public bool FrameAdvance(IController controller, bool renderVideo, bool renderAu
2222
new LibDSDA.PackedPlayerInput()
2323
];
2424

25-
ReadPort[] buttonsReaders =
26-
[
27-
_controllerDeck.ReadButtons1,
28-
_controllerDeck.ReadButtons2,
29-
_controllerDeck.ReadButtons3,
30-
_controllerDeck.ReadButtons4,
31-
];
32-
3325
int commonButtons = 0;
3426

3527
int playersPresent = Convert.ToInt32(_syncSettings.Player1Present)
@@ -149,19 +141,19 @@ public bool FrameAdvance(IController controller, bool renderVideo, bool renderAu
149141
}
150142

151143
// bool buttons
152-
var actionsBitfield = buttonsReaders[i](controller);
153-
players[i].Buttons = actionsBitfield;
144+
if (controller.IsPressed($"P{port} Fire")) players[i].Buttons |= (1 << 0);
145+
if (controller.IsPressed($"P{port} Use")) players[i].Buttons |= (1 << 1);
154146

155147
// Raven Games
156-
if (_syncSettings.InputFormat is DoomControllerTypes.Heretic or DoomControllerTypes.Hexen)
148+
if (_syncSettings.InputFormat is not ControllerTypes.Doom)
157149
{
158150
players[i].FlyLook = controller.AxisValue($"P{port} Fly / Look");
159151
players[i].ArtifactUse = controller.AxisValue($"P{port} Use Artifact");
160152

161-
if (_syncSettings.InputFormat is DoomControllerTypes.Hexen)
153+
if (_syncSettings.InputFormat is ControllerTypes.Hexen)
162154
{
163-
players[i].Jump = (actionsBitfield & 0b01000) >> 3;
164-
players[i].EndPlayer = (actionsBitfield & 0b10000) >> 4;
155+
players[i].Jump = Convert.ToInt32(controller.IsPressed($"P{port} Jump"));
156+
players[i].EndPlayer = Convert.ToInt32(controller.IsPressed($"P{port} End Player"));
165157
}
166158
}
167159
}
@@ -175,16 +167,16 @@ public bool FrameAdvance(IController controller, bool renderVideo, bool renderAu
175167
HeadsUpMode = (int)_settings.HeadsUpMode,
176168
MapDetails = (int)_settings.MapDetails,
177169
MapOverlay = (int)_settings.MapOverlay,
178-
RenderVideo = renderVideo ? 1 : 0,
179-
RenderAudio = renderAudio ? 1 : 0,
180-
ShowMessages = _settings.ShowMessages ? 1 : 0,
181-
ReportSecrets = _settings.ReportSecrets ? 1 : 0,
182-
DsdaExHud = _settings.DsdaExHud ? 1 : 0,
183-
DisplayCoordinates = _settings.DisplayCoordinates ? 1 : 0,
184-
DisplayCommands = _settings.DisplayCommands ? 1 : 0,
185-
MapTotals = _settings.MapTotals ? 1 : 0,
186-
MapTime = _settings.MapTime ? 1 : 0,
187-
MapCoordinates = _settings.MapCoordinates ? 1 : 0,
170+
RenderVideo = Convert.ToInt32(renderVideo),
171+
RenderAudio = Convert.ToInt32(renderAudio),
172+
ShowMessages = Convert.ToInt32(_settings.ShowMessages),
173+
ReportSecrets = Convert.ToInt32(_settings.ReportSecrets),
174+
DsdaExHud = Convert.ToInt32(_settings.DsdaExHud),
175+
DisplayCoordinates = Convert.ToInt32(_settings.DisplayCoordinates),
176+
DisplayCommands = Convert.ToInt32(_settings.DisplayCommands),
177+
MapTotals = Convert.ToInt32(_settings.MapTotals),
178+
MapTime = Convert.ToInt32(_settings.MapTime),
179+
MapCoordinates = Convert.ToInt32(_settings.MapCoordinates),
188180
PlayerPointOfView = _settings.DisplayPlayer - 1,
189181
};
190182

src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.ISettable.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
99
{
1010
public partial class DSDA : ISettable<DSDA.DoomSettings, DSDA.DoomSyncSettings>
1111
{
12+
public enum ControllerTypes
13+
{
14+
Doom,
15+
Heretic,
16+
Hexen
17+
}
18+
1219
public enum CompatibilityLevel : int
1320
{
1421
[Display(Name = "0 - Doom v1.2")]
@@ -272,11 +279,11 @@ public PutSettingsDirtyBits PutSettings(DoomSettings o)
272279
[CoreSettings]
273280
public class DoomSyncSettings
274281
{
275-
[DefaultValue(DoomControllerTypes.Doom)]
282+
[DefaultValue(ControllerTypes.Doom)]
276283
[DisplayName("Input Format")]
277284
[Description("The format provided for the players' input.")]
278285
[TypeConverter(typeof(DescribableEnumConverter))]
279-
public DoomControllerTypes InputFormat { get; set; }
286+
public ControllerTypes InputFormat { get; set; }
280287

281288
[DisplayName("Player 1 Present")]
282289
[Description("Specifies if player 1 is present")]

src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,8 @@ public DSDA(CoreLoadParameters<DoomSettings, DoomSyncSettings> lp)
2929
ServiceProvider = ser;
3030
_finalSyncSettings = _syncSettings = lp.SyncSettings ?? new DoomSyncSettings();
3131
_settings = lp.Settings ?? new DoomSettings();
32-
_controllerDeck = new DoomControllerDeck(
33-
_syncSettings.InputFormat,
34-
_syncSettings.Player1Present,
35-
_syncSettings.Player2Present,
36-
_syncSettings.Player3Present,
37-
_syncSettings.Player4Present,
38-
_syncSettings.TurningResolution == TurningResolution.Longtics);
3932
_loadCallback = LoadCallback;
33+
ControllerDefinition = CreateControllerDefinition(_syncSettings);
4034

4135
// Gathering information for the rest of the wads
4236
_wadFiles = lp.Roms;
@@ -219,7 +213,6 @@ private void ConditionalArg(bool condition, string setting)
219213
private readonly WaterboxHost _elf;
220214
private readonly LibDSDA _core;
221215
private readonly LibDSDA.load_archive_cb _loadCallback;
222-
private readonly DoomControllerDeck _controllerDeck;
223216
private readonly Point _nativeResolution = new(320, 200);
224217
private readonly int[] _runSpeeds = [ 25, 50 ];
225218
private readonly int[] _strafeSpeeds = [ 24, 40 ];

0 commit comments

Comments
 (0)