mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2025-02-16 17:35:39 +00:00
Inputs can now be configured on a per-game basis
This commit is contained in:
parent
b0813ef7a0
commit
98106df68b
|
@ -418,16 +418,16 @@ void CInputs::StoreToConfig(Util::Config::Node *config)
|
||||||
(*it)->StoreToConfig(config);
|
(*it)->StoreToConfig(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CInputs::ConfigureInputs(const Game *game)
|
bool CInputs::ConfigureInputs(const Game &game)
|
||||||
{
|
{
|
||||||
m_system->UngrabMouse();
|
m_system->UngrabMouse();
|
||||||
|
|
||||||
// Print header and help message
|
// Print header and help message
|
||||||
uint32_t gameFlags;
|
uint32_t gameFlags;
|
||||||
if (game)
|
if (!game.name.empty())
|
||||||
{
|
{
|
||||||
PrintHeader("Configure Inputs for %s", game->title.c_str());
|
PrintHeader("Configure Inputs for '%s'", game.title.c_str());
|
||||||
gameFlags = game->inputs;
|
gameFlags = game.inputs;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -599,7 +599,7 @@ Finish:
|
||||||
return !cancelled;
|
return !cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CInputs::ConfigureInputs(const Game *game, unsigned dispX, unsigned dispY, unsigned dispW, unsigned dispH)
|
bool CInputs::ConfigureInputs(const Game &game, unsigned dispX, unsigned dispY, unsigned dispW, unsigned dispH)
|
||||||
{
|
{
|
||||||
// Let the input system know the display geometry
|
// Let the input system know the display geometry
|
||||||
m_system->SetDisplayGeom(dispX, dispY, dispW, dispH);
|
m_system->SetDisplayGeom(dispX, dispY, dispW, dispH);
|
||||||
|
|
|
@ -277,14 +277,14 @@ public:
|
||||||
* Configures the current input mapping assignments for the given game, or all inputs if game is NULL, by asking the user for input.
|
* Configures the current input mapping assignments for the given game, or all inputs if game is NULL, by asking the user for input.
|
||||||
* Returns true if the inputs were configured okay or false if the user exited without requesting to save changes.
|
* Returns true if the inputs were configured okay or false if the user exited without requesting to save changes.
|
||||||
*/
|
*/
|
||||||
bool ConfigureInputs(const Game *game);
|
bool ConfigureInputs(const Game &game);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Configures the current input mapping assignments for the given game, or all inputs if game is NULL, by asking the user for input.
|
* Configures the current input mapping assignments for the given game, or all inputs if game is NULL, by asking the user for input.
|
||||||
* Takes display geometry if this has not been set previously by a call to Poll().
|
* Takes display geometry if this has not been set previously by a call to Poll().
|
||||||
* Returns true if the inputs were configured okay or false if the user exited without requesting to save changes.
|
* Returns true if the inputs were configured okay or false if the user exited without requesting to save changes.
|
||||||
*/
|
*/
|
||||||
bool ConfigureInputs(const Game *game, unsigned dispX, unsigned dispY, unsigned dispW, unsigned dispH);
|
bool ConfigureInputs(const Game &game, unsigned dispX, unsigned dispY, unsigned dispW, unsigned dispH);
|
||||||
|
|
||||||
void CalibrateJoysticks();
|
void CalibrateJoysticks();
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ static bool SetGLGeometry(unsigned *xOffsetPtr, unsigned *yOffsetPtr, unsigned *
|
||||||
* NOTE: keepAspectRatio should always be true. It has not yet been tested with
|
* NOTE: keepAspectRatio should always be true. It has not yet been tested with
|
||||||
* the wide screen hack.
|
* the wide screen hack.
|
||||||
*/
|
*/
|
||||||
static bool CreateGLScreen(const char *caption, unsigned *xOffsetPtr, unsigned *yOffsetPtr, unsigned *xResPtr, unsigned *yResPtr, unsigned *totalXResPtr, unsigned *totalYResPtr, bool keepAspectRatio, bool fullScreen)
|
static bool CreateGLScreen(const std::string &caption, unsigned *xOffsetPtr, unsigned *yOffsetPtr, unsigned *xResPtr, unsigned *yResPtr, unsigned *totalXResPtr, unsigned *totalYResPtr, bool keepAspectRatio, bool fullScreen)
|
||||||
{
|
{
|
||||||
GLenum err;
|
GLenum err;
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ static bool CreateGLScreen(const char *caption, unsigned *xOffsetPtr, unsigned *
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create window caption
|
// Create window caption
|
||||||
SDL_WM_SetCaption(caption,NULL);
|
SDL_WM_SetCaption(caption.c_str(),NULL);
|
||||||
|
|
||||||
// Initialize GLEW, allowing us to use features beyond OpenGL 1.2
|
// Initialize GLEW, allowing us to use features beyond OpenGL 1.2
|
||||||
err = glewInit();
|
err = glewInit();
|
||||||
|
@ -1227,7 +1227,7 @@ static const char s_configFilePath[] = { "Config/Supermodel.ini" };
|
||||||
static const char s_gameXMLFilePath[] = { "Config/Games.xml" };
|
static const char s_gameXMLFilePath[] = { "Config/Games.xml" };
|
||||||
|
|
||||||
// Create and configure inputs
|
// Create and configure inputs
|
||||||
static bool ConfigureInputs(CInputs *Inputs, Util::Config::Node *config, bool configure)
|
static bool ConfigureInputs(CInputs *Inputs, Util::Config::Node *fileConfig, Util::Config::Node *runtimeConfig, const Game &game, bool configure)
|
||||||
{
|
{
|
||||||
static const char configFileComment[] = {
|
static const char configFileComment[] = {
|
||||||
";\n"
|
";\n"
|
||||||
|
@ -1235,22 +1235,39 @@ static bool ConfigureInputs(CInputs *Inputs, Util::Config::Node *config, bool co
|
||||||
";\n"
|
";\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
Inputs->LoadFromConfig(*config);
|
Inputs->LoadFromConfig(*runtimeConfig);
|
||||||
|
|
||||||
// If the user wants to configure the inputs, do that now
|
// If the user wants to configure the inputs, do that now
|
||||||
if (configure)
|
if (configure)
|
||||||
{
|
{
|
||||||
|
// Extract the relevant INI section (which will be the global section if no
|
||||||
|
// game was specified, otherwise the game's node) in the file config, which
|
||||||
|
// will be written back to disk
|
||||||
|
Util::Config::Node *fileConfigRoot = game.name.empty() ? fileConfig : fileConfig->TryGet(game.name);
|
||||||
|
if (fileConfigRoot == nullptr)
|
||||||
|
{
|
||||||
|
fileConfigRoot = &fileConfig->Add(game.name);
|
||||||
|
}
|
||||||
|
|
||||||
// Open an SDL window
|
// Open an SDL window
|
||||||
unsigned xOffset, yOffset, xRes=496, yRes=384;
|
unsigned xOffset, yOffset, xRes=496, yRes=384;
|
||||||
if (OKAY != CreateGLScreen("Supermodel - Configuring Inputs...", &xOffset, &yOffset, &xRes, &yRes, &totalXRes, &totalYRes, false, false))
|
std::string title("Supermodel - ");
|
||||||
|
if (game.name.empty())
|
||||||
|
title.append("Configuring Default Inputs...");
|
||||||
|
else
|
||||||
|
title.append(Util::Format() << "Configuring Inputs for: " << game.title);
|
||||||
|
if (OKAY != CreateGLScreen(title, &xOffset, &yOffset, &xRes, &yRes, &totalXRes, &totalYRes, false, false))
|
||||||
return (bool) ErrorLog("Unable to start SDL to configure inputs.\n");
|
return (bool) ErrorLog("Unable to start SDL to configure inputs.\n");
|
||||||
|
|
||||||
// Configure the inputs
|
// Configure the inputs
|
||||||
if (Inputs->ConfigureInputs(NULL, xOffset, yOffset, xRes, yRes))
|
if (Inputs->ConfigureInputs(game, xOffset, yOffset, xRes, yRes))
|
||||||
{
|
{
|
||||||
// Write input configuration and input system settings to config file
|
// Write input configuration and input system settings to config file
|
||||||
Inputs->StoreToConfig(config);
|
Inputs->StoreToConfig(fileConfigRoot);
|
||||||
Util::Config::WriteINIFile(s_configFilePath, *config, configFileComment);
|
Util::Config::WriteINIFile(s_configFilePath, *fileConfig, configFileComment);
|
||||||
|
|
||||||
|
// Also save to runtime configuration in case we proceed and play
|
||||||
|
Inputs->StoreToConfig(runtimeConfig);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
puts("Configuration aborted...");
|
puts("Configuration aborted...");
|
||||||
|
@ -1672,8 +1689,8 @@ int main(int argc, char **argv)
|
||||||
Game game;
|
Game game;
|
||||||
ROMSet rom_set;
|
ROMSet rom_set;
|
||||||
Util::Config::Node fileConfig("Global");
|
Util::Config::Node fileConfig("Global");
|
||||||
Util::Config::Node fileConfigWithDefaults("Global");
|
|
||||||
{
|
{
|
||||||
|
Util::Config::Node fileConfigWithDefaults("Global");
|
||||||
Util::Config::Node config3("Global");
|
Util::Config::Node config3("Global");
|
||||||
Util::Config::Node config4("Global");
|
Util::Config::Node config4("Global");
|
||||||
Util::Config::FromINIFile(&fileConfig, s_configFilePath);
|
Util::Config::FromINIFile(&fileConfig, s_configFilePath);
|
||||||
|
@ -1722,18 +1739,16 @@ int main(int argc, char **argv)
|
||||||
#endif // SUPERMODEL_DEBUGGER
|
#endif // SUPERMODEL_DEBUGGER
|
||||||
|
|
||||||
// Create input system
|
// Create input system
|
||||||
// NOTE: fileConfigWithDefaults is passed so that the global section is used
|
|
||||||
// for input settings with default values populated
|
|
||||||
std::string selectedInputSystem = s_runtime_config["InputSystem"].ValueAs<std::string>();
|
std::string selectedInputSystem = s_runtime_config["InputSystem"].ValueAs<std::string>();
|
||||||
if (selectedInputSystem == "sdl")
|
if (selectedInputSystem == "sdl")
|
||||||
InputSystem = new CSDLInputSystem();
|
InputSystem = new CSDLInputSystem();
|
||||||
#ifdef SUPERMODEL_WIN32
|
#ifdef SUPERMODEL_WIN32
|
||||||
else if (selectedInputSystem == "dinput")
|
else if (selectedInputSystem == "dinput")
|
||||||
InputSystem = new CDirectInputSystem(fileConfigWithDefaults, false, false);
|
InputSystem = new CDirectInputSystem(s_runtime_config, false, false);
|
||||||
else if (selectedInputSystem == "xinput")
|
else if (selectedInputSystem == "xinput")
|
||||||
InputSystem = new CDirectInputSystem(fileConfigWithDefaults, false, true);
|
InputSystem = new CDirectInputSystem(s_runtime_config, false, true);
|
||||||
else if (selectedInputSystem == "rawinput")
|
else if (selectedInputSystem == "rawinput")
|
||||||
InputSystem = new CDirectInputSystem(fileConfigWithDefaults, true, false);
|
InputSystem = new CDirectInputSystem(s_runtime_config, true, false);
|
||||||
#endif // SUPERMODEL_WIN32
|
#endif // SUPERMODEL_WIN32
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1754,7 +1769,7 @@ int main(int argc, char **argv)
|
||||||
// NOTE: fileConfig is passed so that the global section is used for input settings
|
// NOTE: fileConfig is passed so that the global section is used for input settings
|
||||||
// and because this function may write out a new config file, which must preserve
|
// and because this function may write out a new config file, which must preserve
|
||||||
// all sections. We don't want to pollute the output with built-in defaults.
|
// all sections. We don't want to pollute the output with built-in defaults.
|
||||||
if (ConfigureInputs(Inputs, &fileConfig, cmd_line.config_inputs))
|
if (ConfigureInputs(Inputs, &fileConfig, &s_runtime_config, game, cmd_line.config_inputs))
|
||||||
{
|
{
|
||||||
exitCode = 1;
|
exitCode = 1;
|
||||||
goto Exit;
|
goto Exit;
|
||||||
|
|
Loading…
Reference in a new issue