diff --git a/include/light/entities.hh b/include/light/entities.hh index f7ac6539..e7eebd27 100644 --- a/include/light/entities.hh +++ b/include/light/entities.hh @@ -29,8 +29,6 @@ #include #define DEFAULTLIGHTLEVEL 300.0f -#define LIGHT_TARGETS_START 32 -#define MAX_LIGHT_TARGETS 32 using entdict_t = std::map; @@ -187,7 +185,7 @@ std::string WorldValueForKey(const std::string &key); void LoadEntities(const globalconfig_t &cfg, const mbsp_t *bsp); void SetupLights(const globalconfig_t &cfg, const mbsp_t *bsp); bool ParseLightsFile(const char *fname); -void WriteEntitiesToString(mbsp_t *bsp); +void WriteEntitiesToString(const globalconfig_t &cfg, mbsp_t *bsp); void EstimateVisibleBoundsAtPoint(const vec3_t point, vec3_t mins, vec3_t maxs); bool EntDict_CheckNoEmptyValues(const mbsp_t *bsp, const entdict_t &entdict); diff --git a/include/light/light.hh b/include/light/light.hh index d64ba698..028736a9 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -271,7 +271,8 @@ public: lockable_vec_t minlight; lockable_vec3_t minlight_color; lockable_bool_t spotlightautofalloff; //mxd - + lockable_vec_t compilerstyle_start; // start index for switchable light styles, default 32 (FIXME: should be int) + /* dirt */ lockable_bool_t globalDirt; // apply dirt to all lights (unless they override it) + sunlight + minlight? lockable_vec_t dirtMode, dirtDepth, dirtScale, dirtGain, dirtAngle; @@ -316,6 +317,7 @@ public: minlight {strings{"light", "minlight"}, 0}, minlight_color {strings{"minlight_color", "mincolor"}, 255.0f, 255.0f, 255.0f, vec3_transformer_t::NORMALIZE_COLOR_TO_255}, spotlightautofalloff { "spotlightautofalloff", false }, //mxd + compilerstyle_start { "compilerstyle_start", 32 }, /* dirt */ globalDirt {strings{"dirt", "dirty"}, false}, @@ -363,6 +365,7 @@ public: &minlight, &minlight_color, &spotlightautofalloff, //mxd + &compilerstyle_start, &globalDirt, &dirtMode, &dirtDepth, &dirtScale, &dirtGain, &dirtAngle, &minlightDirt, diff --git a/light/entities.cc b/light/entities.cc index 558fb57e..668bf963 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -60,10 +60,7 @@ const char * light_t::classname() const { static std::vector> lightstyleForTargetname; -static bool IsSwitchableLightstyle(int style) { - return style >= LIGHT_TARGETS_START - && style < (LIGHT_TARGETS_START + MAX_LIGHT_TARGETS); -} +#define MAX_SWITCHABLE_STYLES 64 static entdict_t &WorldEnt() { @@ -90,7 +87,7 @@ std::string WorldValueForKey(const std::string &key) * Pass an empty string to generate a new unique lightstyle. */ static int -LightStyleForTargetname(const std::string &targetname) +LightStyleForTargetname(const globalconfig_t& cfg, const std::string &targetname) { // check if already assigned for (const auto &pr : lightstyleForTargetname) { @@ -99,13 +96,14 @@ LightStyleForTargetname(const std::string &targetname) } } - // check if full - if (lightstyleForTargetname.size() == MAX_LIGHT_TARGETS) { - Error("%s: Too many unique light targetnames\n", __func__); - } - // generate a new style number and return it - const int newStylenum = LIGHT_TARGETS_START + lightstyleForTargetname.size(); + const int newStylenum = cfg.compilerstyle_start.intValue() + lightstyleForTargetname.size(); + + // check if full + if (newStylenum >= MAX_SWITCHABLE_STYLES) { + Error("%s: Too many unique light targetnames (max=%d)\n", __func__, MAX_SWITCHABLE_STYLES); + } + lightstyleForTargetname.emplace_back(targetname, newStylenum); //mxd. https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-emplace.html if (verbose_log) { @@ -1078,7 +1076,7 @@ LoadEntities(const globalconfig_t &cfg, const mbsp_t *bsp) if (classname.find("light") == 0) { const std::string targetname = EntDict_StringForKey(entdict, "targetname"); if (!targetname.empty()) { - const int style = LightStyleForTargetname(targetname); + const int style = LightStyleForTargetname(cfg, targetname); entdict["style"] = std::to_string(style); } } @@ -1087,7 +1085,7 @@ LoadEntities(const globalconfig_t &cfg, const mbsp_t *bsp) if (EntDict_StringForKey(entdict, "_switchableshadow") == "1") { const std::string targetname = EntDict_StringForKey(entdict, "targetname"); // if targetname is "", generates a new unique lightstyle - const int style = LightStyleForTargetname(targetname); + const int style = LightStyleForTargetname(cfg, targetname); // TODO: Configurable key? entdict["switchshadstyle"] = std::to_string(style); } @@ -1384,7 +1382,7 @@ EntDict_VectorForKey(const entdict_t &ent, const std::string &key, vec3_t vec) * ================ */ void -WriteEntitiesToString(mbsp_t *bsp) +WriteEntitiesToString(const globalconfig_t& cfg, mbsp_t *bsp) { std::string entdata = EntData_Write(entdicts); @@ -1394,7 +1392,7 @@ WriteEntitiesToString(mbsp_t *bsp) /* FIXME - why are we printing this here? */ logprint("%i switchable light styles (%d max)\n", static_cast(lightstyleForTargetname.size()), - MAX_LIGHT_TARGETS); + MAX_SWITCHABLE_STYLES - cfg.compilerstyle_start.intValue()); bsp->entdatasize = entdata.size() + 1; // +1 for a null byte at the end bsp->dentdata = (char *) calloc(bsp->entdatasize, 1); diff --git a/light/light.cc b/light/light.cc index c48cefd1..c5150716 100644 --- a/light/light.cc +++ b/light/light.cc @@ -1238,7 +1238,7 @@ light_main(int argc, const char **argv) ExportObj(source, bsp); #endif - WriteEntitiesToString(bsp); + WriteEntitiesToString(cfg, bsp); /* Convert data format back if necessary */ ConvertBSPFormat(loadversion, &bspdata); WriteBSPFile(source, &bspdata);