From 0ec20b23aa4a2cfad0145dc33fc0b16104b811bb Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sun, 14 Sep 2014 12:48:00 +1000 Subject: [PATCH] Initial working version. Video/rendering options supported. No GUI yet. --- apps/opencs/editor.cpp | 32 ++++- apps/opencs/model/settings/usersettings.cpp | 130 ++++++++++++++++++-- apps/opencs/model/settings/usersettings.hpp | 1 + 3 files changed, 150 insertions(+), 13 deletions(-) diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index e8e2d9077..d3e5c6720 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -259,21 +259,32 @@ int CS::Editor::run() std::auto_ptr CS::Editor::setupGraphics() { - // TODO: setting - Ogre::Root::getSingleton().setRenderSystem(Ogre::Root::getSingleton().getRenderSystemByName("OpenGL Rendering Subsystem")); + std::string rendersystem = mUserSettings.settingValue("Video/render system").toStdString(); + Ogre::Root::getSingleton().setRenderSystem(Ogre::Root::getSingleton().getRenderSystemByName(rendersystem)); + std::cout << "editor: render system " + rendersystem << std::endl; // FIXME: debug Ogre::Root::getSingleton().initialise(false); // Create a hidden background window to keep resources Ogre::NameValuePairList params; params.insert(std::make_pair("title", "")); - params.insert(std::make_pair("FSAA", "0")); - params.insert(std::make_pair("vsync", "false")); + + std::string antialiasing = mUserSettings.settingValue("Video/antialiasing").toStdString(); + if(antialiasing == "MSAA 16") antialiasing = "16"; + else if(antialiasing == "MSAA 8") antialiasing = "8"; + else if(antialiasing == "MSAA 4") antialiasing = "4"; + else if(antialiasing == "MSAA 2") antialiasing = "2"; + else antialiasing = "0"; + params.insert(std::make_pair("FSAA", antialiasing)); + + std::string vsync = mUserSettings.settingValue("Video/vsync").toStdString() == "true" ? "true" : "false"; + params.insert(std::make_pair("vsync", vsync)); params.insert(std::make_pair("hidden", "true")); #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE params.insert(std::make_pair("macAPI", "cocoa")); #endif - Ogre::RenderWindow* hiddenWindow = Ogre::Root::getSingleton().createRenderWindow("InactiveHidden", 1, 1, false, ¶ms); + bool fullscreen = mUserSettings.settingValue("Video/fullscreen").toStdString() == "true" ? true : false; + Ogre::RenderWindow* hiddenWindow = Ogre::Root::getSingleton().createRenderWindow("InactiveHidden", 1, 1, fullscreen, ¶ms); hiddenWindow->setActive(false); sh::OgrePlatform* platform = @@ -286,7 +297,16 @@ std::auto_ptr CS::Editor::setupGraphics() std::auto_ptr factory (new sh::Factory (platform)); - factory->setCurrentLanguage (sh::Language_GLSL); /// \todo make this configurable + std::string shLang = mUserSettings.settingValue("Shiny/language").toStdString(); + enum sh::Language lang; + if(shLang == "CG") lang = sh::Language_CG; + else if(shLang == "HLSL") lang = sh::Language_HLSL; + else if(shLang == "GLSL") lang = sh::Language_GLSL; + else if(shLang == "GLSLES") lang = sh::Language_GLSLES; + else if(shLang == "Count") lang = sh::Language_Count; + else lang = sh::Language_None; + + factory->setCurrentLanguage (lang); factory->setWriteSourceCache (true); factory->setReadSourceCache (true); factory->setReadMicrocodeCache (true); diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index 04f98f0d6..be0e3ab26 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -4,10 +4,13 @@ #include #include +#include + #include #include "setting.hpp" #include "support.hpp" +#include #include /** @@ -26,17 +29,66 @@ namespace boost } /* namespace boost */ #endif /* (BOOST_VERSION <= 104600) */ +/* + * FIXME: temporary notes + * + * - CSVSettings::Dialog::Dialog is the settings window + * - provide a hard coded default if not found in config file + * - provide tooltips + * - save/cancel option (or auto-save?) + * - opencs.ini: where all these settings are saved + * . error if can't create file (directory permissions) or save file (file permissions) + * - settings.cfg: where Graphics default settings come from (read only) + * . warning if neither default or user cfg not found or not readable (file permissions) + * - openmw.cfg: not used + * + * - Tabbed view similar to OpenMW or Launcher + * . Video Settings + * . Display Settngs + * . Misc Settings + * + * - Video settings: tick box for "Use the video settings from OpenMW" (default, + * individual settings greyed out) + * . CS::Editor::setupGraphics() + * . the defaults should be the initial setting when unticked, unless previous user + * settings were found + * # OpenGL/Direct3D9 Rendering Subsystem + * # Vsync + * # FSAA (antialiasing) + * # GLSL/CG shader language + * . other shiny options + * . screen number + * # full screen / windowed (resolution) <- replace already existing + * + * - Display Settings + * . text only / icon + text <- replace already existing + * . limit the number of subviews per top level view + * . option to reuse subviews + * . v/w/dialoguesubview min width 325 + * . filter pattern syntax + * + * - misc + * . v/r/scenewidget mFastFactor(4) + * . v/r/scenewidget far clip distance + * . v/r/scenewidget start timer 20 + * . v/r/scenewidget shortcut + * . v/d/adjusterwidget error + * . v/r/navigation factor /= 2 + * . v/w/table redirect extended action + */ + CSMSettings::UserSettings *CSMSettings::UserSettings::mUserSettingsInstance = 0; CSMSettings::UserSettings::UserSettings (const Files::ConfigurationManager& configurationManager) -: mCfgMgr (configurationManager) + : mCfgMgr (configurationManager) + , mSettingDefinitions(NULL) + , mSettingCfgDefinitions(NULL) { assert(!mUserSettingsInstance); mUserSettingsInstance = this; - mSettingDefinitions = 0; - buildSettingModelDefaults(); + mSettingCfgDefinitions = new QSettings(QSettings::IniFormat, QSettings::UserScope, ""); } void CSMSettings::UserSettings::buildSettingModelDefaults() @@ -276,6 +328,8 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() CSMSettings::UserSettings::~UserSettings() { + delete mSettingDefinitions; + delete mSettingCfgDefinitions; mUserSettingsInstance = 0; } @@ -305,6 +359,54 @@ void CSMSettings::UserSettings::loadSettings (const QString &fileName) mSettingDefinitions = new QSettings (QSettings::IniFormat, QSettings::UserScope, "opencs", QString(), this); + + // if user setting (opencs.ini) exists + // if readable, then check whether the option to use settings.cfg video settings should be used is set + // use the config settings from settings.cfg + // else if video config found + // use the config settings from opencs.ini + // if any of the config option is not found, use hard coded default in this file + // + + // Create the settings manager and load default settings file + const std::string localdefault = mCfgMgr.getLocalPath().string() + "/settings-default.cfg"; + const std::string globaldefault = mCfgMgr.getGlobalPath().string() + "/settings-default.cfg"; + + Settings::Manager settings; + // prefer local + if (boost::filesystem::exists(localdefault)) + settings.loadDefault(localdefault); + else if (boost::filesystem::exists(globaldefault)) + settings.loadDefault(globaldefault); + else + std::cerr<< "No default settings file found! Make sure the file \"settings-default.cfg\" was properly installed."<< std::endl; + + // load user settings if they exist, otherwise just load the default settings as user settings + const std::string settingspath = mCfgMgr.getUserConfigPath().string() + "/settings.cfg"; + if (boost::filesystem::exists(settingspath)) + settings.loadUser(settingspath); + else if (boost::filesystem::exists(localdefault)) + settings.loadUser(localdefault); + else if (boost::filesystem::exists(globaldefault)) + settings.loadUser(globaldefault); + + std::string renderSystem = settings.getString("render system", "Video"); + std::cout << "user settings: render system " + renderSystem << std::endl; // FIXME: debug + + if(renderSystem == "") + { +#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 + renderSystem = "Direct3D9 Rendering Subsystem"; +#else + renderSystem = "OpenGL Rendering Subsystem"; +#endif + } + mSettingCfgDefinitions->setValue("Video/render system", renderSystem.c_str()); + // Force shiny language based on render system + if(renderSystem == "Direct3D9 Rendering Subsystem") + mSettingDefinitions->setValue("Shiny/language", "CG"); + else + mSettingDefinitions->setValue("Shiny/language", "GLSL"); } bool CSMSettings::UserSettings::hasSettingDefinitions @@ -326,10 +428,25 @@ void CSMSettings::UserSettings::saveDefinitions() const QString CSMSettings::UserSettings::settingValue (const QString &settingKey) { - if (!mSettingDefinitions->contains (settingKey)) - return QString(); + QStringList defs; - QStringList defs = mSettingDefinitions->value (settingKey).toStringList(); + // check if video settings are overriden + if(settingKey.contains(QRegExp("^\\b(Video)", Qt::CaseInsensitive)) && + mSettingDefinitions->value("Video/override settings.cfg") == "true") + { + std::cout << "user settings: override " << std::endl; // FIXME: debug + if (!mSettingCfgDefinitions->contains (settingKey)) + return QString(); + else + defs = mSettingCfgDefinitions->value (settingKey).toStringList(); + } + else + { + if (!mSettingDefinitions->contains (settingKey)) + return QString(); + + defs = mSettingDefinitions->value (settingKey).toStringList(); + } if (defs.isEmpty()) return QString(); @@ -387,7 +504,6 @@ void CSMSettings::UserSettings::removeSetting } } - CSMSettings::SettingPageMap CSMSettings::UserSettings::settingPageMap() const { SettingPageMap pageMap; diff --git a/apps/opencs/model/settings/usersettings.hpp b/apps/opencs/model/settings/usersettings.hpp index 7e553caf6..9d9b5c9b0 100644 --- a/apps/opencs/model/settings/usersettings.hpp +++ b/apps/opencs/model/settings/usersettings.hpp @@ -33,6 +33,7 @@ namespace CSMSettings { const Files::ConfigurationManager& mCfgMgr; QSettings *mSettingDefinitions; + QSettings *mSettingCfgDefinitions; QList mSettings; public: