Move Fallback map to components/

pull/872/head
scrawl 9 years ago
parent ece40b1e96
commit 6546c05428

@ -3,6 +3,7 @@
#include <components/version/version.hpp> #include <components/version/version.hpp>
#include <components/files/configurationmanager.hpp> #include <components/files/configurationmanager.hpp>
#include <components/fallback/validate.hpp>
#include <SDL_messagebox.h> #include <SDL_messagebox.h>
#include <SDL_main.h> #include <SDL_main.h>
@ -52,39 +53,8 @@ inline boost::filesystem::path lexical_cast<boost::filesystem::path, std::string
} /* namespace boost */ } /* namespace boost */
#endif /* (BOOST_VERSION <= 104600) */ #endif /* (BOOST_VERSION <= 104600) */
struct FallbackMap {
std::map<std::string,std::string> mMap;
};
void validate(boost::any &v, std::vector<std::string> const &tokens, FallbackMap*, int)
{
if(v.empty())
{
v = boost::any(FallbackMap());
}
FallbackMap *map = boost::any_cast<FallbackMap>(&v);
for(std::vector<std::string>::const_iterator it=tokens.begin(); it != tokens.end(); ++it)
{
int sep = it->find(",");
if(sep < 1 || sep == (int)it->length()-1)
#if (BOOST_VERSION < 104200)
throw boost::program_options::validation_error("invalid value");
#else
throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value);
#endif
std::string key(it->substr(0,sep));
std::string value(it->substr(sep+1));
if(map->mMap.find(key) == map->mMap.end())
{
map->mMap.insert(std::make_pair (key,value));
}
}
}
using namespace Fallback;
/** /**
* \brief Parses application command line and calls \ref Cfg::ConfigurationManager * \brief Parses application command line and calls \ref Cfg::ConfigurationManager

@ -56,7 +56,6 @@ namespace MWMechanics
namespace MWWorld namespace MWWorld
{ {
class Fallback;
class CellStore; class CellStore;
class Player; class Player;
class LocalScripts; class LocalScripts;
@ -67,6 +66,11 @@ namespace MWWorld
typedef std::vector<std::pair<MWWorld::Ptr,MWMechanics::Movement> > PtrMovementList; typedef std::vector<std::pair<MWWorld::Ptr,MWMechanics::Movement> > PtrMovementList;
} }
namespace Fallback
{
class Map;
}
namespace MWBase namespace MWBase
{ {
/// \brief Interface for the World (implemented in MWWorld) /// \brief Interface for the World (implemented in MWWorld)
@ -119,7 +123,7 @@ namespace MWBase
virtual void adjustSky() = 0; virtual void adjustSky() = 0;
virtual const MWWorld::Fallback *getFallback () const = 0; virtual const Fallback::Map *getFallback () const = 0;
virtual MWWorld::Player& getPlayer() = 0; virtual MWWorld::Player& getPlayer() = 0;
virtual MWWorld::Ptr getPlayerPtr() = 0; virtual MWWorld::Ptr getPlayerPtr() = 0;

@ -1,5 +1,7 @@
#include "charactercreation.hpp" #include "charactercreation.hpp"
#include <components/fallback/fallback.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"
@ -10,7 +12,6 @@
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/fallback.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "textinput.hpp" #include "textinput.hpp"
@ -32,7 +33,7 @@ namespace
const ESM::Class::Specialization mSpecializations[3]={ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth}; // The specialization for each answer const ESM::Class::Specialization mSpecializations[3]={ESM::Class::Combat, ESM::Class::Magic, ESM::Class::Stealth}; // The specialization for each answer
Step sGenerateClassSteps(int number) { Step sGenerateClassSteps(int number) {
number++; number++;
const MWWorld::Fallback* fallback=MWBase::Environment::get().getWorld()->getFallback(); const Fallback::Map* fallback=MWBase::Environment::get().getWorld()->getFallback();
Step step = {fallback->getFallbackString("Question_"+MyGUI::utility::toString(number)+"_Question"), Step step = {fallback->getFallbackString("Question_"+MyGUI::utility::toString(number)+"_Question"),
{fallback->getFallbackString("Question_"+MyGUI::utility::toString(number)+"_AnswerOne"), {fallback->getFallbackString("Question_"+MyGUI::utility::toString(number)+"_AnswerOne"),
fallback->getFallbackString("Question_"+MyGUI::utility::toString(number)+"_AnswerTwo"), fallback->getFallbackString("Question_"+MyGUI::utility::toString(number)+"_AnswerTwo"),

@ -4,13 +4,14 @@
#include <MyGUI_ImageBox.h> #include <MyGUI_ImageBox.h>
#include <MyGUI_EditBox.h> #include <MyGUI_EditBox.h>
#include <components/fallback/fallback.hpp>
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/fallback.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"

@ -35,11 +35,12 @@
#include <components/sceneutil/skeleton.hpp> #include <components/sceneutil/skeleton.hpp>
#include <components/sceneutil/positionattitudetransform.hpp> #include <components/sceneutil/positionattitudetransform.hpp>
#include <components/fallback/fallback.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/fallback.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwmechanics/character.hpp" // FIXME: for MWMechanics::Priority #include "../mwmechanics/character.hpp" // FIXME: for MWMechanics::Priority
@ -1113,7 +1114,7 @@ namespace MWRender
osg::ref_ptr<osg::Light> light (new osg::Light); osg::ref_ptr<osg::Light> light (new osg::Light);
lightSource->setNodeMask(Mask_Lighting); lightSource->setNodeMask(Mask_Lighting);
const MWWorld::Fallback* fallback = MWBase::Environment::get().getWorld()->getFallback(); const Fallback::Map* fallback = MWBase::Environment::get().getWorld()->getFallback();
float radius = esmLight->mData.mRadius; float radius = esmLight->mData.mRadius;
lightSource->setRadius(radius); lightSource->setRadius(radius);

@ -30,8 +30,8 @@
#include <components/terrain/terraingrid.hpp> #include <components/terrain/terraingrid.hpp>
#include <components/esm/loadcell.hpp> #include <components/esm/loadcell.hpp>
#include <components/fallback/fallback.hpp>
#include "../mwworld/fallback.hpp"
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "sky.hpp" #include "sky.hpp"
@ -126,7 +126,7 @@ namespace MWRender
}; };
RenderingManager::RenderingManager(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem, RenderingManager::RenderingManager(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem,
const MWWorld::Fallback* fallback, const std::string& resourcePath) const Fallback::Map* fallback, const std::string& resourcePath)
: mViewer(viewer) : mViewer(viewer)
, mRootNode(rootNode) , mRootNode(rootNode)
, mResourceSystem(resourceSystem) , mResourceSystem(resourceSystem)

@ -37,9 +37,9 @@ namespace Terrain
class World; class World;
} }
namespace MWWorld namespace Fallback
{ {
class Fallback; class Map;
} }
namespace MWRender namespace MWRender
@ -58,7 +58,7 @@ namespace MWRender
{ {
public: public:
RenderingManager(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem, RenderingManager(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem,
const MWWorld::Fallback* fallback, const std::string& resourcePath); const Fallback::Map* fallback, const std::string& resourcePath);
~RenderingManager(); ~RenderingManager();
MWRender::Objects& getObjects(); MWRender::Objects& getObjects();

@ -15,19 +15,18 @@
#include <components/nifosg/controller.hpp> #include <components/nifosg/controller.hpp>
#include <components/resource/texturemanager.hpp> #include <components/resource/texturemanager.hpp>
#include <components/resource/resourcesystem.hpp> #include <components/resource/resourcesystem.hpp>
#include <components/fallback/fallback.hpp>
#include "vismask.hpp" #include "vismask.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwworld/fallback.hpp"
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
namespace namespace
{ {
void createWaterRippleStateSet(Resource::ResourceSystem* resourceSystem, const MWWorld::Fallback* fallback, osg::Node* node) void createWaterRippleStateSet(Resource::ResourceSystem* resourceSystem, const Fallback::Map* fallback, osg::Node* node)
{ {
int rippleFrameCount = fallback->getFallbackInt("Water_RippleFrameCount"); int rippleFrameCount = fallback->getFallbackInt("Water_RippleFrameCount");
if (rippleFrameCount <= 0) if (rippleFrameCount <= 0)
@ -78,7 +77,7 @@ namespace
namespace MWRender namespace MWRender
{ {
RippleSimulation::RippleSimulation(osg::Group *parent, Resource::ResourceSystem* resourceSystem, const MWWorld::Fallback* fallback) RippleSimulation::RippleSimulation(osg::Group *parent, Resource::ResourceSystem* resourceSystem, const Fallback::Map* fallback)
: mParent(parent) : mParent(parent)
{ {
osg::ref_ptr<osg::Geode> geode (new osg::Geode); osg::ref_ptr<osg::Geode> geode (new osg::Geode);

@ -21,9 +21,9 @@ namespace Resource
class ResourceSystem; class ResourceSystem;
} }
namespace MWWorld namespace Fallback
{ {
class Fallback; class Map;
} }
namespace MWRender namespace MWRender
@ -40,7 +40,7 @@ namespace MWRender
class RippleSimulation class RippleSimulation
{ {
public: public:
RippleSimulation(osg::Group* parent, Resource::ResourceSystem* resourceSystem, const MWWorld::Fallback* fallback); RippleSimulation(osg::Group* parent, Resource::ResourceSystem* resourceSystem, const Fallback::Map* fallback);
~RippleSimulation(); ~RippleSimulation();
/// @param dt Time since the last frame /// @param dt Time since the last frame

@ -33,6 +33,7 @@
#include <components/resource/texturemanager.hpp> #include <components/resource/texturemanager.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
#include <components/fallback/fallback.hpp>
#include <components/sceneutil/util.hpp> #include <components/sceneutil/util.hpp>
#include <components/sceneutil/statesetupdater.hpp> #include <components/sceneutil/statesetupdater.hpp>
@ -42,8 +43,6 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwworld/fallback.hpp"
#include "vismask.hpp" #include "vismask.hpp"
#include "renderbin.hpp" #include "renderbin.hpp"
@ -827,7 +826,7 @@ private:
, mTimeOfDayFade(1.f) , mTimeOfDayFade(1.f)
, mGlareView(1.f) , mGlareView(1.f)
{ {
const MWWorld::Fallback* fallback = MWBase::Environment::get().getWorld()->getFallback(); const Fallback::Map* fallback = MWBase::Environment::get().getWorld()->getFallback();
mColor = fallback->getFallbackColour("Weather_Sun_Glare_Fader_Color"); mColor = fallback->getFallbackColour("Weather_Sun_Glare_Fader_Color");
mSunGlareFaderMax = fallback->getFallbackFloat("Weather_Sun_Glare_Fader_Max"); mSunGlareFaderMax = fallback->getFallbackFloat("Weather_Sun_Glare_Fader_Max");
mSunGlareFaderAngleMax = fallback->getFallbackFloat("Weather_Sun_Glare_Fader_Angle_Max"); mSunGlareFaderAngleMax = fallback->getFallbackFloat("Weather_Sun_Glare_Fader_Angle_Max");
@ -1161,7 +1160,7 @@ void SkyManager::create()
mSun.reset(new Sun(mEarlyRenderBinRoot, *mSceneManager->getTextureManager())); mSun.reset(new Sun(mEarlyRenderBinRoot, *mSceneManager->getTextureManager()));
const MWWorld::Fallback* fallback=MWBase::Environment::get().getWorld()->getFallback(); const Fallback::Map* fallback=MWBase::Environment::get().getWorld()->getFallback();
mMasser.reset(new Moon(mEarlyRenderBinRoot, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Masser_Size")/125, Moon::Type_Masser)); mMasser.reset(new Moon(mEarlyRenderBinRoot, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Masser_Size")/125, Moon::Type_Masser));
mSecunda.reset(new Moon(mEarlyRenderBinRoot, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Secunda_Size")/125, Moon::Type_Secunda)); mSecunda.reset(new Moon(mEarlyRenderBinRoot, *mSceneManager->getTextureManager(), fallback->getFallbackFloat("Moons_Secunda_Size")/125, Moon::Type_Secunda));

@ -34,8 +34,9 @@
#include <components/esm/loadcell.hpp> #include <components/esm/loadcell.hpp>
#include <components/fallback/fallback.hpp>
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwworld/fallback.hpp"
#include "vismask.hpp" #include "vismask.hpp"
#include "ripplesimulation.hpp" #include "ripplesimulation.hpp"
@ -457,7 +458,7 @@ public:
}; };
Water::Water(osg::Group *parent, osg::Group* sceneRoot, Resource::ResourceSystem *resourceSystem, osgUtil::IncrementalCompileOperation *ico, Water::Water(osg::Group *parent, osg::Group* sceneRoot, Resource::ResourceSystem *resourceSystem, osgUtil::IncrementalCompileOperation *ico,
const MWWorld::Fallback* fallback, const std::string& resourcePath) const Fallback::Map* fallback, const std::string& resourcePath)
: mParent(parent) : mParent(parent)
, mSceneRoot(sceneRoot) , mSceneRoot(sceneRoot)
, mResourceSystem(resourceSystem) , mResourceSystem(resourceSystem)

@ -28,11 +28,15 @@ namespace Resource
namespace MWWorld namespace MWWorld
{ {
class Fallback;
class CellStore; class CellStore;
class Ptr; class Ptr;
} }
namespace Fallback
{
class Map;
}
namespace MWRender namespace MWRender
{ {
@ -50,7 +54,7 @@ namespace MWRender
osg::ref_ptr<osg::PositionAttitudeTransform> mWaterNode; osg::ref_ptr<osg::PositionAttitudeTransform> mWaterNode;
osg::ref_ptr<osg::Geode> mWaterGeode; osg::ref_ptr<osg::Geode> mWaterGeode;
Resource::ResourceSystem* mResourceSystem; Resource::ResourceSystem* mResourceSystem;
const MWWorld::Fallback* mFallback; const Fallback::Map* mFallback;
osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation; osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation;
std::auto_ptr<RippleSimulation> mSimulation; std::auto_ptr<RippleSimulation> mSimulation;
@ -77,7 +81,7 @@ namespace MWRender
public: public:
Water(osg::Group* parent, osg::Group* sceneRoot, Water(osg::Group* parent, osg::Group* sceneRoot,
Resource::ResourceSystem* resourceSystem, osgUtil::IncrementalCompileOperation* ico, const MWWorld::Fallback* fallback, Resource::ResourceSystem* resourceSystem, osgUtil::IncrementalCompileOperation* ico, const Fallback::Map* fallback,
const std::string& resourcePath); const std::string& resourcePath);
~Water(); ~Water();

@ -6,6 +6,7 @@
#include <components/esm/esmwriter.hpp> #include <components/esm/esmwriter.hpp>
#include <components/esm/savedgame.hpp> #include <components/esm/savedgame.hpp>
#include <components/esm/weatherstate.hpp> #include <components/esm/weatherstate.hpp>
#include <components/fallback/fallback.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
@ -20,7 +21,6 @@
#include "player.hpp" #include "player.hpp"
#include "esmstore.hpp" #include "esmstore.hpp"
#include "fallback.hpp"
#include "cellstore.hpp" #include "cellstore.hpp"
#include <cmath> #include <cmath>
@ -100,7 +100,7 @@ template class TimeOfDayInterpolator<float>;
template class TimeOfDayInterpolator<osg::Vec4f>; template class TimeOfDayInterpolator<osg::Vec4f>;
Weather::Weather(const std::string& name, Weather::Weather(const std::string& name,
const MWWorld::Fallback& fallback, const Fallback::Map& fallback,
float stormWindSpeed, float stormWindSpeed,
float rainSpeed, float rainSpeed,
const std::string& particleEffect) const std::string& particleEffect)
@ -327,7 +327,7 @@ void RegionWeather::chooseNewWeather()
mWeather = i; mWeather = i;
} }
MoonModel::MoonModel(const std::string& name, const MWWorld::Fallback& fallback) MoonModel::MoonModel(const std::string& name, const Fallback::Map& fallback)
: mFadeInStart(fallback.getFallbackFloat("Moons_" + name + "_Fade_In_Start")) : mFadeInStart(fallback.getFallbackFloat("Moons_" + name + "_Fade_In_Start"))
, mFadeInFinish(fallback.getFallbackFloat("Moons_" + name + "_Fade_In_Finish")) , mFadeInFinish(fallback.getFallbackFloat("Moons_" + name + "_Fade_In_Finish"))
, mFadeOutStart(fallback.getFallbackFloat("Moons_" + name + "_Fade_Out_Start")) , mFadeOutStart(fallback.getFallbackFloat("Moons_" + name + "_Fade_Out_Start"))
@ -496,7 +496,7 @@ inline float MoonModel::earlyMoonShadowAlpha(float angle) const
return 0.0f; return 0.0f;
} }
WeatherManager::WeatherManager(MWRender::RenderingManager& rendering, const MWWorld::Fallback& fallback, MWWorld::ESMStore& store) WeatherManager::WeatherManager(MWRender::RenderingManager& rendering, const Fallback::Map& fallback, MWWorld::ESMStore& store)
: mStore(store) : mStore(store)
, mRendering(rendering) , mRendering(rendering)
, mSunriseTime(fallback.getFallbackFloat("Weather_Sunrise_Time")) , mSunriseTime(fallback.getFallbackFloat("Weather_Sunrise_Time"))
@ -862,7 +862,7 @@ void WeatherManager::clear()
} }
inline void WeatherManager::addWeather(const std::string& name, inline void WeatherManager::addWeather(const std::string& name,
const MWWorld::Fallback& fallback, const Fallback::Map& fallback,
const std::string& particleEffect) const std::string& particleEffect)
{ {
static const float fStromWindSpeed = mStore.get<ESM::GameSetting>().find("fStromWindSpeed")->getFloat(); static const float fStromWindSpeed = mStore.get<ESM::GameSetting>().find("fStromWindSpeed")->getFloat();

@ -29,9 +29,13 @@ namespace Loading
class Listener; class Listener;
} }
namespace Fallback
{
class Map;
}
namespace MWWorld namespace MWWorld
{ {
class Fallback;
class TimeStamp; class TimeStamp;
@ -66,7 +70,7 @@ namespace MWWorld
{ {
public: public:
Weather(const std::string& name, Weather(const std::string& name,
const MWWorld::Fallback& fallback, const Fallback::Map& fallback,
float stormWindSpeed, float stormWindSpeed,
float rainSpeed, float rainSpeed,
const std::string& particleEffect); const std::string& particleEffect);
@ -172,7 +176,7 @@ namespace MWWorld
class MoonModel class MoonModel
{ {
public: public:
MoonModel(const std::string& name, const MWWorld::Fallback& fallback); MoonModel(const std::string& name, const Fallback::Map& fallback);
MWRender::MoonState calculateState(const TimeStamp& gameTime) const; MWRender::MoonState calculateState(const TimeStamp& gameTime) const;
@ -203,7 +207,7 @@ namespace MWWorld
public: public:
// Have to pass fallback and Store, can't use singleton since World isn't fully constructed yet at the time // Have to pass fallback and Store, can't use singleton since World isn't fully constructed yet at the time
WeatherManager(MWRender::RenderingManager& rendering, WeatherManager(MWRender::RenderingManager& rendering,
const MWWorld::Fallback& fallback, const Fallback::Map& fallback,
MWWorld::ESMStore& store); MWWorld::ESMStore& store);
~WeatherManager(); ~WeatherManager();
@ -288,7 +292,7 @@ namespace MWWorld
std::string mPlayingSoundID; std::string mPlayingSoundID;
void addWeather(const std::string& name, void addWeather(const std::string& name,
const MWWorld::Fallback& fallback, const Fallback::Map& fallback,
const std::string& particleEffect = ""); const std::string& particleEffect = "");
void importRegions(); void importRegions();

@ -511,7 +511,7 @@ namespace MWWorld
return 0; return 0;
} }
const MWWorld::Fallback *World::getFallback() const const Fallback::Map *World::getFallback() const
{ {
return &mFallback; return &mFallback;
} }

@ -5,21 +5,20 @@
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <components/settings/settings.hpp>
#include <components/fallback/fallback.hpp>
#include "../mwbase/world.hpp"
#include "ptr.hpp" #include "ptr.hpp"
#include "scene.hpp" #include "scene.hpp"
#include "esmstore.hpp" #include "esmstore.hpp"
#include "cells.hpp" #include "cells.hpp"
#include "localscripts.hpp" #include "localscripts.hpp"
#include "timestamp.hpp" #include "timestamp.hpp"
#include "fallback.hpp"
#include "globals.hpp" #include "globals.hpp"
#include "../mwbase/world.hpp"
#include "contentloader.hpp" #include "contentloader.hpp"
#include <components/settings/settings.hpp>
namespace osg namespace osg
{ {
class Group; class Group;
@ -71,7 +70,7 @@ namespace MWWorld
{ {
Resource::ResourceSystem* mResourceSystem; Resource::ResourceSystem* mResourceSystem;
MWWorld::Fallback mFallback; Fallback::Map mFallback;
MWRender::RenderingManager* mRendering; MWRender::RenderingManager* mRendering;
MWWorld::WeatherManager* mWeatherManager; MWWorld::WeatherManager* mWeatherManager;
@ -210,7 +209,7 @@ namespace MWWorld
virtual void adjustSky(); virtual void adjustSky();
virtual const Fallback *getFallback() const; virtual const Fallback::Map *getFallback() const;
virtual Player& getPlayer(); virtual Player& getPlayer();
virtual MWWorld::Ptr getPlayerPtr(); virtual MWWorld::Ptr getPlayerPtr();

@ -138,6 +138,10 @@ add_component_dir (version
version version
) )
add_component_dir (fallback
fallback validate
)
set (ESM_UI ${CMAKE_SOURCE_DIR}/files/ui/contentselector.ui set (ESM_UI ${CMAKE_SOURCE_DIR}/files/ui/contentselector.ui
) )

@ -2,12 +2,12 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
namespace MWWorld namespace Fallback
{ {
Fallback::Fallback(const std::map<std::string,std::string>& fallback):mFallbackMap(fallback) Map::Map(const std::map<std::string,std::string>& fallback):mFallbackMap(fallback)
{} {}
std::string Fallback::getFallbackString(const std::string& fall) const std::string Map::getFallbackString(const std::string& fall) const
{ {
std::map<std::string,std::string>::const_iterator it; std::map<std::string,std::string>::const_iterator it;
if((it = mFallbackMap.find(fall)) == mFallbackMap.end()) if((it = mFallbackMap.find(fall)) == mFallbackMap.end())
@ -16,7 +16,7 @@ namespace MWWorld
} }
return it->second; return it->second;
} }
float Fallback::getFallbackFloat(const std::string& fall) const float Map::getFallbackFloat(const std::string& fall) const
{ {
std::string fallback=getFallbackString(fall); std::string fallback=getFallbackString(fall);
if(fallback.empty()) if(fallback.empty())
@ -24,7 +24,7 @@ namespace MWWorld
else else
return boost::lexical_cast<float>(fallback); return boost::lexical_cast<float>(fallback);
} }
int Fallback::getFallbackInt(const std::string& fall) const int Map::getFallbackInt(const std::string& fall) const
{ {
std::string fallback=getFallbackString(fall); std::string fallback=getFallbackString(fall);
if(fallback.empty()) if(fallback.empty())
@ -33,7 +33,7 @@ namespace MWWorld
return boost::lexical_cast<int>(fallback); return boost::lexical_cast<int>(fallback);
} }
bool Fallback::getFallbackBool(const std::string& fall) const bool Map::getFallbackBool(const std::string& fall) const
{ {
std::string fallback=getFallbackString(fall); std::string fallback=getFallbackString(fall);
if(fallback.empty()) if(fallback.empty())
@ -41,7 +41,7 @@ namespace MWWorld
else else
return boost::lexical_cast<bool>(fallback); return boost::lexical_cast<bool>(fallback);
} }
osg::Vec4f Fallback::getFallbackColour(const std::string& fall) const osg::Vec4f Map::getFallbackColour(const std::string& fall) const
{ {
std::string sum=getFallbackString(fall); std::string sum=getFallbackString(fall);
if(sum.empty()) if(sum.empty())

@ -1,18 +1,19 @@
#ifndef GAME_MWWORLD_FALLBACK_H #ifndef OPENMW_COMPONENTS_FALLBACK_H
#define GAME_MWWORLD_FALLBACK_H #define OPENMW_COMPONENTS_FALLBACK_H
#include <map> #include <map>
#include <string> #include <string>
#include <osg/Vec4f> #include <osg/Vec4f>
namespace MWWorld namespace Fallback
{ {
class Fallback /// @brief contains settings imported from the Morrowind INI file.
class Map
{ {
const std::map<std::string,std::string> mFallbackMap; const std::map<std::string,std::string> mFallbackMap;
public: public:
Fallback(const std::map<std::string,std::string>& fallback); Map(const std::map<std::string,std::string>& fallback);
std::string getFallbackString(const std::string& fall) const; std::string getFallbackString(const std::string& fall) const;
float getFallbackFloat(const std::string& fall) const; float getFallbackFloat(const std::string& fall) const;
int getFallbackInt(const std::string& fall) const; int getFallbackInt(const std::string& fall) const;

@ -0,0 +1,48 @@
#ifndef OPENMW_COMPONENTS_FALLBACK_VALIDATE_H
#define OPENMW_COMPONENTS_FALLBACK_VALIDATE_H
#include <boost/program_options.hpp>
// Parses and validates a fallback map from boost program_options.
// Note: for boost to pick up the validate function, you need to pull in the namespace e.g.
// by using namespace Fallback;
namespace Fallback
{
struct FallbackMap {
std::map<std::string,std::string> mMap;
};
void validate(boost::any &v, std::vector<std::string> const &tokens, FallbackMap*, int)
{
if(v.empty())
{
v = boost::any(FallbackMap());
}
FallbackMap *map = boost::any_cast<FallbackMap>(&v);
for(std::vector<std::string>::const_iterator it=tokens.begin(); it != tokens.end(); ++it)
{
int sep = it->find(",");
if(sep < 1 || sep == (int)it->length()-1)
#if (BOOST_VERSION < 104200)
throw boost::program_options::validation_error("invalid value");
#else
throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value);
#endif
std::string key(it->substr(0,sep));
std::string value(it->substr(sep+1));
if(map->mMap.find(key) == map->mMap.end())
{
map->mMap.insert(std::make_pair (key,value));
}
}
}
}
#endif
Loading…
Cancel
Save