GUI: Store the shader name in the config file instead of the ID

This commit is contained in:
Cameron Cawley 2020-01-31 23:11:09 +00:00 committed by rsn8887
parent 7488e17c0a
commit f2db412ba5
12 changed files with 97 additions and 19 deletions

View file

@ -54,6 +54,7 @@ public:
static const OSystem::GraphicsMode no_shader[2] = {{"NONE", "Normal (no shader)", 0}, {0, 0, 0}};
return no_shader;
};
virtual int getDefaultShader() const { return 0; }
virtual bool setShader(int id) { return false; }
virtual int getShader() const { return 0; }
virtual const OSystem::GraphicsMode *getSupportedStretchModes() const {

View file

@ -86,10 +86,7 @@ PSP2SdlGraphicsManager::PSP2SdlGraphicsManager(SdlEventSource *sdlEventSource, S
_numShaders++;
p++;
}
_currentShader = ConfMan.getInt("shader");
if (_currentShader < 0 || _currentShader >= _numShaders) {
_currentShader = 0;
}
_currentShader = GFX_SHADER_NONE;
_shaders[0] = NULL;
@ -140,6 +137,10 @@ const OSystem::GraphicsMode *PSP2SdlGraphicsManager::getSupportedShaders() const
return s_supportedShadersPSP2;
}
int PSP2SdlGraphicsManager::getDefaultShader() const {
return GFX_SHADER_SHARP;
}
void PSP2SdlGraphicsManager::unloadGFXMode() {
if (_screen) {
SDL_FreeSurface(_screen);

View file

@ -33,6 +33,7 @@ public:
virtual OSystem::TransactionError endGFXTransaction() override;
virtual const OSystem::GraphicsMode *getSupportedShaders() const override;
virtual int getDefaultShader() const override;
protected:
virtual void setGraphicsModeIntern() override;

View file

@ -83,6 +83,10 @@ const OSystem::GraphicsMode *ModularBackend::getSupportedShaders() const {
return _graphicsManager->getSupportedShaders();
}
int ModularBackend::getDefaultShader() const {
return _graphicsManager->getDefaultShader();
}
bool ModularBackend::setShader(int id) {
return _graphicsManager->setShader(id);
}

View file

@ -68,6 +68,7 @@ public:
virtual bool setGraphicsMode(int mode) override;
virtual int getGraphicsMode() const override;
virtual const GraphicsMode *getSupportedShaders() const override;
virtual int getDefaultShader() const override;
virtual int getShader() const override;
virtual bool setShader(int id) override;
virtual const GraphicsMode *getSupportedStretchModes() const override;

View file

@ -100,7 +100,6 @@ void OSystem_PSP2::initBackend() {
ConfMan.registerDefault("filtering", true);
ConfMan.registerDefault("kbdmouse_speed", 3);
ConfMan.registerDefault("joystick_deadzone", 2);
ConfMan.registerDefault("shader", 0);
ConfMan.registerDefault("touchpad_mouse_mode", false);
ConfMan.registerDefault("frontpanel_touchpad_mode", false);
@ -115,9 +114,6 @@ void OSystem_PSP2::initBackend() {
if (!ConfMan.hasKey("filtering")) {
ConfMan.setBool("filtering", true);
}
if (!ConfMan.hasKey("shader")) {
ConfMan.setInt("shader", 2);
}
if (!ConfMan.hasKey("touchpad_mouse_mode")) {
ConfMan.setBool("touchpad_mouse_mode", false);
}

View file

@ -222,7 +222,7 @@ void registerDefaults() {
ConfMan.registerDefault("render_mode", "default");
ConfMan.registerDefault("desired_screen_aspect_ratio", "auto");
ConfMan.registerDefault("stretch_mode", "default");
ConfMan.registerDefault("shader", 0);
ConfMan.registerDefault("shader", "default");
// Sound & Music
ConfMan.registerDefault("music_volume", 192);
@ -591,6 +591,9 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
DO_LONG_OPTION("stretch-mode")
END_OPTION
DO_LONG_OPTION("shader")
END_OPTION
DO_OPTION_INT('m', "music-volume")
END_OPTION

View file

@ -340,7 +340,7 @@ static void setupGraphics(OSystem &system) {
if (ConfMan.hasKey("stretch_mode"))
system.setStretchMode(ConfMan.get("stretch_mode").c_str());
if (ConfMan.hasKey("shader"))
system.setShader(ConfMan.getInt("shader"));
system.setShader(ConfMan.get("shader").c_str());
system.endGFXTransaction();
// When starting up launcher for the first time, the user might have specified

View file

@ -148,6 +148,27 @@ bool OSystem::setGraphicsMode(const char *name) {
return false;
}
bool OSystem::setShader(const char *name) {
if (!name)
return false;
// Special case for the 'default' filter
if (!scumm_stricmp(name, "default")) {
return setShader(getDefaultShader());
}
const GraphicsMode *sm = getSupportedShaders();
while (sm->name) {
if (!scumm_stricmp(sm->name, name)) {
return setShader(sm->id);
}
sm++;
}
return false;
}
bool OSystem::setStretchMode(const char *name) {
if (!name)
return false;

View file

@ -645,6 +645,16 @@ public:
return no_shader;
}
/**
* Return the ID of the 'default' shader mode. What exactly this means
* is up to the backend. This mode is set by the client code when no user
* overrides are present (i.e. if no custom shader mode is selected via
* the command line or a config file).
*
* @return the ID of the 'default' shader mode
*/
virtual int getDefaultShader() const { return 0; }
/**
* Switch to the specified shader mode. If switching to the new mode
* failed, this method returns false.
@ -654,6 +664,18 @@ public:
*/
virtual bool setShader(int id) { return false; }
/**
* Switch to the shader mode with the given name. If 'name' is unknown,
* or if switching to the new mode failed, this method returns false.
*
* @param name the name of the new shader mode
* @return true if the switch was successful, false otherwise
* @note This is implemented via the setShader(int) method, as well
* as getSupportedShaders() and getDefaultShader().
* In particular, backends do not have to overload this!
*/
bool setShader(const char *name);
/**
* Determine which shader is currently active.
* @return the ID of the active shader

View file

@ -217,7 +217,7 @@ void initCommonGFX() {
g_system->setStretchMode(ConfMan.get("stretch_mode").c_str());
if (gameDomain->contains("shader"))
g_system->setShader(ConfMan.getInt("shader"));
g_system->setShader(ConfMan.get("shader").c_str());
}
}

View file

@ -352,8 +352,17 @@ void OptionsDialog::build() {
_shaderPopUp->setSelected(0);
if (g_system->hasFeature(OSystem::kFeatureShader)) {
// TODO: Consider storing the name of the shader instead of the ID.
_shaderPopUp->setSelected(ConfMan.getInt("shader", _domain));
if (ConfMan.hasKey("shader", _domain)) {
const OSystem::GraphicsMode *sm = g_system->getSupportedShaders();
Common::String shader(ConfMan.get("shader", _domain));
int shaderCount = 1;
while (sm->name) {
shaderCount++;
if (scumm_stricmp(sm->name, shader.c_str()) == 0)
_shaderPopUp->setSelected(shaderCount);
sm++;
}
}
} else {
_shaderPopUpDesc->setVisible(false);
_shaderPopUp->setVisible(false);
@ -542,11 +551,23 @@ void OptionsDialog::apply() {
// Shader options
if (_shaderPopUp) {
if (_enableShaderSettings) {
if (ConfMan.getInt("shader", _domain) != (int32)_shaderPopUp->getSelectedTag())
graphicsModeChanged = true;
bool isSet = false;
// TODO: Consider storing the name of the shader instead of the ID.
ConfMan.setInt("shader", _shaderPopUp->getSelectedTag(), _domain);
if ((int32)_shaderPopUp->getSelectedTag() >= 0) {
const OSystem::GraphicsMode *sm = g_system->getSupportedShaders();
while (sm->name) {
if (sm->id == (int)_shaderPopUp->getSelectedTag()) {
if (ConfMan.get("shader", _domain) != sm->name)
graphicsModeChanged = true;
ConfMan.set("shader", sm->name, _domain);
isSet = true;
break;
}
sm++;
}
}
if (!isSet)
ConfMan.removeKey("shader", _domain);
} else {
ConfMan.removeKey("shader", _domain);
}
@ -566,7 +587,7 @@ void OptionsDialog::apply() {
if (ConfMan.hasKey("filtering"))
g_system->setFeatureState(OSystem::kFeatureFilteringMode, ConfMan.getBool("filtering", _domain));
if (ConfMan.hasKey("shader"))
g_system->setShader(ConfMan.getInt("shader", _domain));
g_system->setShader(ConfMan.get("shader", _domain).c_str());
OSystem::TransactionError gfxError = g_system->endGFXTransaction();
@ -1082,6 +1103,10 @@ void OptionsDialog::addKeyMapperControls(GuiObject *boss, const Common::String &
}
void OptionsDialog::addShaderControls(GuiObject *boss, const Common::String &prefix) {
Common::String context;
if (g_system->getOverlayWidth() <= 320)
context = "lowres";
// Shader selector
if (g_system->getOverlayWidth() > 320)
_shaderPopUpDesc = new StaticTextWidget(boss, prefix + "grShaderPopUpDesc", _("HW Shader:"), _("Different hardware shaders give different visual effects"));
@ -1089,8 +1114,11 @@ void OptionsDialog::addShaderControls(GuiObject *boss, const Common::String &pre
_shaderPopUpDesc = new StaticTextWidget(boss, prefix + "grShaderPopUpDesc", _c("HW Shader:", "lowres"), _("Different hardware shaders give different visual effects"));
_shaderPopUp = new PopUpWidget(boss, prefix + "grShaderPopUp", _("Different shaders give different visual effects"));
const OSystem::GraphicsMode *p = g_system->getSupportedShaders();
_shaderPopUp->appendEntry(_("<default>"));
_shaderPopUp->appendEntry("");
while (p->name) {
_shaderPopUp->appendEntry(p->name, p->id);
_shaderPopUp->appendEntry(_c(p->description, context), p->id);
p++;
}