- more cleanup

Moving init code and key binding getter to backend
This commit is contained in:
Christoph Oelckers 2019-10-28 07:05:32 +01:00
parent 4f4fc1a8d4
commit 901b86577e
10 changed files with 49 additions and 125 deletions

View File

@ -75,14 +75,6 @@ void ctrlInit(void)
KB_FlushKeyboardQueueScans(); KB_FlushKeyboardQueueScans();
CONFIG_SetupMouse(); CONFIG_SetupMouse();
CONFIG_SetupJoystick(); CONFIG_SetupJoystick();
CONTROL_JoystickEnabled = (in_joystick && CONTROL_JoyPresent);
CONTROL_MouseEnabled = (in_mouse && CONTROL_MousePresent);
CONTROL_SmoothMouse = in_mousesmoothing;
// JBF 20040215: evil and nasty place to do this, but joysticks are evil and nasty too
for (int i = 0; i < joystick.numAxes; i++)
joySetDeadZone(i, JoystickAnalogueDead[i], JoystickAnalogueSaturate[i]);
} }
void ctrlTerm(void) void ctrlTerm(void)

View File

@ -343,6 +343,41 @@ void CONFIG_SetDefaultKeys(const char *defbinds, bool lazy/*=false*/)
} }
} }
// FIXME: Consider the mouse as well!
FString CONFIG_GetBoundKeyForLastInput(int gameFunc)
{
if (CONTROL_LastSeenInput == LastSeenInput::Joystick)
{
char const * joyname = CONFIG_GetGameFuncOnJoystick(gameFunc);
if (joyname != nullptr && joyname[0] != '\0')
{
return joyname;
}
char const * keyname = CONFIG_GetGameFuncOnKeyboard(gameFunc);
if (keyname != nullptr && keyname[0] != '\0')
{
return keyname;
}
}
else
{
char const * keyname = CONFIG_GetGameFuncOnKeyboard(gameFunc);
if (keyname != nullptr && keyname[0] != '\0')
{
return keyname;
}
char const * joyname = CONFIG_GetGameFuncOnJoystick(gameFunc);
if (joyname != nullptr && joyname[0] != '\0')
{
return joyname;
}
return "UNBOUND";
}
}
//========================================================================== //==========================================================================
// //
// //
@ -633,6 +668,7 @@ void CONFIG_SetupMouse(void)
CONTROL_MapDigitalAxis(i, MouseDigitalFunctions[i][1], 1, controldevice_mouse); CONTROL_MapDigitalAxis(i, MouseDigitalFunctions[i][1], 1, controldevice_mouse);
CONTROL_SetAnalogAxisScale(i, MouseAnalogueScale[i], controldevice_mouse); CONTROL_SetAnalogAxisScale(i, MouseAnalogueScale[i], controldevice_mouse);
} }
CONTROL_MouseEnabled = (in_mouse && CONTROL_MousePresent);
} }
@ -707,6 +743,13 @@ void CONFIG_SetupJoystick(void)
CONTROL_SetAnalogAxisScale(i, JoystickAnalogueScale[i], controldevice_joystick); CONTROL_SetAnalogAxisScale(i, JoystickAnalogueScale[i], controldevice_joystick);
CONTROL_SetAnalogAxisInvert(i, JoystickAnalogueInvert[i], controldevice_joystick); CONTROL_SetAnalogAxisInvert(i, JoystickAnalogueInvert[i], controldevice_joystick);
} }
CONTROL_JoystickEnabled = (in_joystick && CONTROL_JoyPresent);
// JBF 20040215: evil and nasty place to do this, but joysticks are evil and nasty too
for (int i=0; i<joystick.numAxes; i++)
joySetDeadZone(i,JoystickAnalogueDead[i],JoystickAnalogueSaturate[i]);
} }
static void CONFIG_SetJoystickButtonFunction(int i, int j, int function) static void CONFIG_SetJoystickButtonFunction(int i, int j, int function)
@ -964,11 +1007,8 @@ char const* CONFIG_GetGameFuncOnJoystick(int gameFunc)
for (int i = 0; i < joystick.numAxes; ++i) for (int i = 0; i < joystick.numAxes; ++i)
for (int j = 0; j < 2; ++j) for (int j = 0; j < 2; ++j)
if (JoystickDigitalFunctions[i][j] == gameFunc) if (JoystickDigitalFunctions[i][j] == gameFunc)
return joyGetName(0, i);
return "";
}
void CONFIG_InitMouseAndController() void CONFIG_InitMouseAndController()
{ {

View File

@ -58,8 +58,8 @@ void CONFIG_InitMouseAndController();
void CONFIG_SetGameControllerDefaultsStandard(); void CONFIG_SetGameControllerDefaultsStandard();
void CONFIG_SetGameControllerDefaultsPro(); void CONFIG_SetGameControllerDefaultsPro();
void CONFIG_SetGameControllerDefaultsClear(); void CONFIG_SetGameControllerDefaultsClear();
char const* CONFIG_GetGameFuncOnJoystick(int gameFunc);
char const* CONFIG_GetGameFuncOnKeyboard(int gameFunc); FString CONFIG_GetBoundKeyForLastInput(int gameFunc);
int osdcmd_bind(osdcmdptr_t parm); int osdcmd_bind(osdcmdptr_t parm);
int osdcmd_unbindall(osdcmdptr_t); int osdcmd_unbindall(osdcmdptr_t);

View File

@ -6486,13 +6486,6 @@ int app_main(int argc, const char * const*argv)
{ {
CONFIG_SetupMouse(); CONFIG_SetupMouse();
CONFIG_SetupJoystick(); CONFIG_SetupJoystick();
CONTROL_JoystickEnabled = (in_joystick && CONTROL_JoyPresent);
CONTROL_MouseEnabled = (in_mouse && CONTROL_MousePresent);
// JBF 20040215: evil and nasty place to do this, but joysticks are evil and nasty too
for (int i=0; i<joystick.numAxes; i++)
joySetDeadZone(i,JoystickAnalogueDead[i],JoystickAnalogueSaturate[i]);
} }
#ifdef HAVE_CLIPSHAPE_FEATURE #ifdef HAVE_CLIPSHAPE_FEATURE

View File

@ -3682,46 +3682,10 @@ badindex:
static char const s_KeyboardFormat[] = "[%s]"; static char const s_KeyboardFormat[] = "[%s]";
static char const s_JoystickFormat[] = "(%s)"; static char const s_JoystickFormat[] = "(%s)";
static char const s_Unbound[] = "UNBOUND";
if (CONTROL_LastSeenInput == LastSeenInput::Joystick) auto binding = CONFIG_GetBoundKeyForLastInput(gameFunc);
{ if (binding.Len()) snprintf(apStrings[quoteIndex], MAXQUOTELEN, "(%s)", binding.GetChars());
char const * joyname = CONFIG_GetGameFuncOnJoystick(gameFunc); dispatch();
if (joyname != nullptr && joyname[0] != '\0')
{
snprintf(apStrings[quoteIndex], MAXQUOTELEN, s_JoystickFormat, joyname);
dispatch();
}
char const * keyname = CONFIG_GetGameFuncOnKeyboard(gameFunc);
if (keyname != nullptr && keyname[0] != '\0')
{
snprintf(apStrings[quoteIndex], MAXQUOTELEN, s_KeyboardFormat, keyname);
dispatch();
}
snprintf(apStrings[quoteIndex], MAXQUOTELEN, s_JoystickFormat, s_Unbound);
}
else
{
char const * keyname = CONFIG_GetGameFuncOnKeyboard(gameFunc);
if (keyname != nullptr && keyname[0] != '\0')
{
snprintf(apStrings[quoteIndex], MAXQUOTELEN, s_KeyboardFormat, keyname);
dispatch();
}
char const * joyname = CONFIG_GetGameFuncOnJoystick(gameFunc);
if (joyname != nullptr && joyname[0] != '\0')
{
snprintf(apStrings[quoteIndex], MAXQUOTELEN, s_JoystickFormat, joyname);
dispatch();
}
snprintf(apStrings[quoteIndex], MAXQUOTELEN, s_KeyboardFormat, s_Unbound);
}
dispatch();
} }
vInstruction(CON_QSUBSTR): vInstruction(CON_QSUBSTR):

