light: allow starting assigning switchable styles before default of 32
This commit is contained in:
parent
cf66248261
commit
b132152891
|
|
@ -29,8 +29,6 @@
|
|||
#include <light/light.hh>
|
||||
|
||||
#define DEFAULTLIGHTLEVEL 300.0f
|
||||
#define LIGHT_TARGETS_START 32
|
||||
#define MAX_LIGHT_TARGETS 32
|
||||
|
||||
using entdict_t = std::map<std::string, std::string>;
|
||||
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -271,6 +271,7 @@ 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?
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -60,10 +60,7 @@ const char * light_t::classname() const {
|
|||
|
||||
static std::vector<std::pair<std::string, int>> 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)
|
|||
}
|
||||
}
|
||||
|
||||
// generate a new style number and return it
|
||||
const int newStylenum = cfg.compilerstyle_start.intValue() + lightstyleForTargetname.size();
|
||||
|
||||
// check if full
|
||||
if (lightstyleForTargetname.size() == MAX_LIGHT_TARGETS) {
|
||||
Error("%s: Too many unique light targetnames\n", __func__);
|
||||
if (newStylenum >= MAX_SWITCHABLE_STYLES) {
|
||||
Error("%s: Too many unique light targetnames (max=%d)\n", __func__, MAX_SWITCHABLE_STYLES);
|
||||
}
|
||||
|
||||
// generate a new style number and return it
|
||||
const int newStylenum = LIGHT_TARGETS_START + lightstyleForTargetname.size();
|
||||
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<int>(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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue