light: move command-line parsing to use settings system
This commit is contained in:
parent
df62b9fa16
commit
2e9c58fb46
|
|
@ -33,6 +33,7 @@
|
|||
#include <string>
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
#define ON_EPSILON 0.1
|
||||
#define ANGLE_EPSILON 0.001
|
||||
|
|
@ -236,6 +237,10 @@ public:
|
|||
const std::vector<std::string> &names() const { return _names; }
|
||||
|
||||
virtual void setStringValue(const std::string &str, bool locked = false) = 0;
|
||||
virtual std::string stringValue() const = 0;
|
||||
|
||||
virtual bool isChanged() const = 0;
|
||||
bool isLocked() const { return _locked; }
|
||||
|
||||
bool isRegistered() { return _registered; }
|
||||
void setRegistered() { _registered = true; }
|
||||
|
|
@ -243,7 +248,7 @@ public:
|
|||
|
||||
class lockable_vec_t : public lockable_setting_t {
|
||||
private:
|
||||
float _value, _min, _max;
|
||||
float _default, _value, _min, _max;
|
||||
|
||||
void setFloatInternal(float f) {
|
||||
assert(_registered);
|
||||
|
|
@ -290,10 +295,18 @@ public:
|
|||
else setFloatValue(f);
|
||||
}
|
||||
|
||||
virtual std::string stringValue() const {
|
||||
return std::to_string(_value);
|
||||
}
|
||||
|
||||
virtual bool isChanged() const {
|
||||
return _value != _default;
|
||||
}
|
||||
|
||||
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) {
|
||||
: lockable_setting_t(names), _default(v), _value(v), _min(minval), _max(maxval) {
|
||||
// check the default value is valid
|
||||
assert(_min < _max);
|
||||
assert(_value >= _min);
|
||||
|
|
@ -321,32 +334,37 @@ void normalize_color_format(vec3_t color);
|
|||
|
||||
class lockable_vec3_t : public lockable_setting_t {
|
||||
private:
|
||||
vec3_t _value;
|
||||
vec3_t _default, _value;
|
||||
vec3_transformer_t _transformer;
|
||||
|
||||
void transformAndSetVec3Value(const vec3_t val) {
|
||||
void transformVec3Value(const vec3_t val, vec3_t out) const {
|
||||
// apply transform
|
||||
switch (_transformer) {
|
||||
case vec3_transformer_t::NONE:
|
||||
VectorCopy(val, _value);
|
||||
VectorCopy(val, out);
|
||||
break;
|
||||
case vec3_transformer_t::MANGLE_TO_VEC:
|
||||
vec_from_mangle(_value, val);
|
||||
vec_from_mangle(out, val);
|
||||
break;
|
||||
case vec3_transformer_t::NORMALIZE_COLOR_TO_255:
|
||||
VectorCopy(val, _value);
|
||||
normalize_color_format(_value);
|
||||
VectorCopy(val, out);
|
||||
normalize_color_format(out);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void transformAndSetVec3Value(const vec3_t val) {
|
||||
transformVec3Value(val, _value);
|
||||
}
|
||||
|
||||
public:
|
||||
lockable_vec3_t(std::vector<std::string> names, vec_t a, vec_t b, vec_t c,
|
||||
vec3_transformer_t t = vec3_transformer_t::NONE)
|
||||
: lockable_setting_t(names), _transformer(t)
|
||||
{
|
||||
vec3_t tmp = { a, b, c };
|
||||
transformAndSetVec3Value(tmp);
|
||||
transformVec3Value(tmp, _default);
|
||||
VectorCopy(_default, _value);
|
||||
}
|
||||
|
||||
lockable_vec3_t(std::string name, vec_t a, vec_t b, vec_t c,
|
||||
|
|
@ -384,6 +402,23 @@ public:
|
|||
if (locked) setVec3ValueLocked(vec3t);
|
||||
else setVec3Value(vec3t);
|
||||
}
|
||||
|
||||
virtual std::string stringValue() const {
|
||||
std::stringstream ss;
|
||||
ss << _value[0] << " "
|
||||
<< _value[1] << " "
|
||||
<< _value[2];
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
virtual bool isChanged() const {
|
||||
for (int i=0; i<3; i++) {
|
||||
if (_default[i] != _value[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
void SetGlobalSetting(std::string name, std::string value, bool cmdline);
|
||||
|
|
|
|||
174
light/light.cc
174
light/light.cc
|
|
@ -123,6 +123,7 @@ bool dump_vert;
|
|||
vec3_t dump_vert_point = {0,0,0};
|
||||
|
||||
std::map<std::string, lockable_setting_t *> settingsmap;
|
||||
std::vector<lockable_setting_t *> allsettings;
|
||||
|
||||
static void RegisterSettings(std::vector<lockable_setting_t *> settings)
|
||||
{
|
||||
|
|
@ -162,16 +163,13 @@ void SetGlobalSetting(std::string name, std::string value, bool cmdline)
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
logprint("setting '%s' to '%s' from %s\n",
|
||||
name.c_str(), value.c_str(), cmdline ? "command line" : "worldspawn");
|
||||
|
||||
setting->setStringValue(value, cmdline);
|
||||
}
|
||||
|
||||
void InitSettings()
|
||||
{
|
||||
std::vector<lockable_setting_t *> settings {
|
||||
allsettings = {
|
||||
&minlight,
|
||||
&addminlight,
|
||||
&lightmapgamma,
|
||||
|
|
@ -203,7 +201,22 @@ void InitSettings()
|
|||
&sunlight3,
|
||||
&sunlight3_color
|
||||
};
|
||||
RegisterSettings(settings);
|
||||
RegisterSettings(allsettings);
|
||||
}
|
||||
|
||||
static void
|
||||
PrintOptionsSummary(void)
|
||||
{
|
||||
logprint("Options summary:\n");
|
||||
|
||||
for (lockable_setting_t *setting : allsettings) {
|
||||
if (setting->isChanged()) {
|
||||
logprint(" \"%s\" was set to \"%s\" from %s\n",
|
||||
setting->primaryName().c_str(),
|
||||
setting->stringValue().c_str(),
|
||||
setting->isLocked() ? "commandline" : "worldspawn");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -1570,22 +1583,11 @@ main(int argc, const char **argv)
|
|||
} else if (!strcmp(argv[i], "-extra4")) {
|
||||
oversample = 4;
|
||||
logprint("extra 4x4 sampling enabled\n");
|
||||
} else if (!strcmp(argv[i], "-dist")) {
|
||||
scaledist.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
} else if (!strcmp(argv[i], "-range")) {
|
||||
rangescale.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
} else if (!strcmp(argv[i], "-gate")) {
|
||||
fadegate = ParseVec(&i, argc, argv);
|
||||
if (fadegate > 1) {
|
||||
logprint( "WARNING: -gate value greater than 1 may cause artifacts\n" );
|
||||
}
|
||||
} else if (!strcmp(argv[i], "-light")) {
|
||||
minlight.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
} else if (!strcmp(argv[i], "-addmin")) {
|
||||
addminlight.setFloatValueLocked(true);
|
||||
} else if (!strcmp(argv[i], "-gamma")) {
|
||||
lightmapgamma.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
logprint( "Lightmap gamma %f specified on command-line.\n", lightmapgamma.floatValue() );
|
||||
} else if (!strcmp(argv[i], "-lit")) {
|
||||
write_litfile |= 1;
|
||||
} else if (!strcmp(argv[i], "-lit2")) {
|
||||
|
|
@ -1612,22 +1614,6 @@ main(int argc, const char **argv)
|
|||
softsamples = ParseInt(&i, argc, argv);
|
||||
else
|
||||
softsamples = -1; /* auto, based on oversampling */
|
||||
} else if (!strcmp(argv[i], "-anglescale") || !strcmp(argv[i], "-anglesense")) {
|
||||
global_anglescale.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
logprint("Using global anglescale value of %f from command line.\n", global_anglescale.floatValue());
|
||||
} else if ( !strcmp( argv[ i ], "-dirt" ) ) {
|
||||
int dirt_param = 1;
|
||||
ParseIntOptional(&dirt_param, &i, argc, argv);
|
||||
|
||||
if (dirt_param) {
|
||||
dirty.setFloatValueLocked(true);
|
||||
globalDirt = true;
|
||||
minlightDirt.setFloatValue(true);
|
||||
logprint( "Dirtmapping enabled globally\n" );
|
||||
} else {
|
||||
dirty.setFloatValueLocked(false);
|
||||
logprint( "Dirtmapping disabled\n" );
|
||||
}
|
||||
} else if ( !strcmp( argv[ i ], "-dirtdebug" ) || !strcmp( argv[ i ], "-debugdirt" ) ) {
|
||||
CheckNoDebugModeSet();
|
||||
|
||||
|
|
@ -1635,72 +1621,11 @@ main(int argc, const char **argv)
|
|||
globalDirt = true;
|
||||
debugmode = debugmode_dirt;
|
||||
logprint( "Dirtmap debugging enabled\n" );
|
||||
} else if ( !strcmp( argv[ i ], "-dirtmode" ) ) {
|
||||
dirtMode.setFloatValueLocked(ParseInt(&i, argc, argv));
|
||||
if ( dirtMode.intValue() != 0 && dirtMode.intValue() != 1 ) {
|
||||
dirtMode.setFloatValueLocked(0);
|
||||
}
|
||||
if ( dirtMode.intValue() == 1 ) {
|
||||
logprint( "Enabling randomized dirtmapping\n" );
|
||||
}
|
||||
else{
|
||||
logprint( "Enabling ordered dirtmapping\n" );
|
||||
}
|
||||
} else if ( !strcmp( argv[ i ], "-dirtdepth" ) ) {
|
||||
dirtDepth.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
if ( dirtDepth.floatValue() <= 0.0f ) {
|
||||
dirtDepth.setFloatValueLocked(128.0f);
|
||||
}
|
||||
logprint( "Dirtmapping depth set to %.1f\n", dirtDepth.floatValue() );
|
||||
} else if ( !strcmp( argv[ i ], "-dirtscale" ) ) {
|
||||
dirtScale.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
if ( dirtScale.floatValue() <= 0.0f ) {
|
||||
dirtScale.setFloatValueLocked(1.0f);
|
||||
}
|
||||
logprint( "Dirtmapping scale set to %.1f\n", dirtScale.floatValue() );
|
||||
} else if ( !strcmp( argv[ i ], "-dirtgain" ) ) {
|
||||
dirtGain.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
if ( dirtGain.floatValue() <= 0.0f ) {
|
||||
dirtGain.setFloatValueLocked(1.0f);
|
||||
}
|
||||
logprint( "Dirtmapping gain set to %.1f\n", dirtGain.floatValue());
|
||||
} else if ( !strcmp( argv[ i ], "-dirtangle" ) ) {
|
||||
dirtAngle.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
logprint( "Dirtmapping cone angle set to %.1f\n", dirtAngle.floatValue() );
|
||||
} else if ( !strcmp( argv[ i ], "-phong" ) ) {
|
||||
int phong_param = 1;
|
||||
ParseIntOptional(&phong_param, &i, argc, argv);
|
||||
|
||||
if (phong_param) {
|
||||
logprint( "NOTE: -phong 1 has no effect\n" );
|
||||
} else {
|
||||
phongallowed.setFloatValueLocked(false);
|
||||
logprint( "Phong shading disabled\n" );
|
||||
}
|
||||
} else if ( !strcmp( argv[ i ], "-bounce" ) ) {
|
||||
int bounce_param = 1;
|
||||
ParseIntOptional(&bounce_param, &i, argc, argv);
|
||||
|
||||
bounce.setFloatValueLocked(bounce_param);
|
||||
if (bounce_param)
|
||||
logprint( "Bounce enabled on command line\n");
|
||||
else
|
||||
logprint( "Bounce disabled on command line\n");
|
||||
} else if ( !strcmp( argv[ i ], "-bouncedebug" ) ) {
|
||||
CheckNoDebugModeSet();
|
||||
bounce.setFloatValueLocked(true);
|
||||
debugmode = debugmode_bounce;
|
||||
logprint( "Bounce debugging mode enabled on command line\n" );
|
||||
} else if ( !strcmp( argv[ i ], "-bouncescale" ) ) {
|
||||
bounce.setFloatValueLocked(true);
|
||||
bouncescale.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
logprint( "Bounce scale factor set to %f on command line\n", bouncescale.floatValue() );
|
||||
} else if ( !strcmp( argv[ i ], "-bouncecolorscale" ) ) {
|
||||
bounce.setFloatValueLocked(true);
|
||||
float tmp = ParseVec(&i, argc, argv);
|
||||
tmp = qmin(qmax(tmp, 0.0f), 1.0f);
|
||||
bouncecolorscale.setFloatValueLocked(tmp);
|
||||
logprint( "Bounce color scale factor set to %f on command line\n", bouncecolorscale.floatValue() );
|
||||
} else if ( !strcmp( argv[ i ], "-surflight_subdivide" ) ) {
|
||||
surflight_subdivide = ParseVec(&i, argc, argv);
|
||||
surflight_subdivide = qmin(qmax(surflight_subdivide, 64.0f), 2048.0f);
|
||||
|
|
@ -1737,52 +1662,31 @@ main(int argc, const char **argv)
|
|||
} else if ( !strcmp( argv[ i ], "-debugvert" ) ) {
|
||||
ParseVec3(dump_vert_point, &i, argc, argv);
|
||||
dump_vert = true;
|
||||
} else if ( !strcmp( argv[ i ], "-sunlight" ) ) {
|
||||
sunlight.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
} else if ( !strcmp( argv[ i ], "-sunlight_color" ) ) {
|
||||
vec3_t tmp;
|
||||
ParseVec3(tmp, &i, argc, argv);
|
||||
sunlight_color.setVec3ValueLocked(tmp);
|
||||
} else if ( !strcmp( argv[ i ], "-sun2" ) ) {
|
||||
sun2.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
} else if ( !strcmp( argv[ i ], "-sun2_color" ) ) {
|
||||
vec3_t tmp;
|
||||
ParseVec3(tmp, &i, argc, argv);
|
||||
sun2_color.setVec3ValueLocked(tmp);
|
||||
} else if ( !strcmp( argv[ i ], "-sunlight2" ) ) {
|
||||
sunlight2.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
} else if ( !strcmp( argv[ i ], "-sunlight2_color" ) ) {
|
||||
vec3_t tmp;
|
||||
ParseVec3(tmp, &i, argc, argv);
|
||||
sunlight2_color.setVec3ValueLocked(tmp);
|
||||
} else if ( !strcmp( argv[ i ], "-sunlight3" ) ) {
|
||||
sunlight3.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
} else if ( !strcmp( argv[ i ], "-sunlight3_color" ) ) {
|
||||
vec3_t tmp;
|
||||
ParseVec3(tmp, &i, argc, argv);
|
||||
sunlight3_color.setVec3ValueLocked(tmp);
|
||||
} else if ( !strcmp( argv[ i ], "-sunlight_dirt" ) ) {
|
||||
sunlight_dirt.setFloatValueLocked(ParseInt(&i, argc, argv));
|
||||
} else if ( !strcmp( argv[ i ], "-sunlight2_dirt" ) ) {
|
||||
sunlight2_dirt.setFloatValueLocked(ParseInt(&i, argc, argv));
|
||||
} else if ( !strcmp( argv[ i ], "-sunvec" ) ) {
|
||||
vec3_t tmp;
|
||||
ParseVec3(tmp, &i, argc, argv);
|
||||
sunvec.setVec3ValueLocked(tmp);
|
||||
} else if ( !strcmp( argv[ i ], "-sun2vec" ) ) {
|
||||
vec3_t tmp;
|
||||
ParseVec3(tmp, &i, argc, argv);
|
||||
sun2vec.setVec3ValueLocked(tmp);
|
||||
} else if ( !strcmp( argv[ i ], "-sun_deviance" ) ) {
|
||||
sun_deviance.setFloatValueLocked(ParseVec(&i, argc, argv));
|
||||
} else if ( !strcmp( argv[ i ], "-help" ) ) {
|
||||
PrintUsage();
|
||||
exit(0);
|
||||
} else if (argv[i][0] == '-') {
|
||||
PrintUsage();
|
||||
Error("Unknown option \"%s\"", argv[i]);
|
||||
} else
|
||||
// hand over to the settings system
|
||||
std::string settingname { &argv[i][1] };
|
||||
lockable_setting_t *setting = FindSetting(settingname);
|
||||
if (setting == nullptr) {
|
||||
Error("Unknown option \"-%s\"", settingname.c_str());
|
||||
PrintUsage();
|
||||
}
|
||||
|
||||
if (lockable_vec_t *vecsetting = dynamic_cast<lockable_vec_t *>(setting)) {
|
||||
float v = ParseVec(&i, argc, argv);
|
||||
vecsetting->setFloatValueLocked(v);
|
||||
} else if (lockable_vec3_t *vec3setting = dynamic_cast<lockable_vec3_t *>(setting)) {
|
||||
vec3_t temp;
|
||||
ParseVec3(temp, &i, argc, argv);
|
||||
vec3setting->setVec3ValueLocked(temp);
|
||||
} else {
|
||||
Error("Internal error");
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i != argc - 1) {
|
||||
|
|
@ -1857,6 +1761,8 @@ main(int argc, const char **argv)
|
|||
LoadExtendedTexinfoFlags(source, bsp);
|
||||
LoadEntities(bsp);
|
||||
|
||||
PrintOptionsSummary();
|
||||
|
||||
FindDebugFace(bsp);
|
||||
FindDebugVert(bsp);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue