Merge branch 'master' into buttons
Conflicts: apps/opencs/view/render/instancemode.cppcoverity_scan
commit
4a02563708
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,123 @@
|
||||
#include "gmstcheck.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "../world/defaultgmsts.hpp"
|
||||
|
||||
CSMTools::GmstCheckStage::GmstCheckStage(const CSMWorld::IdCollection<ESM::GameSetting>& gameSettings)
|
||||
: mGameSettings(gameSettings)
|
||||
{}
|
||||
|
||||
int CSMTools::GmstCheckStage::setup()
|
||||
{
|
||||
return mGameSettings.getSize();
|
||||
}
|
||||
|
||||
void CSMTools::GmstCheckStage::perform(int stage, CSMDoc::Messages& messages)
|
||||
{
|
||||
const CSMWorld::Record<ESM::GameSetting>& record = mGameSettings.getRecord (stage);
|
||||
|
||||
if (record.isDeleted())
|
||||
return;
|
||||
|
||||
const ESM::GameSetting& gmst = record.get();
|
||||
|
||||
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Gmst, gmst.mId);
|
||||
|
||||
// Test for empty string
|
||||
if (gmst.mValue.getType() == ESM::VT_String && gmst.mValue.getString().empty())
|
||||
messages.add(id, gmst.mId + " is an empty string", "", CSMDoc::Message::Severity_Warning);
|
||||
|
||||
// Checking type and limits
|
||||
// optimization - compare it to lists based on naming convention (f-float,i-int,s-string)
|
||||
if (gmst.mId[0] == 'f')
|
||||
{
|
||||
for (size_t i = 0; i < CSMWorld::DefaultGmsts::FloatCount; ++i)
|
||||
{
|
||||
if (gmst.mId == CSMWorld::DefaultGmsts::Floats[i])
|
||||
{
|
||||
if (gmst.mValue.getType() != ESM::VT_Float)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << "Expected float type for " << gmst.mId << " but found "
|
||||
<< varTypeToString(gmst.mValue.getType()) << " type";
|
||||
|
||||
messages.add(id, stream.str(), "", CSMDoc::Message::Severity_Error);
|
||||
}
|
||||
|
||||
if (gmst.mValue.getFloat() < CSMWorld::DefaultGmsts::FloatLimits[i*2])
|
||||
messages.add(id, gmst.mId + " is less than the suggested range", "",
|
||||
CSMDoc::Message::Severity_Warning);
|
||||
|
||||
if (gmst.mValue.getFloat() > CSMWorld::DefaultGmsts::FloatLimits[i*2+1])
|
||||
messages.add(id, gmst.mId + " is more than the suggested range", "",
|
||||
CSMDoc::Message::Severity_Warning);
|
||||
|
||||
break; // for loop
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (gmst.mId[0] == 'i')
|
||||
{
|
||||
for (size_t i = 0; i < CSMWorld::DefaultGmsts::IntCount; ++i)
|
||||
{
|
||||
if (gmst.mId == CSMWorld::DefaultGmsts::Ints[i])
|
||||
{
|
||||
if (gmst.mValue.getType() != ESM::VT_Int)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << "Expected int type for " << gmst.mId << " but found "
|
||||
<< varTypeToString(gmst.mValue.getType()) << " type";
|
||||
|
||||
messages.add(id, stream.str(), "", CSMDoc::Message::Severity_Error);
|
||||
}
|
||||
|
||||
if (gmst.mValue.getInteger() < CSMWorld::DefaultGmsts::IntLimits[i*2])
|
||||
messages.add(id, gmst.mId + " is less than the suggested range", "",
|
||||
CSMDoc::Message::Severity_Warning);
|
||||
|
||||
if (gmst.mValue.getInteger() > CSMWorld::DefaultGmsts::IntLimits[i*2+1])
|
||||
messages.add(id, gmst.mId + " is more than the suggested range", "",
|
||||
CSMDoc::Message::Severity_Warning);
|
||||
|
||||
break; // for loop
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (gmst.mId[0] == 's')
|
||||
{
|
||||
for (size_t i = 0; i < CSMWorld::DefaultGmsts::StringCount; ++i)
|
||||
{
|
||||
if (gmst.mId == CSMWorld::DefaultGmsts::Strings[i])
|
||||
{
|
||||
ESM::VarType type = gmst.mValue.getType();
|
||||
|
||||
if (type != ESM::VT_String && type != ESM::VT_None)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << "Expected string or none type for " << gmst.mId << " but found "
|
||||
<< varTypeToString(gmst.mValue.getType()) << " type";
|
||||
|
||||
messages.add(id, stream.str(), "", CSMDoc::Message::Severity_Error);
|
||||
}
|
||||
|
||||
break; // for loop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string CSMTools::GmstCheckStage::varTypeToString(ESM::VarType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ESM::VT_Unknown: return "unknown";
|
||||
case ESM::VT_None: return "none";
|
||||
case ESM::VT_Short: return "short";
|
||||
case ESM::VT_Int: return "int";
|
||||
case ESM::VT_Long: return "long";
|
||||
case ESM::VT_Float: return "float";
|
||||
case ESM::VT_String: return "string";
|
||||
default: return "unhandled";
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
#ifndef CSM_TOOLS_GMSTCHECK_H
|
||||
#define CSM_TOOLS_GMSTCHECK_H
|
||||
|
||||
#include <components/esm/loadgmst.hpp>
|
||||
|
||||
#include "../world/idcollection.hpp"
|
||||
|
||||
#include "../doc/stage.hpp"
|
||||
|
||||
namespace CSMTools
|
||||
{
|
||||
/// \brief VerifyStage: make sure that GMSTs are alright
|
||||
class GmstCheckStage : public CSMDoc::Stage
|
||||
{
|
||||
public:
|
||||
|
||||
GmstCheckStage(const CSMWorld::IdCollection<ESM::GameSetting>& gameSettings);
|
||||
|
||||
virtual int setup();
|
||||
///< \return number of steps
|
||||
|
||||
virtual void perform(int stage, CSMDoc::Messages& messages);
|
||||
///< Messages resulting from this stage will be appended to \a messages
|
||||
|
||||
private:
|
||||
|
||||
const CSMWorld::IdCollection<ESM::GameSetting>& mGameSettings;
|
||||
|
||||
std::string varTypeToString(ESM::VarType);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,34 @@
|
||||
#ifndef CSM_WORLD_DEFAULTGMSTS_H
|
||||
#define CSM_WORLD_DEFAULTGMSTS_H
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace CSMWorld {
|
||||
namespace DefaultGmsts {
|
||||
|
||||
const size_t FloatCount = 258;
|
||||
const size_t IntCount = 89;
|
||||
const size_t StringCount = 1174;
|
||||
|
||||
const size_t OptionalFloatCount = 42;
|
||||
const size_t OptionalIntCount = 4;
|
||||
const size_t OptionalStringCount = 26;
|
||||
|
||||
extern const char* Floats[];
|
||||
extern const char * Ints[];
|
||||
extern const char * Strings[];
|
||||
|
||||
extern const char * OptionalFloats[];
|
||||
extern const char * OptionalInts[];
|
||||
extern const char * OptionalStrings[];
|
||||
|
||||
extern const float FloatsDefaultValues[];
|
||||
extern const int IntsDefaultValues[];
|
||||
|
||||
extern const float FloatLimits[];
|
||||
extern const int IntLimits[];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,23 +0,0 @@
|
||||
#ifndef CSV_RENDER_ELEMENTS_H
|
||||
#define CSV_RENDER_ELEMENTS_H
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
/// Visual elements in a scene
|
||||
enum Elements
|
||||
{
|
||||
// elements that are part of the actual scene
|
||||
Element_Reference = 0x1,
|
||||
Element_Pathgrid = 0x2,
|
||||
Element_Water = 0x4,
|
||||
Element_Fog = 0x8,
|
||||
Element_Terrain = 0x10,
|
||||
|
||||
// control elements
|
||||
Element_CellMarker = 0x10000,
|
||||
Element_CellArrow = 0x20000,
|
||||
Element_CellBorder = 0x40000
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,35 @@
|
||||
#ifndef CSV_RENDER_ELEMENTS_H
|
||||
#define CSV_RENDER_ELEMENTS_H
|
||||
|
||||
namespace CSVRender
|
||||
{
|
||||
|
||||
/// Node masks used on the OSG scene graph in OpenMW-CS.
|
||||
/// @note See the respective file in OpenMW (apps/openmw/mwrender/vismask.hpp)
|
||||
/// for general usage hints about node masks.
|
||||
/// @copydoc MWRender::VisMask
|
||||
enum Mask
|
||||
{
|
||||
// internal use within NifLoader, do not change
|
||||
Mask_UpdateVisitor = 0x1,
|
||||
|
||||
// elements that are part of the actual scene
|
||||
Mask_Reference = 0x2,
|
||||
Mask_Pathgrid = 0x4,
|
||||
Mask_Water = 0x8,
|
||||
Mask_Fog = 0x10,
|
||||
Mask_Terrain = 0x20,
|
||||
|
||||
// used within models
|
||||
Mask_ParticleSystem = 0x100,
|
||||
|
||||
Mask_Lighting = 0x200,
|
||||
|
||||
// control elements
|
||||
Mask_CellMarker = 0x10000,
|
||||
Mask_CellArrow = 0x20000,
|
||||
Mask_CellBorder = 0x40000
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,18 +1,21 @@
|
||||
#ifndef GAME_MWWORLD_FALLBACK_H
|
||||
#define GAME_MWWORLD_FALLBACK_H
|
||||
#ifndef OPENMW_COMPONENTS_FALLBACK_H
|
||||
#define OPENMW_COMPONENTS_FALLBACK_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
std::map<std::string,std::string> mFallbackMap;
|
||||
public:
|
||||
Fallback(const std::map<std::string,std::string>& fallback);
|
||||
Map(const std::map<std::string,std::string>& fallback);
|
||||
Map() {}
|
||||
|
||||
std::string getFallbackString(const std::string& fall) const;
|
||||
float getFallbackFloat(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
|
@ -0,0 +1,109 @@
|
||||
#include "lightutil.hpp"
|
||||
|
||||
#include <osg/Light>
|
||||
#include <osg/Group>
|
||||
#include <osg/ComputeBoundsVisitor>
|
||||
|
||||
#include <components/esm/loadligh.hpp>
|
||||
|
||||
#include "lightmanager.hpp"
|
||||
#include "lightcontroller.hpp"
|
||||
#include "util.hpp"
|
||||
#include "visitor.hpp"
|
||||
#include "positionattitudetransform.hpp"
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
|
||||
void configureLight(osg::Light *light, float radius, bool isExterior, bool outQuadInLin, bool useQuadratic,
|
||||
float quadraticValue, float quadraticRadiusMult, bool useLinear, float linearRadiusMult, float linearValue)
|
||||
{
|
||||
bool quadratic = useQuadratic && (!outQuadInLin || isExterior);
|
||||
|
||||
float quadraticAttenuation = 0;
|
||||
float linearAttenuation = 0;
|
||||
if (quadratic)
|
||||
{
|
||||
float r = radius * quadraticRadiusMult;
|
||||
quadraticAttenuation = quadraticValue / std::pow(r, 2);
|
||||
}
|
||||
if (useLinear)
|
||||
{
|
||||
float r = radius * linearRadiusMult;
|
||||
linearAttenuation = linearValue / r;
|
||||
}
|
||||
|
||||
light->setLinearAttenuation(linearAttenuation);
|
||||
light->setQuadraticAttenuation(quadraticAttenuation);
|
||||
light->setConstantAttenuation(0.f);
|
||||
|
||||
}
|
||||
|
||||
void addLight (osg::Group* node, const ESM::Light* esmLight, unsigned int partsysMask, unsigned int lightMask, bool isExterior, bool outQuadInLin, bool useQuadratic,
|
||||
float quadraticValue, float quadraticRadiusMult, bool useLinear, float linearRadiusMult,
|
||||
float linearValue)
|
||||
{
|
||||
SceneUtil::FindByNameVisitor visitor("AttachLight");
|
||||
node->accept(visitor);
|
||||
|
||||
osg::Group* attachTo = NULL;
|
||||
if (visitor.mFoundNode)
|
||||
{
|
||||
attachTo = visitor.mFoundNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::ComputeBoundsVisitor computeBound;
|
||||
computeBound.setTraversalMask(~partsysMask);
|
||||
// We want the bounds of all children of the node, ignoring the node's local transformation
|
||||
// So do a traverse(), not accept()
|
||||
computeBound.traverse(*node);
|
||||
|
||||
// PositionAttitudeTransform seems to be slightly faster than MatrixTransform
|
||||
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> trans(new SceneUtil::PositionAttitudeTransform);
|
||||
trans->setPosition(computeBound.getBoundingBox().center());
|
||||
|
||||
node->addChild(trans);
|
||||
|
||||
attachTo = trans;
|
||||
}
|
||||
|
||||
osg::ref_ptr<SceneUtil::LightSource> lightSource (new SceneUtil::LightSource);
|
||||
osg::ref_ptr<osg::Light> light (new osg::Light);
|
||||
lightSource->setNodeMask(lightMask);
|
||||
|
||||
float radius = esmLight->mData.mRadius;
|
||||
lightSource->setRadius(radius);
|
||||
|
||||
configureLight(light, radius, isExterior, outQuadInLin, useQuadratic, quadraticValue,
|
||||
quadraticRadiusMult, useLinear, linearRadiusMult, linearValue);
|
||||
|
||||
osg::Vec4f diffuse = SceneUtil::colourFromRGB(esmLight->mData.mColor);
|
||||
if (esmLight->mData.mFlags & ESM::Light::Negative)
|
||||
{
|
||||
diffuse *= -1;
|
||||
diffuse.a() = 1;
|
||||
}
|
||||
light->setDiffuse(diffuse);
|
||||
light->setAmbient(osg::Vec4f(0,0,0,1));
|
||||
light->setSpecular(osg::Vec4f(0,0,0,0));
|
||||
|
||||
lightSource->setLight(light);
|
||||
|
||||
osg::ref_ptr<SceneUtil::LightController> ctrl (new SceneUtil::LightController);
|
||||
ctrl->setDiffuse(light->getDiffuse());
|
||||
if (esmLight->mData.mFlags & ESM::Light::Flicker)
|
||||
ctrl->setType(SceneUtil::LightController::LT_Flicker);
|
||||
if (esmLight->mData.mFlags & ESM::Light::FlickerSlow)
|
||||
ctrl->setType(SceneUtil::LightController::LT_FlickerSlow);
|
||||
if (esmLight->mData.mFlags & ESM::Light::Pulse)
|
||||
ctrl->setType(SceneUtil::LightController::LT_Pulse);
|
||||
if (esmLight->mData.mFlags & ESM::Light::PulseSlow)
|
||||
ctrl->setType(SceneUtil::LightController::LT_PulseSlow);
|
||||
|
||||
lightSource->addUpdateCallback(ctrl);
|
||||
|
||||
attachTo->addChild(lightSource);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
#ifndef OPENMW_COMPONENTS_LIGHTUTIL_H
|
||||
#define OPENMW_COMPONENTS_LIGHTUTIL_H
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Group;
|
||||
}
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class Light;
|
||||
}
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
|
||||
/// @brief Convert an ESM::Light to a SceneUtil::LightSource, and add it to a sub graph.
|
||||
/// @note If the sub graph contains a node named "AttachLight" (case insensitive), then the light is added to that.
|
||||
/// Otherwise, the light is added in the center of the node's bounds.
|
||||
/// @param node The sub graph to add a light to
|
||||
/// @param esmLight The light definition coming from the game files containing radius, color, flicker, etc.
|
||||
/// @param partsysMask Node mask to ignore when computing the sub graph's bounding box.
|
||||
/// @param lightMask Mask to assign to the newly created LightSource.
|
||||
/// @param isExterior Is the light outside? May be used for deciding which attenuation settings to use.
|
||||
/// @par Attenuation parameters come from the game INI file.
|
||||
void addLight (osg::Group* node, const ESM::Light* esmLight, unsigned int partsysMask, unsigned int lightMask, bool isExterior, bool outQuadInLin, bool useQuadratic,
|
||||
float quadraticValue, float quadraticRadiusMult, bool useLinear, float linearRadiusMult,
|
||||
float linearValue);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue