Skip to content

Commit 590d6bd

Browse files
committed
dsda: split out common buttons from players and only send them once
1 parent 5409d09 commit 590d6bd

File tree

7 files changed

+75
-60
lines changed

7 files changed

+75
-60
lines changed

Assets/dll/dsda.wbx.zst

-265 Bytes
Binary file not shown.

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

+16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ public DoomControllerDeck(DoomControllerTypes controllerType, bool player1Presen
2626
if (player3Present) foreach (var kvp in _port3.Definition.Axes) Definition.Axes.Add(kvp);
2727
if (player4Present) foreach (var kvp in _port4.Definition.Axes) Definition.Axes.Add(kvp);
2828

29+
Definition.BoolButtons.AddRange([
30+
"Change Gamma",
31+
"Automap Toggle",
32+
"Automap +",
33+
"Automap -",
34+
"Automap Full/Zoom",
35+
"Automap Follow",
36+
"Automap Up",
37+
"Automap Down",
38+
"Automap Right",
39+
"Automap Left",
40+
"Automap Grid",
41+
"Automap Mark",
42+
"Automap Clear Marks"
43+
]);
44+
2945
Definition.MakeImmutable();
3046
}
3147

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

+17
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,26 @@ public bool FrameAdvance(IController controller, bool renderVideo, bool renderAu
4040
_controllerDeck.ReadButtons4,
4141
];
4242

43+
int commonButtons = 0;
44+
4345
int playersPresent = Convert.ToInt32(_syncSettings.Player1Present)
4446
| Convert.ToInt32(_syncSettings.Player2Present) << 1
4547
| Convert.ToInt32(_syncSettings.Player3Present) << 2
4648
| Convert.ToInt32(_syncSettings.Player4Present) << 3;
49+
50+
if (controller.IsPressed("Change Gamma")) commonButtons |= (1 << 0);
51+
if (controller.IsPressed("Automap Toggle")) commonButtons |= (1 << 1);
52+
if (controller.IsPressed("Automap +")) commonButtons |= (1 << 2);
53+
if (controller.IsPressed("Automap -")) commonButtons |= (1 << 3);
54+
if (controller.IsPressed("Automap Full/Zoom")) commonButtons |= (1 << 4);
55+
if (controller.IsPressed("Automap Follow")) commonButtons |= (1 << 5);
56+
if (controller.IsPressed("Automap Up")) commonButtons |= (1 << 6);
57+
if (controller.IsPressed("Automap Down")) commonButtons |= (1 << 7);
58+
if (controller.IsPressed("Automap Right")) commonButtons |= (1 << 8);
59+
if (controller.IsPressed("Automap Left")) commonButtons |= (1 << 9);
60+
if (controller.IsPressed("Automap Grid")) commonButtons |= (1 << 10);
61+
if (controller.IsPressed("Automap Mark")) commonButtons |= (1 << 11);
62+
if (controller.IsPressed("Automap Clear Marks")) commonButtons |= (1 << 12);
4763

