Added 'Variant' class, which is basically a variable type. Reimplemented

the Settings class to use Variant.  Still TODO is modify various UI elements
that currently accept StringMap to use Variant instead.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2726 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2013-05-08 23:34:42 +00:00
parent 0929adc20d
commit 7de6bbd99b
25 changed files with 306 additions and 349 deletions

View File

@ -300,7 +300,7 @@ void CheatManager::loadCheats(const string& md5sum)
// (and remove the key from the settings, so they won't get set again)
const string& cheats = myOSystem->settings().getString("cheat");
if(cheats != "")
myOSystem->settings().setString("cheat", "");
myOSystem->settings().setValue("cheat", "");
CheatCodeMap::iterator iter = myCheatMap.find(md5sum);
if(iter == myCheatMap.end() && cheats == "")

View File

@ -106,7 +106,7 @@ SoundSDL::~SoundSDL()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void SoundSDL::setEnabled(bool state)
{
myOSystem->settings().setBool("sound", state);
myOSystem->settings().setValue("sound", state);
myOSystem->logMessage(state ? "SoundSDL::setEnabled(true)" :
"SoundSDL::setEnabled(false)", 2);
@ -193,7 +193,7 @@ void SoundSDL::setVolume(Int32 percent)
{
if(myIsInitializedFlag && (percent >= 0) && (percent <= 100))
{
myOSystem->settings().setInt("volume", percent);
myOSystem->settings().setValue("volume", percent);
SDL_LockAudio();
myVolume = percent;
myTIASound.volume(percent);

79
src/common/Variant.hxx Normal file
View File

@ -0,0 +1,79 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2013 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id$
//============================================================================
#ifndef VARIANT_HXX
#define VARIANT_HXX
#include "bspf.hxx"
#include "Rect.hxx"
/**
This class implements a very simple variant type, which is convertible
to several other types. It stores the actual data as a string, and
converts to other types as required. Eventually, this class may be
extended to use templates and become a more full-featured variant type.
@author Stephen Anthony
*/
class Variant
{
private:
// Underlying data store is (currently) always a string
string data;
// Use singleton so we use only one ostringstream object
inline ostringstream& buf() {
static ostringstream buf;
return buf;
}
public:
Variant() : data("") { }
Variant(const string& s) : data(s) { }
Variant(const char* s) : data(s) { }
Variant(int i) { buf().str(""); buf() << i; data = buf().str(); }
Variant(unsigned int i) { buf().str(""); buf() << i; data = buf().str(); }
Variant(float f) { buf().str(""); buf() << f; data = buf().str(); }
Variant(double d) { buf().str(""); buf() << d; data = buf().str(); }
Variant(bool b) { buf().str(""); buf() << b; data = buf().str(); }
Variant(const GUI::Size& s) { buf().str(""); buf() << s; data = buf().str(); }
// Conversion methods
const string& toString() const { return data; }
const char* toCString() const { return data.c_str(); }
const int toInt() const { return atoi(data.c_str()); }
const float toFloat() const { return atof(data.c_str()); }
const bool toBool() const { return data == "1" || data == "true"; }
const GUI::Size toSize() const { return GUI::Size(data); }
// Comparison
bool operator==(const Variant& v) const { return data == v.data; };
bool operator!=(const Variant& v) const { return data != v.data; };
friend ostream& operator<<(ostream& os, const Variant& v) {
os << v.data;
return os;
}
};
static const Variant EmptyVariant("");
#endif

View File

@ -195,7 +195,7 @@ int main(int argc, char* argv[])
Debugger& dbg = theOSystem->debugger();
int bp = dbg.stringToValue(initBreak);
dbg.setBreakPoint(bp, true);
theOSystem->settings().setString("break", "");
theOSystem->settings().setValue("break", "");
}
if(theOSystem->settings().getBool("debug"))

View File

@ -210,16 +210,16 @@ void NTSCFilter::loadConfig(const Settings& settings)
void NTSCFilter::saveConfig(Settings& settings) const
{
// Save adjustables for custom mode
settings.setFloat("tv_hue", myCustomSetup.hue);
settings.setFloat("tv_saturation", myCustomSetup.saturation);
settings.setFloat("tv_contrast", myCustomSetup.contrast);
settings.setFloat("tv_brightness", myCustomSetup.brightness);
settings.setFloat("tv_sharpness", myCustomSetup.sharpness);
settings.setFloat("tv_gamma", myCustomSetup.gamma);
settings.setFloat("tv_resolution", myCustomSetup.resolution);
settings.setFloat("tv_artifacts", myCustomSetup.artifacts);
settings.setFloat("tv_fringing", myCustomSetup.fringing);
settings.setFloat("tv_bleed", myCustomSetup.bleed);
settings.setValue("tv_hue", myCustomSetup.hue);
settings.setValue("tv_saturation", myCustomSetup.saturation);
settings.setValue("tv_contrast", myCustomSetup.contrast);
settings.setValue("tv_brightness", myCustomSetup.brightness);
settings.setValue("tv_sharpness", myCustomSetup.sharpness);
settings.setValue("tv_gamma", myCustomSetup.gamma);
settings.setValue("tv_resolution", myCustomSetup.resolution);
settings.setValue("tv_artifacts", myCustomSetup.artifacts);
settings.setValue("tv_fringing", myCustomSetup.fringing);
settings.setValue("tv_bleed", myCustomSetup.bleed);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -166,13 +166,12 @@ Debugger::~Debugger()
void Debugger::initialize()
{
// Get the dialog size
int w, h;
myOSystem->settings().getSize("debuggerres", w, h);
myWidth = BSPF_max(w, 0);
myHeight = BSPF_max(h, 0);
const GUI::Size& size = myOSystem->settings().getSize("debuggerres");
myWidth = BSPF_max(size.w, 0);
myHeight = BSPF_max(size.h, 0);
myWidth = BSPF_max(myWidth, 1080u);
myHeight = BSPF_max(myHeight, 720u);
myOSystem->settings().setSize("debuggerres", myWidth, myHeight);
myOSystem->settings().setValue("debuggerres", GUI::Size(myWidth, myHeight));
const GUI::Rect& r = getDialogBounds();

View File

@ -174,7 +174,7 @@ void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
else if(rmb == "pcaddr")
{
DiStella::settings.show_addresses = !DiStella::settings.show_addresses;
instance().settings().setBool("dis.showaddr",
instance().settings().setValue("dis.showaddr",
DiStella::settings.show_addresses);
invalidate();
}
@ -183,19 +183,19 @@ void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
if(DiStella::settings.gfx_format == kBASE_16)
{
DiStella::settings.gfx_format = kBASE_2;
instance().settings().setString("dis.gfxformat", "2");
instance().settings().setValue("dis.gfxformat", "2");
}
else
{
DiStella::settings.gfx_format = kBASE_16;
instance().settings().setString("dis.gfxformat", "16");
instance().settings().setValue("dis.gfxformat", "16");
}
invalidate();
}
else if(rmb == "relocate")
{
DiStella::settings.rflag = !DiStella::settings.rflag;
instance().settings().setBool("dis.relocate",
instance().settings().setValue("dis.relocate",
DiStella::settings.rflag);
invalidate();
}
@ -207,7 +207,7 @@ void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
break;
case kResolveDataChanged:
instance().settings().setString("dis.resolvedata", myResolveData->getSelectedTag());
instance().settings().setValue("dis.resolvedata", myResolveData->getSelectedTag());
invalidate();
loadConfig();
break;

View File

@ -262,7 +262,7 @@ string Cartridge::createFromMultiCart(const uInt8*& image, uInt32& size,
id = buf.str();
// Move to the next game the next time this ROM is loaded
settings.setInt("romloadcount", (i+1)%numroms);
settings.setValue("romloadcount", (i+1)%numroms);
if(size <= 2048) return "2K";
else if(size == 4096) return "4K";

View File

@ -119,7 +119,7 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props)
// will take over 250 frames!
// The 'fastscbios' option must be changed before the system is reset
bool fastscbios = myOSystem->settings().getBool("fastscbios");
myOSystem->settings().setBool("fastscbios", true);
myOSystem->settings().setValue("fastscbios", true);
mySystem->reset(true); // autodetect in reset enabled
for(int i = 0; i < 60; ++i)
myTIA->update();
@ -131,7 +131,7 @@ Console::Console(OSystem* osystem, Cartridge* cart, const Properties& props)
}
// Don't forget to reset the SC progress bars again
myOSystem->settings().setBool("fastscbios", fastscbios);
myOSystem->settings().setValue("fastscbios", fastscbios);
}
myConsoleInfo.DisplayFormat = myDisplayFormat + autodetected;
@ -286,7 +286,7 @@ void Console::toggleFormat(int direction)
void Console::toggleColorLoss()
{
bool colorloss = !myOSystem->settings().getBool("colorloss");
myOSystem->settings().setBool("colorloss", colorloss);
myOSystem->settings().setValue("colorloss", colorloss);
myTIA->enableColorLoss(colorloss);
string message = string("PAL color-loss ") +
@ -337,7 +337,7 @@ void Console::togglePalette()
message = "Standard Stella palette";
}
myOSystem->settings().setString("palette", palette);
myOSystem->settings().setValue("palette", palette);
myOSystem->frameBuffer().showMessage(message);
setPalette(palette);

View File

@ -274,7 +274,7 @@ void EventHandler::mapStelladaptors(const string& saport)
}
}
}
myOSystem->settings().setString("saport", saport);
myOSystem->settings().setValue("saport", saport);
// We're potentially swapping out an input device behind the back of
// the Event system, so we make sure all Stelladaptor-generated events
@ -1721,7 +1721,7 @@ void EventHandler::saveKeyMapping()
for(int i = 0; i < KBDK_LAST; ++i)
keybuf << ":" << myKeyTable[i][mode];
myOSystem->settings().setString("keymap", keybuf.str());
myOSystem->settings().setValue("keymap", keybuf.str());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1756,7 +1756,7 @@ void EventHandler::saveJoyMapping()
for(iter = myJoystickMap.begin(); iter != myJoystickMap.end(); ++iter)
joybuf << "^" << iter->second;
myOSystem->settings().setString("joymap", joybuf.str());
myOSystem->settings().setValue("joymap", joybuf.str());
#endif
}
@ -1774,7 +1774,7 @@ void EventHandler::saveComboMapping()
for(int j = 1; j < kEventsPerCombo; ++j)
buf << "," << myComboTable[i][j];
}
myOSystem->settings().setString("combomap", buf.str());
myOSystem->settings().setValue("combomap", buf.str());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -152,7 +152,7 @@ FBInitStatus FrameBuffer::initialize(const string& title,
// Did we get the requested fullscreen state?
const string& fullscreen = myOSystem->settings().getString("fullscreen");
if(fullscreen != "-1")
myOSystem->settings().setString("fullscreen", fullScreen() ? "1" : "0");
myOSystem->settings().setValue("fullscreen", fullScreen() ? "1" : "0");
setCursorState();
}
else
@ -335,7 +335,7 @@ void FrameBuffer::toggleFrameStats()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::showFrameStats(bool enable)
{
myOSystem->settings().setBool("stats", enable);
myOSystem->settings().setValue("stats", enable);
myStatsMsg.enabled = enable;
refresh();
}
@ -533,7 +533,7 @@ void FrameBuffer::setNTSC(NTSCFilter::Preset preset, bool show)
const string& mode = myNTSCFilter.setPreset(preset);
buf << "TV filtering (" << mode << " mode)";
}
myOSystem->settings().setInt("tv_filter", (int)preset);
myOSystem->settings().setValue("tv_filter", (int)preset);
}
else
buf << "TV filtering not available in software mode";
@ -551,7 +551,7 @@ void FrameBuffer::setScanlineIntensity(int amount)
{
uInt32 intensity = enableScanlines(amount);
buf << "Scanline intensity at " << intensity << "%";
myOSystem->settings().setInt("tv_scanlines", intensity);
myOSystem->settings().setValue("tv_scanlines", intensity);
}
else
buf << "Scanlines only available in TV filtering mode";
@ -573,7 +573,7 @@ void FrameBuffer::toggleScanlineInterpolation()
bool enable = !myOSystem->settings().getBool("tv_scaninter");
enableScanlineInterpolation(enable);
buf << "Scanline interpolation " << (enable ? "enabled" : "disabled");
myOSystem->settings().setBool("tv_scaninter", enable);
myOSystem->settings().setValue("tv_scaninter", enable);
}
else
buf << "Scanlines only available in TV filtering mode";
@ -779,7 +779,7 @@ bool FrameBuffer::changeVidMode(int direction)
// Did we get the requested fullscreen state?
const string& fullscreen = myOSystem->settings().getString("fullscreen");
if(fullscreen != "-1")
myOSystem->settings().setString("fullscreen", fullScreen() ? "1" : "0");
myOSystem->settings().setValue("fullscreen", fullScreen() ? "1" : "0");
setCursorState();
if(!inUIMode)
@ -788,7 +788,7 @@ bool FrameBuffer::changeVidMode(int direction)
showMessage(vidmode.gfxmode.description);
}
if(saveModeChange)
myOSystem->settings().setString("tia_filter", vidmode.gfxmode.name);
myOSystem->settings().setValue("tia_filter", vidmode.gfxmode.name);
refresh();
}
@ -826,7 +826,7 @@ void FrameBuffer::setCursorState()
void FrameBuffer::toggleGrabMouse()
{
bool state = myOSystem->settings().getBool("grabmouse");
myOSystem->settings().setBool("grabmouse", !state);
myOSystem->settings().setValue("grabmouse", !state);
setCursorState();
}
@ -1156,15 +1156,14 @@ const FrameBuffer::VideoMode FrameBuffer::
if(isFullscreen && !BSPF_equalsIgnoreCase(settings.getString("fullres"), "auto"))
{
// Only use 'fullres' if it's *bigger* than the requested mode
int w, h;
settings.getSize("fullres", w, h);
const GUI::Size& s = settings.getSize("fullres");
if(w != -1 && h != -1 && (uInt32)w >= myModeList[myIdx].screen_w &&
(uInt32)h >= myModeList[myIdx].screen_h)
if(s.w != -1 && s.h != -1 && (uInt32)s.w >= myModeList[myIdx].screen_w &&
(uInt32)s.h >= myModeList[myIdx].screen_h)
{
VideoMode mode = myModeList[myIdx];
mode.screen_w = w;
mode.screen_h = h;
mode.screen_w = s.w;
mode.screen_h = s.h;
mode.image_x = (mode.screen_w - mode.image_w) >> 1;
mode.image_y = (mode.screen_h - mode.image_h) >> 1;

View File

@ -357,19 +357,19 @@ void OSystem::setConfigPaths()
if(s == "") s = myBaseDir + "stella.cht";
node = FilesystemNode(s);
myCheatFile = node.getPath();
mySettings->setString("cheatfile", node.getShortPath());
mySettings->setValue("cheatfile", node.getShortPath());
s = mySettings->getString("palettefile");
if(s == "") s = myBaseDir + "stella.pal";
node = FilesystemNode(s);
myPaletteFile = node.getPath();
mySettings->setString("palettefile", node.getShortPath());
mySettings->setValue("palettefile", node.getShortPath());
s = mySettings->getString("propsfile");
if(s == "") s = myBaseDir + "stella.pro";
node = FilesystemNode(s);
myPropertiesFile = node.getPath();
mySettings->setString("propsfile", node.getShortPath());
mySettings->setValue("propsfile", node.getShortPath());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -477,7 +477,7 @@ fallback:
{
logMessage("ERROR: OpenGL mode failed, fallback to software", 0);
delete myFrameBuffer; myFrameBuffer = NULL;
mySettings->setString("video", "soft");
mySettings->setValue("video", "soft");
FBInitStatus newstatus = createFrameBuffer();
if(newstatus == kSuccess)
{
@ -497,7 +497,7 @@ void OSystem::createSound()
if(!mySound)
mySound = MediaFactory::createAudio(this);
#ifndef SOUND_SUPPORT
mySettings->setBool("sound", false);
mySettings->setValue("sound", false);
#endif
}
@ -523,7 +523,7 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum,
// Each time a new console is loaded, we simulate a cart removal
// Some carts need knowledge of this, as they behave differently
// based on how many power-cycles they've been through since plugged in
mySettings->setInt("romloadcount", 0);
mySettings->setValue("romloadcount", 0);
}
// Create an instance of the 2600 game console
@ -633,7 +633,7 @@ bool OSystem::reloadConsole()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool OSystem::createLauncher(const string& startdir)
{
mySettings->setString("tmpromdir", startdir);
mySettings->setValue("tmpromdir", startdir);
bool status = false;
myEventHandler->reset(EventHandler::S_LAUNCHER);
@ -829,7 +829,7 @@ void OSystem::validatePath(string& path, const string& setting,
node.makeDir();
path = node.getPath();
mySettings->setString(setting, node.getShortPath());
mySettings->setValue(setting, node.getShortPath());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -982,9 +982,8 @@ bool OSystem::queryVideoHardware()
// Check the 'maxres' setting, which is an undocumented developer feature
// that specifies the desktop size
// Normally, this wouldn't be set, and we ask SDL directly
int w, h;
mySettings->getSize("maxres", w, h);
if(w <= 0 || h <= 0)
const GUI::Size& s = mySettings->getSize("maxres");
if(s.w <= 0 || s.h <= 0)
{
const SDL_VideoInfo* info = SDL_GetVideoInfo();
myDesktopWidth = info->current_w;
@ -992,8 +991,8 @@ bool OSystem::queryVideoHardware()
}
else
{
myDesktopWidth = BSPF_max(w, 320);
myDesktopHeight = BSPF_max(h, 240);
myDesktopWidth = BSPF_max(s.w, 320);
myDesktopHeight = BSPF_max(s.h, 240);
}
// Various parts of the codebase assume a minimum screen size of 320x240

View File

@ -468,6 +468,28 @@ void Settings::usage()
<< endl << flush;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const Variant& Settings::value(const string& key) const
{
// Try to find the named setting and answer its value
int idx = -1;
if((idx = getInternalPos(key)) != -1)
return myInternalSettings[idx].value;
else if((idx = getExternalPos(key)) != -1)
return myExternalSettings[idx].value;
else
return EmptyVariant;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::setValue(const string& key, const Variant& value)
{
if(int idx = getInternalPos(key) != -1)
setInternal(key, value, idx);
else
setExternal(key, value);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::saveConfig()
{
@ -518,139 +540,6 @@ void Settings::saveConfig()
out.close();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::setInt(const string& key, const int value)
{
ostringstream stream;
stream << value;
if(int idx = getInternalPos(key) != -1)
setInternal(key, stream.str(), idx);
else
setExternal(key, stream.str());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::setFloat(const string& key, const float value)
{
ostringstream stream;
stream << value;
if(int idx = getInternalPos(key) != -1)
setInternal(key, stream.str(), idx);
else
setExternal(key, stream.str());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::setBool(const string& key, const bool value)
{
ostringstream stream;
stream << value;
if(int idx = getInternalPos(key) != -1)
setInternal(key, stream.str(), idx);
else
setExternal(key, stream.str());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::setString(const string& key, const string& value)
{
if(int idx = getInternalPos(key) != -1)
setInternal(key, value, idx);
else
setExternal(key, value);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::getSize(const string& key, int& x, int& y) const
{
char c = '\0';
x = y = -1;
string size = getString(key);
istringstream buf(size);
buf >> x >> c >> y;
if(c != 'x')
x = y = -1;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Settings::getInt(const string& key) const
{
// Try to find the named setting and answer its value
int idx = -1;
if((idx = getInternalPos(key)) != -1)
return (int) atoi(myInternalSettings[idx].value.c_str());
else if((idx = getExternalPos(key)) != -1)
return (int) atoi(myExternalSettings[idx].value.c_str());
else
return -1;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
float Settings::getFloat(const string& key) const
{
// Try to find the named setting and answer its value
int idx = -1;
if((idx = getInternalPos(key)) != -1)
return (float) atof(myInternalSettings[idx].value.c_str());
else if((idx = getExternalPos(key)) != -1)
return (float) atof(myExternalSettings[idx].value.c_str());
else
return -1.0;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Settings::getBool(const string& key) const
{
// Try to find the named setting and answer its value
int idx = -1;
if((idx = getInternalPos(key)) != -1)
{
const string& value = myInternalSettings[idx].value;
if(value == "1" || value == "true")
return true;
else if(value == "0" || value == "false")
return false;
else
return false;
}
else if((idx = getExternalPos(key)) != -1)
{
const string& value = myExternalSettings[idx].value;
if(value == "1" || value == "true")
return true;
else if(value == "0" || value == "false")
return false;
else
return false;
}
else
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const string& Settings::getString(const string& key) const
{
// Try to find the named setting and answer its value
int idx = -1;
if((idx = getInternalPos(key)) != -1)
return myInternalSettings[idx].value;
else if((idx = getExternalPos(key)) != -1)
return myExternalSettings[idx].value;
else
return EmptyString;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Settings::setSize(const string& key, const int value1, const int value2)
{
ostringstream buf;
buf << value1 << "x" << value2;
setString(key, buf.str());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Settings::getInternalPos(const string& key) const
{
@ -672,7 +561,7 @@ int Settings::getExternalPos(const string& key) const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Settings::setInternal(const string& key, const string& value,
int Settings::setInternal(const string& key, const Variant& value,
int pos, bool useAsInitial)
{
int idx = -1;
@ -727,7 +616,7 @@ int Settings::setInternal(const string& key, const string& value,
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Settings::setExternal(const string& key, const string& value,
int Settings::setExternal(const string& key, const Variant& value,
int pos, bool useAsInitial)
{
int idx = -1;

View File

@ -23,6 +23,7 @@
class OSystem;
#include "Array.hxx"
#include "Variant.hxx"
#include "bspf.hxx"
/**
@ -66,89 +67,32 @@ class Settings
void usage();
/**
Get the value assigned to the specified key. If the key does
not exist then -1 is returned.
Get the value assigned to the specified key.
@param key The key of the setting to lookup
@return The integer value of the setting
@return The (variant) value of the setting
*/
int getInt(const string& key) const;
const Variant& value(const string& key) const;
/**
Get the value assigned to the specified key. If the key does
not exist then -1.0 is returned.
Set the value associated with the specified key.
@param key The key of the setting
@param value The (variant) value to assign to the setting
*/
void setValue(const string& key, const Variant& value);
/**
Convenience methods to return specific types.
@param key The key of the setting to lookup
@return The floating point value of the setting
@return The specific type value of the setting
*/
float getFloat(const string& key) const;
/**
Get the value assigned to the specified key. If the key does
not exist then false is returned.
@param key The key of the setting to lookup
@return The boolean value of the setting
*/
bool getBool(const string& key) const;
/**
Get the value assigned to the specified key. If the key does
not exist then the empty string is returned.
@param key The key of the setting to lookup
@return The string value of the setting
*/
const string& getString(const string& key) const;
/**
Get the x*y size assigned to the specified key. If the key does
not exist (or is invalid) then results are -1 for each item.
@param key The key of the setting to lookup
@return The x and y values encoded in the key
*/
void getSize(const string& key, int& x, int& y) const;
/**
Set the value associated with key to the given value.
@param key The key of the setting
@param value The value to assign to the setting
*/
void setInt(const string& key, const int value);
/**
Set the value associated with key to the given value.
@param key The key of the setting
@param value The value to assign to the setting
*/
void setFloat(const string& key, const float value);
/**
Set the value associated with key to the given value.
@param key The key of the setting
@param value The value to assign to the setting
*/
void setBool(const string& key, const bool value);
/**
Set the value associated with key to the given value.
@param key The key of the setting
@param value The value to assign to the setting
*/
void setString(const string& key, const string& value);
/**
Set the value associated with key to the given value.
@param key The key of the setting
@param value The value to assign to the setting
*/
void setSize(const string& key, const int value1, const int value2);
int getInt(const string& key) const { return value(key).toInt(); }
float getFloat(const string& key) const { return value(key).toFloat(); }
bool getBool(const string& key) const { return value(key).toBool(); }
const string& getString(const string& key) const { return value(key).toString(); }
const GUI::Size getSize(const string& key) const { return value(key).toSize(); }
protected:
/**
@ -184,8 +128,8 @@ class Settings
struct Setting
{
string key;
string value;
string initialValue;
Variant value;
Variant initialValue;
};
typedef Common::Array<Setting> SettingsArray;
@ -199,9 +143,9 @@ class Settings
int getExternalPos(const string& key) const;
/** Add key,value pair to specified array at specified position */
int setInternal(const string& key, const string& value,
int setInternal(const string& key, const Variant& value,
int pos = -1, bool useAsInitial = false);
int setExternal(const string& key, const string& value,
int setExternal(const string& key, const Variant& value,
int pos = -1, bool useAsInitial = false);
private:

View File

@ -155,14 +155,14 @@ void AudioDialog::saveConfig()
Settings& settings = instance().settings();
// Volume
settings.setInt("volume", myVolumeSlider->getValue());
settings.setValue("volume", myVolumeSlider->getValue());
instance().sound().setVolume(myVolumeSlider->getValue());
// Fragsize
settings.setString("fragsize", myFragsizePopup->getSelectedTag());
settings.setValue("fragsize", myFragsizePopup->getSelectedTag());
// Output frequency
settings.setString("freq", myFreqPopup->getSelectedTag());
settings.setValue("freq", myFreqPopup->getSelectedTag());
// Enable/disable sound (requires a restart to take effect)
instance().sound().setEnabled(mySoundEnableCheckbox->getState());

View File

@ -213,17 +213,17 @@ void FileSnapDialog::loadConfig()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FileSnapDialog::saveConfig()
{
instance().settings().setString("romdir", myRomPath->getEditString());
instance().settings().setString("snapsavedir", mySnapSavePath->getEditString());
instance().settings().setString("snaploaddir", mySnapLoadPath->getEditString());
instance().settings().setString("cheatfile", myCheatFile->getEditString());
instance().settings().setString("palettefile", myPaletteFile->getEditString());
instance().settings().setString("propsfile", myPropsFile->getEditString());
instance().settings().setString("statedir", myStatePath->getEditString());
instance().settings().setString("nvramdir", myNVRamPath->getEditString());
instance().settings().setBool("sssingle", mySnapSingle->getState());
instance().settings().setBool("ss1x", mySnap1x->getState());
instance().settings().setString("ssinterval", mySnapInterval->getSelectedTag());
instance().settings().setValue("romdir", myRomPath->getEditString());
instance().settings().setValue("snapsavedir", mySnapSavePath->getEditString());
instance().settings().setValue("snaploaddir", mySnapLoadPath->getEditString());
instance().settings().setValue("cheatfile", myCheatFile->getEditString());
instance().settings().setValue("palettefile", myPaletteFile->getEditString());
instance().settings().setValue("propsfile", myPropsFile->getEditString());
instance().settings().setValue("statedir", myStatePath->getEditString());
instance().settings().setValue("nvramdir", myNVRamPath->getEditString());
instance().settings().setValue("sssingle", mySnapSingle->getState());
instance().settings().setValue("ss1x", mySnap1x->getState());
instance().settings().setValue("ssinterval", mySnapInterval->getSelectedTag());
// Flush changes to disk and inform the OSystem
instance().saveConfig();

View File

@ -202,23 +202,23 @@ void GlobalPropsDialog::saveConfig()
s = myBSType->getSelectedTag();
if(s == "AUTO") s = "";
settings.setString("bs", s);
settings.setValue("bs", s);
s = myLeftDiff->getSelectedTag();
if(s == "DEFAULT") s = "";
settings.setString("ld", s);
settings.setValue("ld", s);
s = myRightDiff->getSelectedTag();
if(s == "DEFAULT") s = "";
settings.setString("rd", s);
settings.setValue("rd", s);
s = myTVType->getSelectedTag();
if(s == "DEFAULT") s = "";
settings.setString("tv", s);
settings.setValue("tv", s);
settings.setBool("holdselect", myHoldSelect->getState());
settings.setBool("holdreset", myHoldReset->getState());
settings.setBool("holdbutton0", myHoldButton0->getState());
settings.setValue("holdselect", myHoldSelect->getState());
settings.setValue("holdreset", myHoldReset->getState());
settings.setValue("holdbutton0", myHoldButton0->getState());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -238,32 +238,32 @@ void InputDialog::saveConfig()
// Joystick deadzone
int deadzone = myDeadzone->getValue();
instance().settings().setInt("joydeadzone", deadzone);
instance().settings().setValue("joydeadzone", deadzone);
Joystick::setDeadZone(deadzone);
// Grab mouse
instance().settings().setBool("grabmouse", myGrabMouse->getState());
instance().settings().setValue("grabmouse", myGrabMouse->getState());
instance().frameBuffer().setCursorState();
// Paddle speed (digital and mouse)
int sensitivity = myDPaddleSpeed->getValue();
instance().settings().setInt("dsense", sensitivity);
instance().settings().setValue("dsense", sensitivity);
Paddles::setDigitalSensitivity(sensitivity);
sensitivity = myMPaddleSpeed->getValue();
instance().settings().setInt("msense", sensitivity);
instance().settings().setValue("msense", sensitivity);
Paddles::setMouseSensitivity(sensitivity);
// AtariVox serial port
instance().settings().setString("avoxport", myAVoxPort->getEditString());
instance().settings().setValue("avoxport", myAVoxPort->getEditString());
// Allow all 4 joystick directions
bool allowall4 = myAllowAll4->getState();
instance().settings().setBool("joyallow4", allowall4);
instance().settings().setValue("joyallow4", allowall4);
instance().eventHandler().allowAllDirections(allowall4);
// Use mouse as a controller
bool usemouse = myMouseControl->getState();
instance().settings().setBool("usemouse", usemouse);
instance().settings().setValue("usemouse", usemouse);
instance().eventHandler().setMouseControllerMode(usemouse);
}

View File

@ -31,7 +31,8 @@
Launcher::Launcher(OSystem* osystem)
: DialogContainer(osystem)
{
myOSystem->settings().getSize("launcherres", (int&)myWidth, (int&)myHeight);
const GUI::Size& s = myOSystem->settings().getSize("launcherres");
myWidth = s.w; myHeight = s.h;
// The launcher dialog is resizable, within certain bounds
// We check those bounds now
@ -40,7 +41,8 @@ Launcher::Launcher(OSystem* osystem)
myWidth = BSPF_min(myWidth, osystem->desktopWidth());
myHeight = BSPF_min(myHeight, osystem->desktopHeight());
myOSystem->settings().setSize("launcherres", myWidth, myHeight);
myOSystem->settings().setValue("launcherres",
GUI::Size(myWidth, myHeight));
myBaseDialog = new LauncherDialog(myOSystem, this, 0, 0, myWidth, myHeight);
}

View File

@ -526,7 +526,7 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
const string& result =
instance().createConsole(romnode, myGameList->md5(item));
if(result == EmptyString)
instance().settings().setString("lastrom", myList->getSelectedString());
instance().settings().setValue("lastrom", myList->getSelectedString());
else
instance().frameBuffer().showMessage(result, kMiddleCenter, true);
}
@ -569,7 +569,7 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
case kStartupRomDirChosenCmd:
{
FilesystemNode dir(myRomDir->getResult());
instance().settings().setString("romdir", dir.getShortPath());
instance().settings().setValue("romdir", dir.getShortPath());
// fall through to the next case
}
case kRomDirChosenCmd:

View File

@ -175,7 +175,7 @@ void LauncherFilterDialog::saveConfig()
{
const string& type = myFileType->getSelectedTag();
if(type == "allfiles" || type == "allroms")
instance().settings().setString("launcherexts", type);
instance().settings().setValue("launcherexts", type);
else
{
ostringstream buf;
@ -185,9 +185,9 @@ void LauncherFilterDialog::saveConfig()
// No ROMs selected means use all files
if(buf.str() == "")
instance().settings().setString("launcherexts", "allfiles");
instance().settings().setValue("launcherexts", "allfiles");
else
instance().settings().setString("launcherexts", buf.str());
instance().settings().setValue("launcherexts", buf.str());
}
// Let parent know about the changes

View File

@ -107,9 +107,9 @@ void LoggerDialog::loadConfig()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LoggerDialog::saveConfig()
{
instance().settings().setString("loglevel",
instance().settings().setValue("loglevel",
myLogLevel->getSelectedTag());
instance().settings().setBool("logtoconsole", myLogToConsole->getState());
instance().settings().setValue("logtoconsole", myLogToConsole->getState());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -40,9 +40,48 @@ struct Point
Point() : x(0), y(0) {};
Point(const Point & p) : x(p.x), y(p.y) {};
explicit Point(int x1, int y1) : x(x1), y(y1) {};
Point(const string& p) {
char c = '\0';
x = y = -1;
istringstream buf(p);
buf >> x >> c >> y;
if(c != 'x')
x = y = 0;
}
Point & operator=(const Point & p) { x = p.x; y = p.y; return *this; };
bool operator==(const Point & p) const { return x == p.x && y == p.y; };
bool operator!=(const Point & p) const { return x != p.x || y != p.y; };
friend ostream& operator<<(ostream& os, const Point& p) {
os << p.x << "x" << p.y;
return os;
}
};
struct Size
{
int w; //!< The width part of the size
int h; //!< The height part of the size
Size() : w(0), h(0) {};
Size(const Size & s) : w(s.w), h(s.h) {};
explicit Size(int w1, int h1) : w(w1), h(h1) {};
Size(const string& s) {
char c = '\0';
w = h = -1;
istringstream buf(s);
buf >> w >> c >> h;
if(c != 'x')
w = h = -1;
}
Size & operator=(const Size & s) { w = s.w; h = s.h; return *this; };
bool operator==(const Size & s) const { return w == s.w && h == s.h; };
bool operator!=(const Size & s) const { return w != s.w || h != s.h; };
friend ostream& operator<<(ostream& os, const Size& s) {
os << s.w << "x" << s.h;
return os;
}
};
/*
@ -73,13 +112,18 @@ struct Rect
{
assert(isValidRect());
}
int x() const { return left; }
int y() const { return top; }
int width() const { return right - left; }
int height() const { return bottom - top; }
Point point() const { return Point(x(), y()); }
void setWidth(int aWidth) { right = left + aWidth; }
int width() const { return right - left; }
int height() const { return bottom - top; }
Size size() const { return Size(width(), height()); }
void setWidth(int aWidth) { right = left + aWidth; }
void setHeight(int aHeight) { bottom = top + aHeight; }
void setSize(const Size& size) { setWidth(size.w); setHeight(size.h); }
/*
@param x the horizontal position to check
@ -166,8 +210,7 @@ struct Rect
}
friend ostream& operator<<(ostream& os, const Rect& r) {
os << "x=" << r.x() << ", y=" << r.y()
<< ", w=" << r.width() << ", h=" << r.height();
os << "Point: " << r.point() << ", Size: " << r.size();
return os;
}
};

View File

@ -285,10 +285,10 @@ UIDialog::~UIDialog()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void UIDialog::loadConfig()
{
int w, h;
// Launcher size
instance().settings().getSize("launcherres", w, h);
const GUI::Size& ls = instance().settings().getSize("launcherres");
int w = ls.w, h = ls.h;
w = BSPF_max(w, 320);
h = BSPF_max(h, 240);
w = BSPF_min(w, 1920);
@ -313,7 +313,8 @@ void UIDialog::loadConfig()
#ifdef DEBUGGER_SUPPORT
// Debugger size
instance().settings().getSize("debuggerres", w, h);
const GUI::Size& ds = instance().settings().getSize("debuggerres");
w = ds.w, h = ds.h;
w = BSPF_max(w, 1080);
h = BSPF_max(h, 720);
w = BSPF_min(w, 1920);
@ -344,36 +345,38 @@ void UIDialog::loadConfig()
void UIDialog::saveConfig()
{
// Launcher size
instance().settings().setSize("launcherres",
myLauncherWidthSlider->getValue(), myLauncherHeightSlider->getValue());
instance().settings().setValue("launcherres",
GUI::Size(myLauncherWidthSlider->getValue(),
myLauncherHeightSlider->getValue()));
// Launcher font
instance().settings().setString("launcherfont",
instance().settings().setValue("launcherfont",
myLauncherFontPopup->getSelectedTag());
// ROM launcher info viewer
instance().settings().setString("romviewer",
instance().settings().setValue("romviewer",
myRomViewerPopup->getSelectedTag());
// Exit to Launcher
instance().settings().setString("exitlauncher",
instance().settings().setValue("exitlauncher",
myLauncherExitPopup->getSelectedTag());
// Debugger size
instance().settings().setSize("debuggerres",
myDebuggerWidthSlider->getValue(), myDebuggerHeightSlider->getValue());
instance().settings().setValue("debuggerres",
GUI::Size(myDebuggerWidthSlider->getValue(),
myDebuggerHeightSlider->getValue()));
// UI palette
instance().settings().setString("uipalette",
instance().settings().setValue("uipalette",
myPalettePopup->getSelectedTag());
// Listwidget quick delay
instance().settings().setString("listdelay",
instance().settings().setValue("listdelay",
myListDelayPopup->getSelectedTag());
ListWidget::setQuickSelectDelay(atoi(myListDelayPopup->getSelectedTag().c_str()));
// Mouse wheel lines
instance().settings().setString("mwheel",
instance().settings().setValue("mwheel",
myWheelLinesPopup->getSelectedTag());
ScrollBarWidget::setWheelLines(atoi(myWheelLinesPopup->getSelectedTag().c_str()));
}

View File

@ -495,31 +495,31 @@ void VideoDialog::loadConfig()
void VideoDialog::saveConfig()
{
// Renderer setting
instance().settings().setString("video", myRendererPopup->getSelectedTag());
instance().settings().setValue("video", myRendererPopup->getSelectedTag());
// TIA Filter
instance().settings().setString("tia_filter", myTIAFilterPopup->getSelectedTag());
instance().settings().setValue("tia_filter", myTIAFilterPopup->getSelectedTag());
// TIA Palette
instance().settings().setString("palette", myTIAPalettePopup->getSelectedTag());
instance().settings().setValue("palette", myTIAPalettePopup->getSelectedTag());
// Fullscreen resolution
instance().settings().setString("fullres", myFSResPopup->getSelectedTag());
instance().settings().setValue("fullres", myFSResPopup->getSelectedTag());
// Wait between frames
instance().settings().setString("timing", myFrameTimingPopup->getSelectedTag());
instance().settings().setValue("timing", myFrameTimingPopup->getSelectedTag());
// GL Filter setting
instance().settings().setBool("gl_inter",
instance().settings().setValue("gl_inter",
myGLFilterPopup->getSelectedTag() == "linear" ? true : false);
// GL aspect ratio setting (NTSC and PAL)
instance().settings().setString("gl_aspectn", myNAspectRatioLabel->getLabel());
instance().settings().setString("gl_aspectp", myPAspectRatioLabel->getLabel());
instance().settings().setValue("gl_aspectn", myNAspectRatioLabel->getLabel());
instance().settings().setValue("gl_aspectp", myPAspectRatioLabel->getLabel());
// Framerate
int i = myFrameRateSlider->getValue();
instance().settings().setInt("framerate", i);
instance().settings().setValue("framerate", i);
if(&instance().console())
{
// Make sure auto-frame calculation is only enabled when necessary
@ -528,30 +528,30 @@ void VideoDialog::saveConfig()
}
// Fullscreen
instance().settings().setString("fullscreen", myFullscreenPopup->getSelectedTag());
instance().settings().setValue("fullscreen", myFullscreenPopup->getSelectedTag());
// PAL color-loss effect
instance().settings().setBool("colorloss", myColorLossCheckbox->getState());
instance().settings().setValue("colorloss", myColorLossCheckbox->getState());
if(&instance().console())
instance().console().toggleColorLoss(myColorLossCheckbox->getState());
// GL stretch setting
instance().settings().setBool("gl_fsscale", myGLStretchCheckbox->getState());
instance().settings().setValue("gl_fsscale", myGLStretchCheckbox->getState());
// Use sync to vertical blank (GL mode only)
instance().settings().setBool("gl_vsync", myUseVSyncCheckbox->getState());
instance().settings().setValue("gl_vsync", myUseVSyncCheckbox->getState());
// Show UI messages
instance().settings().setBool("uimessages", myUIMessagesCheckbox->getState());
instance().settings().setValue("uimessages", myUIMessagesCheckbox->getState());
// Center window
instance().settings().setBool("center", myCenterCheckbox->getState());
instance().settings().setValue("center", myCenterCheckbox->getState());
// Fast loading of Supercharger BIOS
instance().settings().setBool("fastscbios", myFastSCBiosCheckbox->getState());
instance().settings().setValue("fastscbios", myFastSCBiosCheckbox->getState());
// TV Mode
instance().settings().setString("tv_filter", myTVMode->getSelectedTag());
instance().settings().setValue("tv_filter", myTVMode->getSelectedTag());
// TV Custom adjustables
NTSCFilter::Adjustable adj;
@ -568,8 +568,8 @@ void VideoDialog::saveConfig()
instance().frameBuffer().ntsc().setCustomAdjustables(adj);
// TV scanline intensity and interpolation
instance().settings().setString("tv_scanlines", myTVScanIntenseLabel->getLabel());
instance().settings().setBool("tv_scaninter", myTVScanInterpolate->getState());
instance().settings().setValue("tv_scanlines", myTVScanIntenseLabel->getLabel());
instance().settings().setValue("tv_scaninter", myTVScanInterpolate->getState());
// Finally, issue a complete framebuffer re-initialization
instance().createFrameBuffer();