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