View File

@ -997,16 +997,12 @@ void G_DisplayRest(int32_t smoothratio)
} }
else else
{ {
#ifdef __ANDROID__
CONTROL_Android_ScrollMap(&ud.fola, &ud.folx, &ud.foly, &pp->zoom);
#else
if (!ud.pause_on) if (!ud.pause_on)
{ {
ud.fola += ud.folavel>>3; ud.fola += ud.folavel>>3;
ud.folx += (ud.folfvel*sintable[(512+2048-ud.fola)&2047])>>14; ud.folx += (ud.folfvel*sintable[(512+2048-ud.fola)&2047])>>14;
ud.foly += (ud.folfvel*sintable[(512+1024-512-ud.fola)&2047])>>14; ud.foly += (ud.folfvel*sintable[(512+1024-512-ud.fola)&2047])>>14;
} }
#endif
cposx = ud.folx; cposx = ud.folx;
cposy = ud.foly; cposy = ud.foly;
cang = ud.fola; cang = ud.fola;

View File

@ -7869,13 +7869,6 @@ int app_main(int argc, char const * const * argv)
{ {
CONFIG_SetupMouse(); CONFIG_SetupMouse();
CONFIG_SetupJoystick(); CONFIG_SetupJoystick();
CONTROL_JoystickEnabled = (in_joystick && CONTROL_JoyPresent);
CONTROL_MouseEnabled = (in_mouse && CONTROL_MousePresent);
// JBF 20040215: evil and nasty place to do this, but joysticks are evil and nasty too
for (bssize_t i=0; i<joystick.numAxes; i++)
joySetDeadZone(i,JoystickAnalogueDead[i],JoystickAnalogueSaturate[i]);
} }
#ifdef HAVE_CLIPSHAPE_FEATURE #ifdef HAVE_CLIPSHAPE_FEATURE

View File

@ -1030,16 +1030,12 @@ void G_DisplayRest(int32_t smoothratio)
} }
else else
{ {
#ifdef __ANDROID__
CONTROL_Android_ScrollMap(&ud.fola, &ud.folx, &ud.foly, &pp->zoom);
#else
if (!ud.pause_on) if (!ud.pause_on)
{ {
ud.fola += ud.folavel>>3; ud.fola += ud.folavel>>3;
ud.folx += (ud.folfvel*sintable[(512+2048-ud.fola)&2047])>>14; ud.folx += (ud.folfvel*sintable[(512+2048-ud.fola)&2047])>>14;
ud.foly += (ud.folfvel*sintable[(512+1024-512-ud.fola)&2047])>>14; ud.foly += (ud.folfvel*sintable[(512+1024-512-ud.fola)&2047])>>14;
} }
#endif
cposx = ud.folx; cposx = ud.folx;
cposy = ud.foly; cposy = ud.foly;
cang = ud.fola; cang = ud.fola;

View File

@ -1128,35 +1128,6 @@ void CON_MultiNameChange(void)
void CON_LoadSetup(void) void CON_LoadSetup(void)
{ {
/*
char base[80],command[80];
// Format: showuser [SpriteNum]
if (sscanf(MessageInputString,"%s %s",base,command) < 2)
{
strcpy(MessageInputString,"help config");
CON_GetHelp();
return;
}
if (!SafeFileExists(command))
{
CON_ConMessage("CON_LoadSetup: %s does not exist.",command);
return;
} else
{
strcpy(setupfilename,command);
}
initkeys();
CONFIG_ReadSetup();
if (CONTROL_JoystickEnabled)
{
CONTROL_CenterJoystick(CenterCenter, UpperLeft, LowerRight, CenterThrottle,
CenterRudder);
}
CON_ConMessage("Loaded new config file.");
*/
CON_ConMessage("JonoF: Maybe later"); CON_ConMessage("JonoF: Maybe later");
} }
@ -1194,8 +1165,6 @@ void CON_DamageData(void)
char base[80],field[80]; char base[80],field[80];
int16_t op1=0; int16_t op1=0;
unsigned int op2, i; unsigned int op2, i;
SPRITEp sp;
USERp u;
// Format: damage [field] [item] [value] // Format: damage [field] [item] [value]
if (sscanf(MessageInputString,"%s %s %hd %u",base,field,&op1,&op2) < 3) if (sscanf(MessageInputString,"%s %s %hd %u",base,field,&op1,&op2) < 3)

View File

@ -87,27 +87,8 @@ int32_t GetTime(void)
void InitSetup(void) void InitSetup(void)
{ {
int i;
//RegisterShutdownFunction( ShutDown );
//StartWindows();
//initkeys();
//CONFIG_GetSetupFilename();
//InitializeKeyDefList();
//CONFIG_ReadSetup();
CONFIG_SetupMouse(); CONFIG_SetupMouse();
CONFIG_SetupJoystick(); CONFIG_SetupJoystick();
CONTROL_JoystickEnabled = (UseJoystick && CONTROL_JoyPresent);
CONTROL_MouseEnabled = (UseMouse && CONTROL_MousePresent);
/*{
int i;
CONTROL_PrintKeyMap();
for(i=0;i<NUMGAMEFUNCTIONS;i++) CONTROL_PrintControlFlag(i);
CONTROL_PrintAxes();
}*/
} }
#if 0 #if 0