diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 166c9c16b..849ccbe2e 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -426,6 +426,9 @@ void OMW::Engine::go() // Start the main rendering loop mOgre->start(); + // Save user settings + settings.saveUser(settingspath); + std::cout << "Quitting peacefully.\n"; } diff --git a/apps/openmw/mwrender/terrainmaterial.cpp b/apps/openmw/mwrender/terrainmaterial.cpp index 67ebf45af..922ea2280 100644 --- a/apps/openmw/mwrender/terrainmaterial.cpp +++ b/apps/openmw/mwrender/terrainmaterial.cpp @@ -36,7 +36,7 @@ THE SOFTWARE. #include "OgreHardwarePixelBuffer.h" #include "OgreShadowCameraSetupPSSM.h" -#define POINTLIGHTS +#include namespace Ogre { @@ -220,22 +220,10 @@ namespace Ogre } - int TerrainMaterialGeneratorB::SM2Profile::getNumberOfLightsSupported() const - { - #ifndef POINTLIGHTS - return 1; - #else - // number of supported lights depends on the number of available constant registers, - // which in turn depends on the shader profile used - if (GpuProgramManager::getSingleton().isSyntaxSupported("ps_3_0") - || GpuProgramManager::getSingleton().isSyntaxSupported("ps_4_0") - || GpuProgramManager::getSingleton().isSyntaxSupported("fp40") - ) - return 32; - else - return 8; - #endif - } + int TerrainMaterialGeneratorB::SM2Profile::getNumberOfLightsSupported() const + { + return Settings::Manager::getInt("num lights", "Terrain"); + } //--------------------------------------------------------------------- MaterialPtr TerrainMaterialGeneratorB::SM2Profile::generate(const Terrain* terrain) { @@ -565,7 +553,8 @@ namespace Ogre { params->setNamedAutoConstant("lightPosObjSpace"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_POSITION_OBJECT_SPACE, i); params->setNamedAutoConstant("lightDiffuseColour"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_DIFFUSE_COLOUR, i); - params->setNamedAutoConstant("lightAttenuation"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_ATTENUATION, i); + if (prof->getNumberOfLightsSupported() > 1) + params->setNamedAutoConstant("lightAttenuation"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_ATTENUATION, i); //params->setNamedAutoConstant("lightSpecularColour"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_SPECULAR_COLOUR, i); } @@ -980,10 +969,9 @@ namespace Ogre //"uniform float3 lightSpecularColour"<getNumberOfLightsSupported() > 1) + outStream << + "uniform float4 lightAttenuation"<getNumberOfLightsSupported() > 1) + outStream << "float d; \n" "float attn; \n"; - #endif outStream << " eyeDir = normalize(eyeDir); \n"; @@ -1144,13 +1131,12 @@ namespace Ogre outStream << " float3 halfAngle"<getNumberOfLightsSupported() > 1) outStream << // pre-multiply light color with attenuation factor "d = length( lightDir"<begin(); i != settings->end(); ++i) { - fout << i->first.c_str() << '=' << i->second.c_str() << '\n'; + fout << i->first.c_str() << " = " << i->second.c_str() << '\n'; } - seci.getNext(); + CategorySettingValueMap::iterator it = mNewSettings.begin(); + while (it != mNewSettings.end()) + { + if (it->first.first == sectionName) + { + fout << it->first.second << " = " << it->second << '\n'; + mNewSettings.erase(it++); + } + else + ++it; + } + } + + std::string category = ""; + for (CategorySettingValueMap::iterator it = mNewSettings.begin(); + it != mNewSettings.end(); ++it) + { + if (category != it->first.first) + { + category = it->first.first; + fout << '\n' << '[' << category << ']' << '\n'; + } + fout << it->first.second << " = " << it->second << '\n'; } } const std::string Manager::getString (const std::string& setting, const std::string& category) { + if (mNewSettings.find(std::make_pair(category, setting)) != mNewSettings.end()) + return mNewSettings[std::make_pair(category, setting)]; + std::string defaultval = mDefaultFile.getSetting(setting, category); return mFile.getSetting(setting, category, defaultval); } @@ -73,22 +99,45 @@ const bool Manager::getBool (const std::string& setting, const std::string& cate void Manager::setString (const std::string& setting, const std::string& category, const std::string& value) { + CategorySetting s = std::make_pair(category, setting); + bool found=false; - Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category); - while (it.hasMoreElements()) + try { - Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current(); - - if ((*i).first == setting && (*i).second != value) + Ogre::ConfigFile::SettingsIterator it = mFile.getSettingsIterator(category); + while (it.hasMoreElements()) { - mChangedSettings.push_back(std::make_pair(setting, category)); - (*i).second = value; - found = true; + Ogre::ConfigFile::SettingsMultiMap::iterator i = it.current(); + + if ((*i).first == setting) + { + if ((*i).second != value) + { + mChangedSettings.push_back(std::make_pair(category, setting)); + (*i).second = value; + } + found = true; + } + + it.getNext(); } + } + catch (Ogre::Exception&) + {} - it.getNext(); + if (!found) + { + if (mNewSettings.find(s) != mNewSettings.end()) + { + if (mNewSettings[s] != value) + { + mChangedSettings.push_back(std::make_pair(category, setting)); + mNewSettings[s] = value; + } + } + else + mNewSettings[s] = value; } - assert(found && "Attempting to change a non-existing setting"); } void Manager::setInt (const std::string& setting, const std::string& category, const int value) @@ -106,9 +155,9 @@ void Manager::setBool (const std::string& setting, const std::string& category, setString(setting, category, Ogre::StringConverter::toString(value)); } -const SettingCategoryVector Manager::apply() +const CategorySettingVector Manager::apply() { - SettingCategoryVector vec = mChangedSettings; + CategorySettingVector vec = mChangedSettings; mChangedSettings.clear(); return vec; } diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index 368b5e692..f670ea1dd 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -5,7 +5,9 @@ namespace Settings { - typedef std::vector< std::pair > SettingCategoryVector; + typedef std::pair < std::string, std::string > CategorySetting; + typedef std::vector< std::pair > CategorySettingVector; + typedef std::map < CategorySetting, std::string > CategorySettingValueMap; /// /// \brief Settings management (can change during runtime) @@ -16,9 +18,12 @@ namespace Settings static Ogre::ConfigFile mFile; static Ogre::ConfigFile mDefaultFile; - static SettingCategoryVector mChangedSettings; + static CategorySettingVector mChangedSettings; ///< tracks all the settings that were changed since the last apply() call + static CategorySettingValueMap mNewSettings; + ///< tracks all the settings that are in the default file, but not in user file yet + void loadDefault (const std::string& file); ///< load file as the default settings (can be overridden by user settings) @@ -31,7 +36,7 @@ namespace Settings void saveUser (const std::string& file); ///< save user settings to file - const SettingCategoryVector apply(); + static const CategorySettingVector apply(); ///< returns the list of changed settings and then clears it static const int getInt (const std::string& setting, const std::string& category); diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 7a35b7102..1a6b9b328 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -1,3 +1,6 @@ [Objects] shaders = true num lights = 8 + +[Terrain] +num lights = 8