Make the controls submenu select the controller type instead of core options

This commit is contained in:
DarthMew 2021-11-01 01:07:38 +01:00
commit aab19cbb9b
4 changed files with 85 additions and 154 deletions

View file

@ -831,24 +831,6 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
"Disabled"
},
{
"duckstation_Controller1.Type",
"Controller 1 Type",
NULL,
"Sets the type of controller for Slot 1.",
NULL,
"port",
{
{ "None", NULL },
{ "DigitalController", "Digital Controller" },
{ "AnalogController", "Analog Controller (DualShock)" },
{ "AnalogJoystick", "Analog Joystick" },
{ "NeGcon", NULL },
{ "PlayStationMouse", "PlayStation Mouse" },
{ NULL, NULL },
},
"DigitalController"
},
{
"duckstation_Controller1.ForceAnalogOnReset",
"Controller 1 Force Analog Mode on Reset",
@ -892,24 +874,6 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
"1.00f"
},
{
"duckstation_Controller2.Type",
"Controller 2 Type",
NULL,
"Sets the type of controller for Slot 2.",
NULL,
"port",
{
{ "None", NULL },
{ "DigitalController", "Digital Controller" },
{ "AnalogController", "Analog Controller (DualShock)" },
{ "AnalogJoystick", "Analog Joystick" },
{ "NeGcon", NULL },
{ "PlayStationMouse", "PlayStation Mouse" },
{ NULL, NULL },
},
"None"
},
{
"duckstation_Controller2.ForceAnalogOnReset",
"Controller 2 Force Analog Mode on Reset",
@ -953,23 +917,6 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
"1.00f"
},
{
"duckstation_Controller3.Type",
"Controller 3 Type",
NULL,
"Sets the type of controller for Slot 3.",
NULL,
"port",
{
{ "None", NULL },
{ "DigitalController", "Digital Controller" },
{ "AnalogController", "Analog Controller (DualShock)" },
{ "AnalogJoystick", "Analog Joystick" },
{ "NeGcon", NULL },
{ "PlayStationMouse", "PlayStation Mouse" },
},
"None"
},
{
"duckstation_Controller3.ForceAnalogOnReset",
"Controller 3 Force Analog Mode on Reset",
@ -1013,23 +960,6 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
"1.00f"
},
{
"duckstation_Controller4.Type",
"Controller 4 Type",
NULL,
"Sets the type of controller for Slot 4.",
NULL,
"port",
{
{ "None", NULL },
{ "DigitalController", "Digital Controller" },
{ "AnalogController", "Analog Controller (DualShock)" },
{ "AnalogJoystick", "Analog Joystick" },
{ "NeGcon", NULL },
{ "PlayStationMouse", "PlayStation Mouse" },
},
"None"
},
{
"duckstation_Controller4.ForceAnalogOnReset",
"Controller 4 Force Analog Mode on Reset",
@ -1073,24 +1003,6 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
"1.00f"
},
{
"duckstation_Controller5.Type",
"Controller 5 Type",
NULL,
"Sets the type of controller for Slot 1.",
NULL,
"port",
{
{ "None", NULL },
{ "DigitalController", "Digital Controller" },
{ "AnalogController", "Analog Controller (DualShock)" },
{ "AnalogJoystick", "Analog Joystick" },
{ "NeGcon", NULL },
{ "PlayStationMouse", "PlayStation Mouse" },
{ NULL, NULL },
},
"None"
},
{
"duckstation_Controller5.ForceAnalogOnReset",
"Controller 5 Force Analog Mode on Reset",
@ -1134,24 +1046,6 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
"1.00f"
},
{
"duckstation_Controller6.Type",
"Controller 6 Type",
NULL,
"Sets the type of controller for Slot 6.",
NULL,
"port",
{
{ "None", NULL },
{ "DigitalController", "Digital Controller" },
{ "AnalogController", "Analog Controller (DualShock)" },
{ "AnalogJoystick", "Analog Joystick" },
{ "NeGcon", NULL },
{ "PlayStationMouse", "PlayStation Mouse" },
{ NULL, NULL },
},
"None"
},
{
"duckstation_Controller6.ForceAnalogOnReset",
"Controller 6 Force Analog Mode on Reset",
@ -1195,24 +1089,6 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
"1.00f"
},
{
"duckstation_Controller7.Type",
"Controller 7 Type",
NULL,
"Sets the type of controller for Slot 7.",
NULL,
"port",
{
{ "None", NULL },
{ "DigitalController", "Digital Controller" },
{ "AnalogController", "Analog Controller (DualShock)" },
{ "AnalogJoystick", "Analog Joystick" },
{ "NeGcon", NULL },
{ "PlayStationMouse", "PlayStation Mouse" },
{ NULL, NULL },
},
"None"
},
{
"duckstation_Controller7.ForceAnalogOnReset",
"Controller 7 Force Analog Mode on Reset",
@ -1256,24 +1132,6 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
"1.00f"
},
{
"duckstation_Controller8.Type",
"Controller 8 Type",
NULL,
"Sets the type of controller for Slot 8.",
NULL,
"port",
{
{ "None", NULL },
{ "DigitalController", "Digital Controller" },
{ "AnalogController", "Analog Controller (DualShock)" },
{ "AnalogJoystick", "Analog Joystick" },
{ "NeGcon", NULL },
{ "PlayStationMouse", "PlayStation Mouse" },
{ NULL, NULL },
},
"None"
},
{
"duckstation_Controller8.ForceAnalogOnReset",
"Controller 8 Force Analog Mode on Reset",

View file

@ -35,6 +35,12 @@ Log_SetChannel(LibretroHostInterface);
LibretroHostInterface g_libretro_host_interface;
#define P_THIS (&g_libretro_host_interface)
#define RETRO_DEVICE_PS_CONTROLLER RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0)
#define RETRO_DEVICE_PS_DUALSHOCK RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 0)
#define RETRO_DEVICE_PS_ANALOG_JOYSTICK RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 1)
#define RETRO_DEVICE_PS_NEGCON RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_ANALOG, 2)
#define RETRO_DEVICE_PS_MOUSE RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_MOUSE, 0)
retro_environment_t g_retro_environment_callback;
retro_video_refresh_t g_retro_video_refresh_callback;
retro_audio_sample_t g_retro_audio_sample_callback;
@ -78,6 +84,30 @@ void LibretroHostInterface::retro_set_environment()
{
libretro_supports_option_categories = false;
libretro_set_core_options(g_retro_environment_callback, &libretro_supports_option_categories);
static const struct retro_controller_description pads[] = {
{ "Digital Controller (Gamepad)", RETRO_DEVICE_JOYPAD },
{ "Analog Controller (DualShock)", RETRO_DEVICE_PS_DUALSHOCK },
{ "Analog Joystick", RETRO_DEVICE_PS_ANALOG_JOYSTICK },
{ "NeGcon", RETRO_DEVICE_PS_NEGCON },
{ "PlayStation Mouse", RETRO_DEVICE_PS_MOUSE },
{ NULL, 0 },
};
static const struct retro_controller_info ports[] = {
{ pads, 5 },
{ pads, 5 },
{ pads, 5 },
{ pads, 5 },
{ pads, 5 },
{ pads, 5 },
{ pads, 5 },
{ pads, 5 },
{ NULL, 0 },
};
g_retro_environment_callback(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void *)ports);
InitLogging();
}
@ -86,8 +116,8 @@ void LibretroHostInterface::InitInterfaces()
InitRumbleInterface();
InitDiskControlInterface();
unsigned dummy = 0;
m_supports_input_bitmasks = g_retro_environment_callback(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, &dummy);
//unsigned dummy = 0;
//m_supports_input_bitmasks = g_retro_environment_callback(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, &dummy);
}
void LibretroHostInterface::InitLogging()
@ -494,6 +524,51 @@ bool LibretroHostInterface::retro_load_game(const struct retro_game_info* game)
return true;
}
void LibretroHostInterface::retro_set_controller_port_device(unsigned port, unsigned device)
{
Settings old_settings(std::move(g_settings));
if (port >= NUM_CONTROLLER_AND_CARD_PORTS)
return;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
case RETRO_DEVICE_PS_CONTROLLER:
g_settings.controller_types[port] = ControllerType::DigitalController;
Log_InfoPrintf("Port %u = Digital Controller (Gamepad)", (port + 1));
break;
case RETRO_DEVICE_PS_DUALSHOCK:
g_settings.controller_types[port] = ControllerType::AnalogController;
Log_InfoPrintf("Port %u = Analog Controller (DualShock)", (port + 1));
break;
case RETRO_DEVICE_PS_ANALOG_JOYSTICK:
g_settings.controller_types[port] = ControllerType::AnalogJoystick;
Log_InfoPrintf("Port %u = Analog Joystick", (port + 1));
break;
case RETRO_DEVICE_PS_NEGCON:
g_settings.controller_types[port] = ControllerType::NeGcon;
Log_InfoPrintf("Port %u = NeGcon", (port + 1));
break;
case RETRO_DEVICE_PS_MOUSE:
g_settings.controller_types[port] = ControllerType::PlayStationMouse;
Log_InfoPrintf("Port %u = PlayStation Mouse", (port + 1));
break;
case RETRO_DEVICE_NONE:
default:
g_settings.controller_types[port] = ControllerType::None;
Log_InfoPrintf("Port %u = None", (port + 1));
break;
}
CheckForSettingsChanges(old_settings);
}
void LibretroHostInterface::retro_run_frame()
{
Assert(!System::IsShutdown());
@ -652,7 +727,10 @@ void LibretroHostInterface::OnSystemPaused(bool paused) {}
void LibretroHostInterface::OnSystemDestroyed() {}
void LibretroHostInterface::OnControllerTypeChanged(u32 slot) {}
void LibretroHostInterface::OnControllerTypeChanged(u32 slot)
{
//Log_InfoPrintf("Switched controller.");
}
void LibretroHostInterface::SetMouseMode(bool relative, bool hide_cursor) {}
@ -710,12 +788,10 @@ void LibretroHostInterface::LoadSettings(SettingsInterface& si)
{
unsigned i;
struct retro_core_option_display option_display;
char controller_multitap_options[8][49] = {
"duckstation_Controller3.Type",
char controller_multitap_options[6][49] = {
"duckstation_Controller3.ForceAnalogOnReset",
"duckstation_Controller3.AnalogDPadInDigitalMode",
"duckstation_Controller3.AxisScale",
"duckstation_Controller4.Type",
"duckstation_Controller4.ForceAnalogOnReset",
"duckstation_Controller4.AnalogDPadInDigitalMode",
"duckstation_Controller4.AxisScale"
@ -729,20 +805,16 @@ void LibretroHostInterface::LoadSettings(SettingsInterface& si)
g_retro_environment_callback(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);
}
char controller_double_multitap_options[16][49] = {
"duckstation_Controller5.Type",
char controller_double_multitap_options[12][49] = {
"duckstation_Controller5.ForceAnalogOnReset",
"duckstation_Controller5.AnalogDPadInDigitalMode",
"duckstation_Controller5.AxisScale",
"duckstation_Controller6.Type",
"duckstation_Controller6.ForceAnalogOnReset",
"duckstation_Controller6.AnalogDPadInDigitalMode",
"duckstation_Controller6.AxisScale",
"duckstation_Controller7.Type",
"duckstation_Controller7.ForceAnalogOnReset",
"duckstation_Controller7.AnalogDPadInDigitalMode",
"duckstation_Controller7.AxisScale",
"duckstation_Controller8.Type",
"duckstation_Controller8.ForceAnalogOnReset",
"duckstation_Controller8.AnalogDPadInDigitalMode",
"duckstation_Controller8.AxisScale"

View file

@ -61,6 +61,7 @@ public:
void retro_set_environment();
void retro_get_system_av_info(struct retro_system_av_info* info);
bool retro_load_game(const struct retro_game_info* game);
void retro_set_controller_port_device(unsigned port, unsigned device);
void retro_run_frame();
unsigned retro_get_region();
size_t retro_serialize_size();

View file

@ -48,7 +48,7 @@ RETRO_API void retro_get_system_av_info(struct retro_system_av_info* info)
RETRO_API void retro_set_controller_port_device(unsigned port, unsigned device)
{
Log_ErrorPrintf("retro_set_controller_port_device(%u, %u)", port, device);
g_libretro_host_interface.retro_set_controller_port_device(port, device);
}
RETRO_API void retro_reset(void)