From d467888d890eeae8febeefb60fa4151c9c273ad6 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 13 Jul 2016 22:11:21 -0600 Subject: [PATCH] light: register settings in a map --- include/light/light.hh | 27 ++++++++++++------ light/entities.cc | 6 ++-- light/light.cc | 62 +++++++++++++++++++++++++++++++++++++++--- light/ltface.cc | 2 +- 4 files changed, 80 insertions(+), 17 deletions(-) diff --git a/include/light/light.hh b/include/light/light.hh index 07a0da26..5f7432a4 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -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 _names; + +public: + const std::vector &names() const { return _names; } + lockable_setting_t(std::vector 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 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 { name }, v, l) {} }; -class lockable_vec3_t { -private: - std::vector _names; - +class lockable_vec3_t : public lockable_setting_t { public: vec3_t value; bool locked; lockable_vec3_t(std::vector 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 */ diff --git a/light/entities.cc b/light/entities.cc index 8ef0a351..fe84289b 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -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; } } } diff --git a/light/light.cc b/light/light.cc index 296d3545..fa4ccc58 100644 --- a/light/light.cc +++ b/light/light.cc @@ -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 settingsmap; + +static void RegisterSettings(std::vector 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 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; diff --git a/light/ltface.cc b/light/ltface.cc index ec092f5f..41401d88 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -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);