1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-06 00:55:50 +00:00

Fallback system rewritten, added light fallbacks

This commit is contained in:
Glorf 2013-03-15 10:17:30 +01:00
parent ef72894b81
commit 521bebd2f4
12 changed files with 163 additions and 141 deletions

View File

@ -53,7 +53,7 @@ add_openmw_dir (mwworld
containerstore actiontalk actiontake manualref player cellfunctors failedaction
cells localscripts customdata weather inventorystore ptr actionopen actionread
actionequip timestamp actionalchemy cellstore actionapply actioneat
esmstore store recordcmp
esmstore store recordcmp fallback
)
add_openmw_dir (mwclass

View File

@ -103,12 +103,8 @@ namespace MWBase
virtual void getTriangleBatchCount(unsigned int &triangles, unsigned int &batches) = 0;
virtual void setFallbackValues (const std::map<std::string, std::string>& fallbackMap) = 0;
virtual std::string getFallback (const std::string& key) const = 0;
virtual std::string getFallback (const std::string& key, const std::string& def) const = 0;
virtual MWWorld::Player& getPlayer() = 0;
virtual const MWWorld::ESMStore& getStore() const = 0;

View File

@ -16,16 +16,31 @@
#include "renderconst.hpp"
using namespace MWRender;
float Objects::lightLinearValue()
{
return mFallback->getFallbackFloat("LightAttenuation_LinearValue");
}
float Objects::lightLinearRadiusMult()
{
return mFallback->getFallbackFloat("LightAttenuation_LinearRadiusMult");
}
float Objects::lightQuadraticValue()
{
return mFallback->getFallbackFloat("LightAttenuation_QuadraticValue");
}
float Objects::lightQuadraticRadiusMult()
{
return mFallback->getFallbackFloat("LightAttenuation_QuadraticRadiusMult");
}
/// \todo Replace these, once fallback values from the ini file are available.
float Objects::lightLinearValue = 3;
float Objects::lightLinearRadiusMult = 1;
float Objects::lightQuadraticValue = 16;
float Objects::lightQuadraticRadiusMult = 1;
bool Objects::lightOutQuadInLin = true;
bool Objects::lightQuadratic = false;
bool Objects::lightOutQuadInLin()
{
return mFallback->getFallbackBool("LightAttenuation_OutQuadInLin");
}
bool Objects::lightQuadratic()
{
return mFallback->getFallbackBool("LightAttenuation_UseQuadratic");
}
int Objects::uniqueID = 0;
@ -269,14 +284,14 @@ void Objects::insertLight (const MWWorld::Ptr& ptr, Ogre::Entity* skelBase, Ogre
if (!quadratic)
{
float r = radius * lightLinearRadiusMult;
float attenuation = lightLinearValue / r;
float r = radius * lightLinearRadiusMult();
float attenuation = lightLinearValue() / r;
light->setAttenuation(r*10, 0, attenuation, 0);
}
else
{
float r = radius * lightQuadraticRadiusMult;
float attenuation = lightQuadraticValue / pow(r, 2);
float r = radius * lightQuadraticRadiusMult();
float attenuation = lightQuadraticValue() / pow(r, 2);
light->setAttenuation(r*10, 0, 0, attenuation);
}

View File

@ -5,6 +5,7 @@
#include <OgreAxisAlignedBox.h>
#include <openengine/ogre/renderer.hpp>
#include "../mwworld/fallback.hpp"
namespace MWWorld
{
@ -56,21 +57,21 @@ class Objects{
Ogre::SceneNode* mRootNode;
bool mIsStatic;
static int uniqueID;
MWWorld::Fallback* mFallback;
float lightLinearValue();
float lightLinearRadiusMult();
static float lightLinearValue;
static float lightLinearRadiusMult;
bool lightQuadratic();
float lightQuadraticValue();
float lightQuadraticRadiusMult();
static bool lightQuadratic;
static float lightQuadraticValue;
static float lightQuadraticRadiusMult;
static bool lightOutQuadInLin;
bool lightOutQuadInLin();
void clearSceneNode (Ogre::SceneNode *node);
///< Remove all movable objects from \a node.
public:
Objects(OEngine::Render::OgreRenderer& renderer): mRenderer (renderer), mIsStatic(false) {}
Objects(OEngine::Render::OgreRenderer& renderer, MWWorld::Fallback* fallback): mRenderer (renderer), mIsStatic(false), mFallback(fallback) {}
~Objects(){}
void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_);
void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh, bool light=false);

View File

@ -48,9 +48,10 @@ using namespace Ogre;
namespace MWRender {
RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir,
const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine)
const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine,MWWorld::Fallback* fallback)
: mRendering(_rend)
, mObjects(mRendering)
, mFallback(fallback)
, mObjects(mRendering,mFallback)
, mActors(mRendering, this)
, mAmbientMode(0)
, mSunEnabled(0)

View File

@ -60,7 +60,7 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList
public:
RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir,
const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine);
const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine,MWWorld::Fallback* fallback);
virtual ~RenderingManager();
void togglePOV() {
@ -220,6 +220,8 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList
bool mSunEnabled;
MWWorld::Fallback* mFallback;
SkyManager* mSkyManager;
OcclusionQuery* mOcclusionQuery;

View File

@ -0,0 +1,46 @@
#include "fallback.hpp"
#include "boost/lexical_cast.hpp"
namespace MWWorld
{
std::string Fallback::getFallbackString(const std::string& fall) const
{
std::map<std::string,std::string>::const_iterator it;
if((it = mFallbackMap.find(fall)) == mFallbackMap.end())
{
return "";
}
return it->second;
}
float Fallback::getFallbackFloat(const std::string& fall) const
{
std::string fallback=getFallbackString(fall);
if(fallback=="")
return 0;
else
return boost::lexical_cast<float>(fallback);
}
bool Fallback::getFallbackBool(const std::string& fall) const
{
std::string fallback=getFallbackString(fall);
if(fallback=="")
return false;
else
return boost::lexical_cast<bool>(fallback);
}
Ogre::ColourValue Fallback::getFallbackColour(const std::string& fall) const
{
std::string sum=getFallbackString(fall);
if(sum=="")
return Ogre::ColourValue(0,0,0);
else
{
std::string ret[3];
unsigned int j=0;
for(unsigned int i=0;i<sum.length();i++){
if(sum[i]==',') j++;
else ret[j]+=sum[i];
}
return Ogre::ColourValue(boost::lexical_cast<int>(ret[0])/255.f,boost::lexical_cast<int>(ret[1])/255.f,boost::lexical_cast<int>(ret[2])/255.f);
}
}
}

View File

@ -0,0 +1,17 @@
#ifndef GAME_MWWORLD_FALLBACK_H
#define GAME_MWWORLD_FALLBACK_H
#include <OgreColourValue.h>
namespace MWWorld
{
class Fallback
{
const std::map<std::string,std::string> mFallbackMap;
public:
Fallback(const std::map<std::string,std::string> fallback):mFallbackMap(fallback){};
std::string getFallbackString(const std::string& fall) const;
float getFallbackFloat(const std::string& fall) const;
bool getFallbackBool(const std::string& fall) const;
Ogre::ColourValue getFallbackColour(const std::string& fall) const;
};
}
#endif

View File

@ -4,7 +4,6 @@
#include <cstdlib>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwbase/soundmanager.hpp"
@ -19,100 +18,68 @@ using namespace MWWorld;
using namespace MWSound;
#define lerp(x, y) (x * (1-factor) + y * factor)
std::string WeatherManager::getFallback (const std::string& key) const
{
std::map<std::string,std::string>::const_iterator it;
if((it = mFallback.find(key)) == mFallback.end())
{
return "";
}
return it->second;
}
std::string WeatherManager::getFallbackString(const std::string& fall) const
{
return getFallback(fall);
}
float WeatherManager::getFallbackFloat(const std::string& fall) const
{
std::string fallback=getFallbackString(fall);
return boost::lexical_cast<float>(fallback);
}
ColourValue WeatherManager::getFallbackColour(const std::string& fall) const
{
std::string sum;
std::string ret[3];
sum=getFallback(fall);
unsigned int j=0;
for(unsigned int i=0;i<sum.length();i++){
if(sum[i]==',') j++;
else ret[j]+=sum[i];
}
return ColourValue(boost::lexical_cast<int>(ret[0])/255.f,boost::lexical_cast<int>(ret[1])/255.f,boost::lexical_cast<int>(ret[2])/255.f);
}
void WeatherManager::setFallbackWeather(Weather& weather,const std::string& name)
{
std::string upper=name;
upper[0]=toupper(name[0]);
weather.mCloudsMaximumPercent = getFallbackFloat("Weather_"+upper+"_Clouds_Maximum_Percent");
weather.mTransitionDelta = getFallbackFloat("Weather_"+upper+"_Transition_Delta");
weather.mSkySunriseColor=getFallbackColour("Weather_"+upper+"_Sky_Sunrise_Color");
weather.mSkyDayColor = getFallbackColour("Weather_"+upper+"_Sky_Day_Color");
weather.mSkySunsetColor = getFallbackColour("Weather_"+upper+"_Sky_Sunset_Color");
weather.mSkyNightColor = getFallbackColour("Weather_"+upper+"_Sky_Night_Color");
weather.mFogSunriseColor = getFallbackColour("Weather_"+upper+"_Fog_Sunrise_Color");
weather.mFogDayColor = getFallbackColour("Weather_"+upper+"_Fog_Day_Color");
weather.mFogSunsetColor = getFallbackColour("Weather_"+upper+"_Fog_Sunset_Color");
weather.mFogNightColor = getFallbackColour("Weather_"+upper+"_Fog_Night_Color");
weather.mAmbientSunriseColor = getFallbackColour("Weather_"+upper+"_Ambient_Sunrise_Color");
weather.mAmbientDayColor = getFallbackColour("Weather_"+upper+"_Ambient_Day_Color");
weather.mAmbientSunsetColor = getFallbackColour("Weather_"+upper+"_Ambient_Sunset_Color");
weather.mAmbientNightColor = getFallbackColour("Weather_"+upper+"_Ambient_Night_Color");
weather.mSunSunriseColor = getFallbackColour("Weather_"+upper+"_Sun_Sunrise_Color");
weather.mSunDayColor = getFallbackColour("Weather_"+upper+"_Sun_Day_Color");
weather.mSunSunsetColor = getFallbackColour("Weather_"+upper+"_Sun_Sunset_Color");
weather.mSunNightColor = getFallbackColour("Weather_"+upper+"_Sun_Night_Color");
weather.mSunDiscSunsetColor = getFallbackColour("Weather_"+upper+"_Sun_Disc_Sunset_Color");
weather.mLandFogDayDepth = getFallbackFloat("Weather_"+upper+"_Land_Fog_Day_Depth");
weather.mLandFogNightDepth = getFallbackFloat("Weather_"+upper+"_Land_Fog_Night_Depth");
weather.mWindSpeed = getFallbackFloat("Weather_"+upper+"_Wind_Speed");
weather.mCloudSpeed = getFallbackFloat("Weather_"+upper+"_Cloud_Speed");
weather.mGlareView = getFallbackFloat("Weather_"+upper+"_Glare_View");
std::string upper=name;
upper[0]=toupper(name[0]);
weather.mCloudsMaximumPercent = mFallback->getFallbackFloat("Weather_"+upper+"_Clouds_Maximum_Percent");
weather.mTransitionDelta = mFallback->getFallbackFloat("Weather_"+upper+"_Transition_Delta");
weather.mSkySunriseColor=mFallback->getFallbackColour("Weather_"+upper+"_Sky_Sunrise_Color");
weather.mSkyDayColor = mFallback->getFallbackColour("Weather_"+upper+"_Sky_Day_Color");
weather.mSkySunsetColor = mFallback->getFallbackColour("Weather_"+upper+"_Sky_Sunset_Color");
weather.mSkyNightColor = mFallback->getFallbackColour("Weather_"+upper+"_Sky_Night_Color");
weather.mFogSunriseColor = mFallback->getFallbackColour("Weather_"+upper+"_Fog_Sunrise_Color");
weather.mFogDayColor = mFallback->getFallbackColour("Weather_"+upper+"_Fog_Day_Color");
weather.mFogSunsetColor = mFallback->getFallbackColour("Weather_"+upper+"_Fog_Sunset_Color");
weather.mFogNightColor = mFallback->getFallbackColour("Weather_"+upper+"_Fog_Night_Color");
weather.mAmbientSunriseColor = mFallback->getFallbackColour("Weather_"+upper+"_Ambient_Sunrise_Color");
weather.mAmbientDayColor = mFallback->getFallbackColour("Weather_"+upper+"_Ambient_Day_Color");
weather.mAmbientSunsetColor = mFallback->getFallbackColour("Weather_"+upper+"_Ambient_Sunset_Color");
weather.mAmbientNightColor = mFallback->getFallbackColour("Weather_"+upper+"_Ambient_Night_Color");
weather.mSunSunriseColor = mFallback->getFallbackColour("Weather_"+upper+"_Sun_Sunrise_Color");
weather.mSunDayColor = mFallback->getFallbackColour("Weather_"+upper+"_Sun_Day_Color");
weather.mSunSunsetColor = mFallback->getFallbackColour("Weather_"+upper+"_Sun_Sunset_Color");
weather.mSunNightColor = mFallback->getFallbackColour("Weather_"+upper+"_Sun_Night_Color");
weather.mSunDiscSunsetColor = mFallback->getFallbackColour("Weather_"+upper+"_Sun_Disc_Sunset_Color");
weather.mLandFogDayDepth = mFallback->getFallbackFloat("Weather_"+upper+"_Land_Fog_Day_Depth");
weather.mLandFogNightDepth = mFallback->getFallbackFloat("Weather_"+upper+"_Land_Fog_Night_Depth");
weather.mWindSpeed = mFallback->getFallbackFloat("Weather_"+upper+"_Wind_Speed");
weather.mCloudSpeed = mFallback->getFallbackFloat("Weather_"+upper+"_Cloud_Speed");
weather.mGlareView = mFallback->getFallbackFloat("Weather_"+upper+"_Glare_View");
mWeatherSettings[name] = weather;
}
WeatherManager::WeatherManager(MWRender::RenderingManager* rendering,const std::map<std::string,std::string>& fallbackMap) :
WeatherManager::WeatherManager(MWRender::RenderingManager* rendering,MWWorld::Fallback* fallback) :
mHour(14), mCurrentWeather("clear"), mFirstUpdate(true), mWeatherUpdateTime(0),
mThunderFlash(0), mThunderChance(0), mThunderChanceNeeded(50), mThunderSoundDelay(0),
mRemainingTransitionTime(0), mMonth(0), mDay(0),
mTimePassed(0), mFallback(fallbackMap)
mTimePassed(0), mFallback(fallback)
{
mRendering = rendering;
//Globals
mThunderSoundID0 = getFallbackString("Weather_Thunderstorm_Thunder_Sound_ID_0");
mThunderSoundID1 = getFallbackString("Weather_Thunderstorm_Thunder_Sound_ID_1");
mThunderSoundID2 = getFallbackString("Weather_Thunderstorm_Thunder_Sound_ID_2");
mThunderSoundID3 = getFallbackString("Weather_Thunderstorm_Thunder_Sound_ID_3");
mSunriseTime = getFallbackFloat("Weather_Sunrise_Time");
mSunsetTime = getFallbackFloat("Weather_Sunset_Time");
mSunriseDuration = getFallbackFloat("Weather_Sunrise_Duration");
mSunsetDuration = getFallbackFloat("Weather_Sunset_Duration");
mWeatherUpdateTime = getFallbackFloat("Weather_Hours_Between_Weather_Changes");
mThunderFrequency = getFallbackFloat("Weather_Thunderstorm_Thunder_Frequency");
mThunderThreshold = getFallbackFloat("Weather_Thunderstorm_Thunder_Threshold");
mThunderSoundDelay = 0.25;
//Weather
Weather clear;
clear.mCloudTexture = "tx_sky_clear.dds";
setFallbackWeather(clear,"clear");
//Globals
mThunderSoundID0 = mFallback->getFallbackString("Weather_Thunderstorm_Thunder_Sound_ID_0");
mThunderSoundID1 = mFallback->getFallbackString("Weather_Thunderstorm_Thunder_Sound_ID_1");
mThunderSoundID2 = mFallback->getFallbackString("Weather_Thunderstorm_Thunder_Sound_ID_2");
mThunderSoundID3 = mFallback->getFallbackString("Weather_Thunderstorm_Thunder_Sound_ID_3");
mSunriseTime = mFallback->getFallbackFloat("Weather_Sunrise_Time");
mSunsetTime = mFallback->getFallbackFloat("Weather_Sunset_Time");
mSunriseDuration = mFallback->getFallbackFloat("Weather_Sunrise_Duration");
mSunsetDuration = mFallback->getFallbackFloat("Weather_Sunset_Duration");
mWeatherUpdateTime = mFallback->getFallbackFloat("Weather_Hours_Between_Weather_Changes");
mThunderFrequency = mFallback->getFallbackFloat("Weather_Thunderstorm_Thunder_Frequency");
mThunderThreshold = mFallback->getFallbackFloat("Weather_Thunderstorm_Thunder_Threshold");
mThunderSoundDelay = 0.25;
//Weather
Weather clear;
clear.mCloudTexture = "tx_sky_clear.dds";
setFallbackWeather(clear,"clear");
Weather cloudy;
cloudy.mCloudTexture = "tx_sky_cloudy.dds";
cloudy.mCloudTexture = "tx_sky_cloudy.dds";
setFallbackWeather(cloudy,"cloudy");
Weather foggy;
foggy.mCloudTexture = "tx_sky_foggy.dds";
foggy.mCloudTexture = "tx_sky_foggy.dds";
setFallbackWeather(foggy,"foggy");
Weather thunderstorm;

View File

@ -3,7 +3,7 @@
#include <OgreString.h>
#include <OgreColourValue.h>
#include "fallback.hpp"
namespace MWRender
{
class RenderingManager;
@ -112,7 +112,7 @@ namespace MWWorld
class WeatherManager
{
public:
WeatherManager(MWRender::RenderingManager*,const std::map<std::string,std::string>& fallbackMap);
WeatherManager(MWRender::RenderingManager*,MWWorld::Fallback* fallback);
/**
* Change the weather in the specified region
@ -141,11 +141,7 @@ namespace MWWorld
private:
float mHour;
int mDay, mMonth;
std::map<std::string,std::string> mFallback;
std::string getFallback (const std::string& key) const;
std::string getFallbackString(const std::string& fall) const;
float getFallbackFloat(const std::string& fall) const;
Ogre::ColourValue getFallbackColour(const std::string& fall) const;
MWWorld::Fallback* mFallback;
void setFallbackWeather(Weather& weather,const std::string& name);
MWRender::RenderingManager* mRendering;

View File

@ -154,24 +154,9 @@ namespace MWWorld
mRendering->skyDisable();
}
void World::setFallbackValues (const std::map<std::string,std::string>& fallbackMap)
{
mFallback = fallbackMap;
}
std::string World::getFallback (const std::string& key) const
{
return getFallback(key, "");
}
std::string World::getFallback (const std::string& key, const std::string& def) const
{
std::map<std::string,std::string>::const_iterator it;
if((it = mFallback.find(key)) == mFallback.end())
{
return def;
}
return it->second;
return mFallback.getFallbackString(key);
}
World::World (OEngine::Render::OgreRenderer& renderer,
@ -181,17 +166,16 @@ namespace MWWorld
ToUTF8::Utf8Encoder* encoder, const std::map<std::string,std::string>& fallbackMap, int mActivationDistanceOverride)
: mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0),
mSky (true), mCells (mStore, mEsm),
mNumFacing(0), mActivationDistanceOverride (mActivationDistanceOverride),
mFallback (fallbackMap)
mNumFacing(0), mActivationDistanceOverride (mActivationDistanceOverride),mFallback(fallbackMap)
{
mPhysics = new PhysicsSystem(renderer);
mPhysEngine = mPhysics->getEngine();
mRendering = new MWRender::RenderingManager(renderer, resDir, cacheDir, mPhysEngine);
mRendering = new MWRender::RenderingManager(renderer, resDir, cacheDir, mPhysEngine,&mFallback);
mPhysEngine->setSceneManager(renderer.getScene());
mWeatherManager = new MWWorld::WeatherManager(mRendering,fallbackMap);
mWeatherManager = new MWWorld::WeatherManager(mRendering,&mFallback);
int idx = 0;
// NOTE: We might need to reserve one more for the running game / save.

View File

@ -10,6 +10,7 @@
#include "cells.hpp"
#include "localscripts.hpp"
#include "timestamp.hpp"
#include "fallback.hpp"
#include "../mwbase/world.hpp"
@ -49,6 +50,7 @@ namespace MWWorld
class World : public MWBase::World
{
MWWorld::Fallback mFallback;
MWRender::RenderingManager* mRendering;
MWWorld::WeatherManager* mWeatherManager;
@ -82,7 +84,6 @@ namespace MWWorld
float mFaced1Distance;
float mFaced2Distance;
int mNumFacing;
std::map<std::string,std::string> mFallback;
unsigned long lastTick;
Ogre::Timer mTimer;
@ -132,12 +133,8 @@ namespace MWWorld
virtual void getTriangleBatchCount(unsigned int &triangles, unsigned int &batches);
virtual void setFallbackValues (const std::map<std::string,std::string>& fallbackMap);
virtual std::string getFallback (const std::string& key) const;
virtual std::string getFallback (const std::string& key, const std::string& def) const;
virtual Player& getPlayer();
virtual const MWWorld::ESMStore& getStore() const;