mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
ABSTRACTION HELL
This commit is contained in:
parent
7a9e36cfb4
commit
735a792380
3 changed files with 34 additions and 22 deletions
19
src/g_game.c
19
src/g_game.c
|
|
@ -848,6 +848,15 @@ static INT32 G_GetValueFromControlTable(INT32 deviceID, INT32 deadzone, INT32 *c
|
||||||
return failret;
|
return failret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void G_SetGamepadPrompts(UINT8 p, boolean prompts)
|
||||||
|
{
|
||||||
|
if (showgamepadprompts[p] != prompts)
|
||||||
|
{
|
||||||
|
// CONS_Printf("Setting player %d to gamepadprompts %d\n", p, prompts);
|
||||||
|
showgamepadprompts[p] = prompts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
|
INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
|
||||||
{
|
{
|
||||||
const INT32 deadzone = (JOYAXISRANGE * cv_deadzone[p].value) / FRACUNIT;
|
const INT32 deadzone = (JOYAXISRANGE * cv_deadzone[p].value) / FRACUNIT;
|
||||||
|
|
@ -879,7 +888,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
|
||||||
// This is only intended for P1.
|
// This is only intended for P1.
|
||||||
if (main_player == true)
|
if (main_player == true)
|
||||||
{
|
{
|
||||||
showgamepadprompts[p] = false;
|
G_SetGamepadPrompts(p, false);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -899,7 +908,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
|
||||||
value = G_GetValueFromControlTable(deviceID, deadzone, &(gamecontrol[p][gc][0]));
|
value = G_GetValueFromControlTable(deviceID, deadzone, &(gamecontrol[p][gc][0]));
|
||||||
if (value > 0)
|
if (value > 0)
|
||||||
{
|
{
|
||||||
showgamepadprompts[p] = (deviceID != KEYBOARD_MOUSE_DEVICE);
|
G_SetGamepadPrompts(p, (deviceID != KEYBOARD_MOUSE_DEVICE));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
if (value != NO_BINDS_REACHABLE)
|
if (value != NO_BINDS_REACHABLE)
|
||||||
|
|
@ -913,7 +922,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
|
||||||
value = G_GetValueFromControlTable(KEYBOARD_MOUSE_DEVICE, deadzone, &(gamecontrol[p][gc][0]));
|
value = G_GetValueFromControlTable(KEYBOARD_MOUSE_DEVICE, deadzone, &(gamecontrol[p][gc][0]));
|
||||||
if (value > 0)
|
if (value > 0)
|
||||||
{
|
{
|
||||||
showgamepadprompts[p] = true;
|
G_SetGamepadPrompts(p, false);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
if (value != NO_BINDS_REACHABLE)
|
if (value != NO_BINDS_REACHABLE)
|
||||||
|
|
@ -954,7 +963,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
|
||||||
value = G_GetValueFromControlTable(tryDevice, deadzone, &(gamecontrol[p][gc][0]));
|
value = G_GetValueFromControlTable(tryDevice, deadzone, &(gamecontrol[p][gc][0]));
|
||||||
if (value > 0)
|
if (value > 0)
|
||||||
{
|
{
|
||||||
showgamepadprompts[p] = (tryDevice != KEYBOARD_MOUSE_DEVICE);
|
G_SetGamepadPrompts(p, (tryDevice != KEYBOARD_MOUSE_DEVICE));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
if (value != NO_BINDS_REACHABLE)
|
if (value != NO_BINDS_REACHABLE)
|
||||||
|
|
@ -971,7 +980,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, UINT8 menuPlayers)
|
||||||
value = G_GetValueFromControlTable(deviceID, deadzone, &(gamecontroldefault[gc][0]));
|
value = G_GetValueFromControlTable(deviceID, deadzone, &(gamecontroldefault[gc][0]));
|
||||||
if (value > 0)
|
if (value > 0)
|
||||||
{
|
{
|
||||||
showgamepadprompts[p] = (deviceID != KEYBOARD_MOUSE_DEVICE);
|
G_SetGamepadPrompts(p, (deviceID != KEYBOARD_MOUSE_DEVICE));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1271,27 +1271,19 @@ INT32 G_CheckDoubleUsage(INT32 keynum, INT32 playernum, boolean modify)
|
||||||
|
|
||||||
INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control)
|
INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control)
|
||||||
{
|
{
|
||||||
UINT8 targetplayer = MAXSPLITSCREENPLAYERS;
|
INT32 device = showgamepadprompts[player] ? 1 : KEYBOARD_MOUSE_DEVICE;
|
||||||
for (UINT8 i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
|
||||||
{
|
|
||||||
if (g_localplayers[i] == player)
|
|
||||||
targetplayer = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetplayer == MAXSPLITSCREENPLAYERS)
|
|
||||||
targetplayer = 0;
|
|
||||||
|
|
||||||
INT32 device = showgamepadprompts[targetplayer] ? 1 : KEYBOARD_MOUSE_DEVICE;
|
|
||||||
|
|
||||||
INT32 bestbind = -1; // Bind that matches our input device
|
INT32 bestbind = -1; // Bind that matches our input device
|
||||||
INT32 anybind = -1; // Bind that doesn't match, but is at least for this control
|
INT32 anybind = -1; // Bind that doesn't match, but is at least for this control
|
||||||
|
|
||||||
INT32 bindindex = MAXINPUTMAPPING-1;
|
INT32 bindindex = MAXINPUTMAPPING-1;
|
||||||
|
|
||||||
|
// CONS_Printf("Check bind %d for player %d device %d\n", control, player, device);
|
||||||
|
|
||||||
// PASS 1: Binds that are directly in our active control mapping.
|
// PASS 1: Binds that are directly in our active control mapping.
|
||||||
while (bindindex >= 0) // Prefer earlier binds
|
while (bindindex >= 0) // Prefer earlier binds
|
||||||
{
|
{
|
||||||
INT32 possiblecontrol = gamecontrol[targetplayer][control][bindindex];
|
INT32 possiblecontrol = gamecontrol[player][control][bindindex];
|
||||||
|
|
||||||
bindindex--;
|
bindindex--;
|
||||||
|
|
||||||
|
|
@ -1301,11 +1293,13 @@ INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control)
|
||||||
// if (device is gamepad) == (bound control is in gamepad range) - e.g. if bind matches device
|
// if (device is gamepad) == (bound control is in gamepad range) - e.g. if bind matches device
|
||||||
if ((device != KEYBOARD_MOUSE_DEVICE) == (possiblecontrol >= KEY_JOY1 && possiblecontrol < JOYINPUTEND))
|
if ((device != KEYBOARD_MOUSE_DEVICE) == (possiblecontrol >= KEY_JOY1 && possiblecontrol < JOYINPUTEND))
|
||||||
{
|
{
|
||||||
|
// CONS_Printf("PASS1 found %s\n", G_KeynumToShortString(possiblecontrol));
|
||||||
bestbind = possiblecontrol;
|
bestbind = possiblecontrol;
|
||||||
anybind = possiblecontrol;
|
anybind = possiblecontrol;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// CONS_Printf("PASS1 considering %s\n", G_KeynumToShortString(possiblecontrol));
|
||||||
anybind = possiblecontrol;
|
anybind = possiblecontrol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1326,11 +1320,13 @@ INT32 G_FindPlayerBindForGameControl(INT32 player, gamecontrols_e control)
|
||||||
|
|
||||||
if ((device != KEYBOARD_MOUSE_DEVICE) == (possiblecontrol >= KEY_JOY1 && possiblecontrol < JOYINPUTEND))
|
if ((device != KEYBOARD_MOUSE_DEVICE) == (possiblecontrol >= KEY_JOY1 && possiblecontrol < JOYINPUTEND))
|
||||||
{
|
{
|
||||||
|
// CONS_Printf("PASS2 found %s\n", G_KeynumToShortString(possiblecontrol));
|
||||||
bestbind = possiblecontrol;
|
bestbind = possiblecontrol;
|
||||||
anybind = possiblecontrol;
|
anybind = possiblecontrol;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// CONS_Printf("PASS2 considering %s\n", G_KeynumToShortString(possiblecontrol));
|
||||||
anybind = possiblecontrol;
|
anybind = possiblecontrol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -168,12 +168,19 @@ Draw::TextElement& Draw::TextElement::parse(std::string_view raw)
|
||||||
{
|
{
|
||||||
if (auto id = inputdefinition.find(it->second & (~0xF0)); id != inputdefinition.end()) // This is a game control, do descriptive input translation!
|
if (auto id = inputdefinition.find(it->second & (~0xF0)); id != inputdefinition.end()) // This is a game control, do descriptive input translation!
|
||||||
{
|
{
|
||||||
// Grab our local controls
|
// Grab our local controls - if pid set in the call to parse(), use stplyr's controls
|
||||||
UINT8 targetplayer = as_.value_or(stplyr - players); // If not set in the call to parse(), use stplyr's controls
|
UINT8 localplayer = 0;
|
||||||
if (targetplayer >= MAXPLAYERS)
|
UINT8 indexedplayer = as_.value_or(stplyr - players);
|
||||||
targetplayer = 0;
|
for (UINT8 i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||||
|
{
|
||||||
|
if (g_localplayers[i] == indexedplayer)
|
||||||
|
{
|
||||||
|
localplayer = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
INT32 bind = G_FindPlayerBindForGameControl(targetplayer, id->second);
|
INT32 bind = G_FindPlayerBindForGameControl(localplayer, id->second);
|
||||||
|
|
||||||
if (auto pretty = prettyinputs.find(bind); pretty != prettyinputs.end()) // Gamepad direction or keyboard arrow, use something nice-looking
|
if (auto pretty = prettyinputs.find(bind); pretty != prettyinputs.end()) // Gamepad direction or keyboard arrow, use something nice-looking
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue