diff --git a/include/light/light.hh b/include/light/light.hh index 869832fb..09a6c5d6 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -222,11 +222,15 @@ protected: bool _locked; bool _registered; std::vector _names; - -public: - const std::vector &names() const { return _names; } + lockable_setting_t(std::vector 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 &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 names, vec_t v) - : lockable_setting_t(names), _value(v) {} + lockable_vec_t(std::vector names, float v, + float minval=-std::numeric_limits::infinity(), + float maxval=std::numeric_limits::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 { name }, v) {} + lockable_vec_t(std::string name, float v, + float minval=-std::numeric_limits::infinity(), + float maxval=std::numeric_limits::infinity()) + : lockable_vec_t(std::vector { name }, v, minval, maxval) {} }; class lockable_vec3_t : public lockable_setting_t { diff --git a/light/entities.cc b/light/entities.cc index 8bf919de..aead0e80 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -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 diff --git a/light/light.cc b/light/light.cc index a91056d3..46e2b59c 100644 --- a/light/light.cc +++ b/light/light.cc @@ -43,12 +43,12 @@ using namespace std; using strings = std::vector; -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::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;