light: set min/max values for some settings

This commit is contained in:
Eric Wasylishen 2016-07-14 00:02:44 -06:00
parent 08a6733204
commit 60d96df31c
3 changed files with 50 additions and 24 deletions

View File

@ -222,11 +222,15 @@ protected:
bool _locked;
bool _registered;
std::vector<std::string> _names;
public:
const std::vector<std::string> &names() const { return _names; }
lockable_setting_t(std::vector<std::string> names)
: _locked(false), _registered(false), _names(names) {}
: _locked(false), _registered(false), _names(names) {
assert(_names.size() > 0);
}
public:
const std::string &primaryName() const { return _names.at(0); }
const std::vector<std::string> &names() const { return _names; }
bool isRegistered() { return _registered; }
void setRegistered() { _registered = true; }
@ -234,7 +238,22 @@ public:
class lockable_vec_t : public lockable_setting_t {
private:
vec_t _value;
float _value, _min, _max;
void setFloatInternal(float f) {
assert(_registered);
if (f < _min) {
logprint("WARNING: '%s': %f is less than minimum value %f.\n",
primaryName().c_str(), f, _min);
f = _min;
}
if (f > _max) {
logprint("WARNING: '%s': %f is greater than maximum value %f.\n",
primaryName().c_str(), f, _max);
f = _max;
}
_value = f;
}
public:
bool boolValue() const {
@ -250,23 +269,30 @@ public:
}
void setFloatValue(float f) {
assert(_registered);
if (!_locked) {
_value = f;
setFloatInternal(f);
}
}
void setFloatValueLocked(float f) {
assert(_registered);
_value = f;
setFloatInternal(f);
_locked = true;
}
lockable_vec_t(std::vector<std::string> names, vec_t v)
: lockable_setting_t(names), _value(v) {}
lockable_vec_t(std::vector<std::string> names, float v,
float minval=-std::numeric_limits<float>::infinity(),
float maxval=std::numeric_limits<float>::infinity())
: lockable_setting_t(names), _value(v), _min(minval), _max(maxval) {
// check the default value is valid
assert(_min < _max);
assert(_value >= _min);
assert(_value <= _max);
}
lockable_vec_t(std::string name, vec_t v)
: lockable_vec_t(std::vector<std::string> { name }, v) {}
lockable_vec_t(std::string name, float v,
float minval=-std::numeric_limits<float>::infinity(),
float maxval=std::numeric_limits<float>::infinity())
: lockable_vec_t(std::vector<std::string> { name }, v, minval, maxval) {}
};
class lockable_vec3_t : public lockable_setting_t {

View File

@ -52,7 +52,7 @@ lockable_vec_t sunlight_dirt { "sunlight_dirt", 0.0f };
lockable_vec_t sunlight2_dirt { "sunlight2_dirt", 0.0f };
lockable_vec3_t sunvec { strings{"sunlight_mangle", "sun_mangle"}, 0.0f, 0.0f, -1.0f }; /* defaults to straight down */
lockable_vec3_t sun2vec { "sun2_mangle", 0.0f, 0.0f, -1.0f }; /* defaults to straight down */
lockable_vec_t sun_deviance { "sunlight_penumbra", 0.0f };
lockable_vec_t sun_deviance { "sunlight_penumbra", 0.0f, 0.0f, 180.0f };
// entity_t

View File

@ -43,12 +43,12 @@ using namespace std;
using strings = std::vector<std::string>;
lockable_vec_t scaledist {"dist", 1.0};
lockable_vec_t rangescale {"range", 0.5};
lockable_vec_t global_anglescale {strings{"anglescale", "anglesense"}, 0.5};
lockable_vec_t scaledist {"dist", 1.0, 0.0f, 100.0f};
lockable_vec_t rangescale {"range", 0.5f, 0.0f, 100.0f};
lockable_vec_t global_anglescale {strings{"anglescale", "anglesense"}, 0.5, 0.0f, 1.0f};
float fadegate = EQUAL_EPSILON;
int softsamples = 0;
lockable_vec_t lightmapgamma {"gamma", 1.0};
lockable_vec_t lightmapgamma {"gamma", 1.0, 0.0f, 100.0f};
const vec3_t vec3_white = { 255, 255, 255 };
float surflight_subdivide = 128.0f;
int sunsamples = 64;
@ -63,10 +63,10 @@ sun_t *suns = NULL;
/* dirt */
lockable_vec_t dirty {strings{"dirt", "dirty"}, 0.0f};
lockable_vec_t dirtMode {"dirtmode", 0.0f};
lockable_vec_t dirtDepth {"dirtdepth", 128.0f};
lockable_vec_t dirtScale {"dirtscale", 1.0f};
lockable_vec_t dirtGain {"dirtgain", 1.0f};
lockable_vec_t dirtAngle {"dirtangle", 88.0f};
lockable_vec_t dirtDepth {"dirtdepth", 128.0f, 1.0f, std::numeric_limits<float>::infinity()};
lockable_vec_t dirtScale {"dirtscale", 1.0f, 0.0f, 100.0f};
lockable_vec_t dirtGain {"dirtgain", 1.0f, 0.0f, 100.0f};
lockable_vec_t dirtAngle {"dirtangle", 88.0f, 0.0f, 90.0f};
qboolean globalDirt = false;
lockable_vec_t minlightDirt {"minlight_dirt", 0};
@ -76,8 +76,8 @@ lockable_vec_t phongallowed {"phong", 1.0f};
/* bounce */
lockable_vec_t bounce {"bounce", 0.0f};
lockable_vec_t bouncescale {"bouncescale", 1.0f};
lockable_vec_t bouncecolorscale {"bouncecolorscale", 0.0f};
lockable_vec_t bouncescale {"bouncescale", 1.0f, 0.0f, 100.0f};
lockable_vec_t bouncecolorscale {"bouncecolorscale", 0.0f, 0.0f, 1.0f};
qboolean surflight_dump = false;