4864
for (int i = 0; i < 4; i++)
4965
{
@@ -139,6 +155,7 @@ public bool FrameAdvance(IController controller, bool renderVideo, bool renderAu
139155
renderInfo.PlayerPointOfView = _settings.DisplayPlayer - 1;
140156

141157
IsLagFrame = _core.dsda_frame_advance(
158+
commonButtons,
142159
ref players[0],
143160
ref players[1],
144161
ref players[2],

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

+2-28
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,21 @@ public DoomController(int portNum, bool longtics)
7272
"Strafe Right",
7373
"Run",
7474
"Strafe",
75-
"Change Gamma",
7675
"Weapon Select 1",
7776
"Weapon Select 2",
7877
"Weapon Select 3",
7978
"Weapon Select 4",
8079
"Weapon Select 5",
8180
"Weapon Select 6",
8281
"Weapon Select 7",
83-
"Automap Toggle",
84-
"Automap +",
85-
"Automap -",
86-
"Automap Full/Zoom",
87-
"Automap Follow",
88-
"Automap Up",
89-
"Automap Down",
90-
"Automap Right",
91-
"Automap Left",
92-
"Automap Grid",
93-
"Automap Mark",
94-
"Automap Clear Marks",
9582
];
9683

9784
public int ReadButtons(IController c)
9885
{
9986
int result = 0;
10087

101-
if (c.IsPressed($"P{PortNum} Fire")) result |= (1 << 0);
102-
if (c.IsPressed($"P{PortNum} Use")) result |= (1 << 1);
103-
if (c.IsPressed($"P{PortNum} Change Gamma")) result |= (1 << 2);
104-
if (c.IsPressed($"P{PortNum} Automap Toggle")) result |= (1 << 3);
105-
if (c.IsPressed($"P{PortNum} Automap +")) result |= (1 << 4);
106-
if (c.IsPressed($"P{PortNum} Automap -")) result |= (1 << 5);
107-
if (c.IsPressed($"P{PortNum} Automap Full/Zoom")) result |= (1 << 6);
108-
if (c.IsPressed($"P{PortNum} Automap Follow")) result |= (1 << 7);
109-
if (c.IsPressed($"P{PortNum} Automap Up")) result |= (1 << 8);
110-
if (c.IsPressed($"P{PortNum} Automap Down")) result |= (1 << 9);
111-
if (c.IsPressed($"P{PortNum} Automap Right")) result |= (1 << 10);
112-
if (c.IsPressed($"P{PortNum} Automap Left")) result |= (1 << 11);
113-
if (c.IsPressed($"P{PortNum} Automap Grid")) result |= (1 << 12);
114-
if (c.IsPressed($"P{PortNum} Automap Mark")) result |= (1 << 13);
115-
if (c.IsPressed($"P{PortNum} Automap Clear Marks")) result |= (1 << 14);
88+
if (c.IsPressed($"P{PortNum} Fire")) result |= (1 << 0);
89+
if (c.IsPressed($"P{PortNum} Use")) result |= (1 << 1);
11690

11791
return result;
11892
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public struct PackedRenderInfo
8383

8484
[BizImport(CallingConvention.Cdecl)]
8585
public abstract bool dsda_frame_advance(
86+
int commonInputs,
8687
ref PackedPlayerInput player1Inputs,
8788
ref PackedPlayerInput player2Inputs,
8889
ref PackedPlayerInput player3Inputs,

waterbox/dsda/BizhawkInterface.c

+29-30
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22

33
bool foundIWAD = false;
44
bool wipeDone = true;
5-
AllButtons last_buttons[4] = { 0 };
5+
CommonButtons last_buttons = { 0 };
66

7-
void handle_automap_input(AllButtons buttons, int playerId)
7+
void common_input(CommonButtons buttons)
88
{
99
static int bigstate = 0;
10+
m_paninc.y = 0;
11+
m_paninc.x = 0;
1012

11-
if (buttons.AutomapToggle && !last_buttons[playerId].AutomapToggle)
13+
if (buttons.ChangeGamma && !last_buttons.ChangeGamma)
14+
{
15+
dsda_CycleConfig(dsda_config_usegamma, true);
16+
dsda_AddMessage(usegamma == 0 ? GAMMALVL0 :
17+
usegamma == 1 ? GAMMALVL1 :
18+
usegamma == 2 ? GAMMALVL2 :
19+
usegamma == 3 ? GAMMALVL3 :
20+
GAMMALVL4);
21+
}
22+
23+
if (buttons.AutomapToggle && !last_buttons.AutomapToggle)
1224
{
1325
if (automap_active)
1426
{
@@ -19,19 +31,19 @@ void handle_automap_input(AllButtons buttons, int playerId)
1931
AM_Start(true);
2032
}
2133

22-
if (buttons.AutomapFollow && !last_buttons[playerId].AutomapFollow)
34+
if (buttons.AutomapFollow && !last_buttons.AutomapFollow)
2335
{
2436
dsda_ToggleConfig(dsda_config_automap_follow, true);
2537
dsda_AddMessage(automap_follow ? AMSTR_FOLLOWON : AMSTR_FOLLOWOFF);
2638
}
2739

28-
if (buttons.AutomapGrid && !last_buttons[playerId].AutomapGrid)
40+
if (buttons.AutomapGrid && !last_buttons.AutomapGrid)
2941
{
3042
dsda_ToggleConfig(dsda_config_automap_grid, true);
3143
dsda_AddMessage(automap_grid ? AMSTR_GRIDON : AMSTR_GRIDOFF);
3244
}
3345

34-
if (buttons.AutomapMark && !last_buttons[playerId].AutomapMark)
46+
if (buttons.AutomapMark && !last_buttons.AutomapMark)
3547
{
3648
if (!raven)
3749
{
@@ -40,13 +52,13 @@ void handle_automap_input(AllButtons buttons, int playerId)
4052
}
4153
}
4254

43-
if (buttons.AutomapClearMarks && !last_buttons[playerId].AutomapClearMarks)
55+
if (buttons.AutomapClearMarks && !last_buttons.AutomapClearMarks)
4456
{
4557
AM_clearMarks();
4658
dsda_AddMessage(AMSTR_MARKSCLEARED);
4759
}
4860

49-
if (buttons.AutomapFullZoom && !last_buttons[playerId].AutomapFullZoom)
61+
if (buttons.AutomapFullZoom && !last_buttons.AutomapFullZoom)
5062
{
5163
bigstate = !bigstate;
5264
if (bigstate)
@@ -86,9 +98,11 @@ void handle_automap_input(AllButtons buttons, int playerId)
8698
if (buttons.AutomapRight) m_paninc.x += FTOM(map_pan_speed);
8799
if (buttons.AutomapLeft) m_paninc.x -= FTOM(map_pan_speed);
88100
}
101+
102+
last_buttons = buttons;
89103
}
90104

91-
void send_input(struct PackedPlayerInput *inputs, int playerId)
105+
void player_input(struct PackedPlayerInput *inputs, int playerId)
92106
{
93107
local_cmds[playerId].forwardmove = inputs->RunSpeed;
94108
local_cmds[playerId].sidemove = inputs->StrafingSpeed;
@@ -106,19 +120,6 @@ void send_input(struct PackedPlayerInput *inputs, int playerId)
106120
local_cmds[playerId].buttons |= BT_CHANGE;
107121
local_cmds[playerId].buttons |= (inputs->WeaponSelect - 1) << BT_WEAPONSHIFT;
108122
}
109-
110-
if (inputs->Buttons.ChangeGamma && !last_buttons[playerId].ChangeGamma)
111-
{
112-
dsda_CycleConfig(dsda_config_usegamma, true);
113-
dsda_AddMessage(usegamma == 0 ? GAMMALVL0 :
114-
usegamma == 1 ? GAMMALVL1 :
115-
usegamma == 2 ? GAMMALVL2 :
116-
usegamma == 3 ? GAMMALVL3 :
117-
GAMMALVL4);
118-
}
119-
120-
handle_automap_input(inputs->Buttons, playerId);
121-
last_buttons[playerId] = inputs->Buttons;
122123
}
123124

124125
ECL_EXPORT void dsda_get_audio(int *n, void **buffer)
@@ -156,19 +157,17 @@ ECL_EXPORT void dsda_get_video(int *w, int *h, int *pitch, uint8_t **buffer, int
156157
*paletteBuffer = _convertedPaletteBuffer;
157158
}
158159

159-
ECL_EXPORT bool dsda_frame_advance(struct PackedPlayerInput *player1Inputs, struct PackedPlayerInput *player2Inputs, struct PackedPlayerInput *player3Inputs, struct PackedPlayerInput *player4Inputs, struct PackedRenderInfo *renderInfo)
160+
ECL_EXPORT bool dsda_frame_advance(CommonButtons commonButtons, struct PackedPlayerInput *player1Inputs, struct PackedPlayerInput *player2Inputs, struct PackedPlayerInput *player3Inputs, struct PackedPlayerInput *player4Inputs, struct PackedRenderInfo *renderInfo)
160161
{
161162
// Setting inputs
162163
headlessClearTickCommand();
163-
164-
m_paninc.y = 0;
165-
m_paninc.x = 0;
164+
common_input(commonButtons);
166165

167166
// Setting Players inputs
168-
send_input(player1Inputs, 0);
169-
send_input(player2Inputs, 1);
170-
send_input(player3Inputs, 2);
171-
send_input(player4Inputs, 3);
167+
player_input(player1Inputs, 0);
168+
player_input(player2Inputs, 1);
169+
player_input(player3Inputs, 2);
170+
player_input(player4Inputs, 3);
172171

173172
// Enabling/Disabling rendering, as required
174173
if ( renderInfo->RenderVideo) headlessEnableVideoRendering();

waterbox/dsda/BizhawkInterface.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ typedef union
9696
{
9797
bool Fire:1;
9898
bool Use:1;
99+
};
100+
uint8_t data;
101+
} PlayerButtons;
102+
103+
typedef union
104+
{
105+
struct
106+
{
99107
bool ChangeGamma:1;
100108
bool AutomapToggle:1;
101109
bool AutomapZoomIn:1;
@@ -111,7 +119,7 @@ typedef union
111119
bool AutomapClearMarks:1;
112120
};
113121
uint32_t data;
114-
} AllButtons;
122+
} CommonButtons;
115123

116124
struct InitSettings
117125
{
@@ -133,7 +141,7 @@ struct PackedPlayerInput
133141
int StrafingSpeed;
134142
int TurningSpeed;
135143
int WeaponSelect;
136-
AllButtons Buttons;
144+
PlayerButtons Buttons;
137145
int FlyLook;
138146
int ArtifactUse;
139147
int Jump;

0 commit comments

Comments
 (0)