light: register settings in a map
This commit is contained in:
parent
cd013405e7
commit
d467888d89
|
|
@ -216,9 +216,21 @@ Face_EdgeIndexSmoothed(const bsp2_t *bsp, const bsp2_dface_t *f, const int edgei
|
|||
|
||||
/* command-line options */
|
||||
|
||||
class lockable_vec_t {
|
||||
private:
|
||||
class lockable_setting_t {
|
||||
protected:
|
||||
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)
|
||||
: _registered(false), _names(names) {}
|
||||
|
||||
bool isRegistered() { return _registered; }
|
||||
void setRegistered() { _registered = true; }
|
||||
};
|
||||
|
||||
class lockable_vec_t : public lockable_setting_t {
|
||||
public:
|
||||
vec_t value;
|
||||
bool locked;
|
||||
|
|
@ -232,22 +244,19 @@ public:
|
|||
}
|
||||
|
||||
lockable_vec_t(std::vector<std::string> names, vec_t v, bool l = false)
|
||||
: _names(names), value(v), locked(l) {}
|
||||
: lockable_setting_t(names), value(v), locked(l) {}
|
||||
|
||||
lockable_vec_t(std::string name, vec_t v, bool l = false)
|
||||
: lockable_vec_t(std::vector<std::string> { name }, v, l) {}
|
||||
};
|
||||
|
||||
class lockable_vec3_t {
|
||||
private:
|
||||
std::vector<std::string> _names;
|
||||
|
||||
class lockable_vec3_t : public lockable_setting_t {
|
||||
public:
|
||||
vec3_t value;
|
||||
bool locked;
|
||||
|
||||
lockable_vec3_t(std::vector<std::string> names, vec_t a, vec_t b, vec_t c, bool l = false)
|
||||
: _names(names), locked(l)
|
||||
: lockable_setting_t(names), locked(l)
|
||||
{
|
||||
VectorSet(value, a, b, c);
|
||||
}
|
||||
|
|
@ -285,7 +294,7 @@ extern lockable_vec_t dirtGain;
|
|||
extern lockable_vec_t dirtAngle;
|
||||
|
||||
extern qboolean globalDirt; // apply dirt to all lights (unless they override it)?
|
||||
extern qboolean minlightDirt; // apply dirt to minlight?
|
||||
extern lockable_vec_t minlightDirt; // apply dirt to minlight?
|
||||
|
||||
/* phong */
|
||||
|
||||
|
|
|
|||
|
|
@ -1260,16 +1260,16 @@ LoadEntities(const bsp2_t *bsp)
|
|||
}
|
||||
|
||||
if (entity->minlight_dirt == 1) {
|
||||
minlightDirt = true;
|
||||
minlightDirt.value = true;
|
||||
if (!dirty.locked) {
|
||||
dirty.value = true;
|
||||
}
|
||||
logprint("Minlight dirtmapping enabled in worldspawn.\n");
|
||||
} else if (entity->minlight_dirt == -1) {
|
||||
minlightDirt = false;
|
||||
minlightDirt.value = false;
|
||||
logprint("Minlight dirtmapping disabled in worldspawn.\n");
|
||||
} else {
|
||||
minlightDirt = globalDirt;
|
||||
minlightDirt.value = globalDirt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ lockable_vec_t dirtGain {"dirtgain", 1.0f};
|
|||
lockable_vec_t dirtAngle {"dirtangle", 88.0f};
|
||||
|
||||
qboolean globalDirt = false;
|
||||
qboolean minlightDirt = false;
|
||||
lockable_vec_t minlightDirt {"minlight_dirt", 0};
|
||||
|
||||
/* phong */
|
||||
lockable_vec_t phongallowed {"phong", 1.0f};
|
||||
|
|
@ -118,6 +118,59 @@ int dump_facenum = -1;
|
|||
bool dump_face;
|
||||
vec3_t dump_face_point = {0,0,0};
|
||||
|
||||
std::map<std::string, lockable_setting_t *> settingsmap;
|
||||
|
||||
static void RegisterSettings(std::vector<lockable_setting_t *> settings)
|
||||
{
|
||||
for (lockable_setting_t *setting : settings) {
|
||||
assert(!setting->isRegistered());
|
||||
for (const auto &name : setting->names()) {
|
||||
assert(settingsmap.find(name) == settingsmap.end());
|
||||
|
||||
settingsmap[name] = setting;
|
||||
}
|
||||
|
||||
setting->setRegistered();
|
||||
}
|
||||
}
|
||||
|
||||
void InitSettings()
|
||||
{
|
||||
std::vector<lockable_setting_t *> settings {
|
||||
&minlight,
|
||||
&addminlight,
|
||||
&lightmapgamma,
|
||||
&bounce,
|
||||
&bouncescale,
|
||||
&bouncecolorscale,
|
||||
&minlight_color,
|
||||
&minlightDirt,
|
||||
&scaledist,
|
||||
&rangescale,
|
||||
&global_anglescale,
|
||||
&dirtDepth,
|
||||
&dirtMode,
|
||||
&dirtScale,
|
||||
&dirtGain,
|
||||
&dirtAngle,
|
||||
&dirty,
|
||||
&sunlight,
|
||||
&sunvec,
|
||||
&sunlight_color,
|
||||
&sun_deviance,
|
||||
&sunlight_dirt,
|
||||
&sun2,
|
||||
&sun2vec,
|
||||
&sun2_color,
|
||||
&sunlight2,
|
||||
&sunlight2_color,
|
||||
&sunlight2_dirt,
|
||||
&sunlight3,
|
||||
&sunlight3_color
|
||||
};
|
||||
RegisterSettings(settings);
|
||||
}
|
||||
|
||||
void
|
||||
GetFileSpace(byte **lightdata, byte **colordata, byte **deluxdata, int size)
|
||||
{
|
||||
|
|
@ -1427,13 +1480,14 @@ main(int argc, const char **argv)
|
|||
double end;
|
||||
char source[1024];
|
||||
const char *lmscaleoverride = NULL;
|
||||
|
||||
|
||||
init_log("light.log");
|
||||
logprint("---- light / TyrUtils " stringify(TYRUTILS_VERSION) " ----\n");
|
||||
|
||||
LowerProcessPriority();
|
||||
numthreads = GetDefaultThreads();
|
||||
|
||||
InitSettings();
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "-threads")) {
|
||||
numthreads = ParseInt(&i, argc, argv);
|
||||
|
|
@ -1496,7 +1550,7 @@ main(int argc, const char **argv)
|
|||
dirty.value = true;
|
||||
dirty.locked = true;
|
||||
globalDirt = true;
|
||||
minlightDirt = true;
|
||||
minlightDirt.value = true;
|
||||
logprint( "Dirtmapping enabled globally\n" );
|
||||
} else {
|
||||
dirty.value = false;
|
||||
|
|
|
|||
|
|
@ -1528,7 +1528,7 @@ LightFace_Min(const bsp2_t *bsp, const bsp2_dface_t *face,
|
|||
sample = lightmap->samples;
|
||||
for (i = 0; i < lightsurf->numpoints; i++, sample++) {
|
||||
vec_t value = light->light;
|
||||
if (minlightDirt)
|
||||
if (minlightDirt.boolValue())
|
||||
value *= Dirt_GetScaleFactor(lightsurf->occlusion[i], NULL, lightsurf);
|
||||
if (addminlight.boolValue())
|
||||
Light_Add(sample, value, light->color, vec3_origin);
|
||||
|
|
|
|||
Loading…
Reference in New Issue