light: use entdicts array for FIndModelInfo
This commit is contained in:
parent
d8094c83e5
commit
ca507336ca
|
|
@ -30,6 +30,8 @@
|
||||||
|
|
||||||
#define DEFAULTLIGHTLEVEL 300.0f
|
#define DEFAULTLIGHTLEVEL 300.0f
|
||||||
|
|
||||||
|
using entdict_t = std::map<std::string, std::string>;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Light attenuation formalae
|
* Light attenuation formalae
|
||||||
* (relative to distance 'x' from the light source)
|
* (relative to distance 'x' from the light source)
|
||||||
|
|
@ -146,10 +148,13 @@ public:
|
||||||
#define MAX_LIGHTS 65536
|
#define MAX_LIGHTS 65536
|
||||||
extern entity_t *lights[MAX_LIGHTS];
|
extern entity_t *lights[MAX_LIGHTS];
|
||||||
|
|
||||||
entity_t *FindEntityWithKeyPair(const char *key, const char *value);
|
const entdict_t *FindEntDictWithKeyPair(const std::string &key, const std::string &value);
|
||||||
const char *ValueForKey(const entity_t *ent, const char *key);
|
const char *ValueForKey(const entity_t *ent, const char *key);
|
||||||
void GetVectorForKey(const entity_t *ent, const char *key, vec3_t vec);
|
void GetVectorForKey(const entity_t *ent, const char *key, vec3_t vec);
|
||||||
|
|
||||||
|
std::string EntDict_StringForKey(const entdict_t &dict, const std::string key);
|
||||||
|
float EntDict_FloatForKey(const entdict_t &dict, const std::string key);
|
||||||
|
|
||||||
void SetWorldKeyValue(const char *key, const char *value);
|
void SetWorldKeyValue(const char *key, const char *value);
|
||||||
const char *WorldValueForKey(const char *key);
|
const char *WorldValueForKey(const char *key);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ int num_surfacelight_templates;
|
||||||
static void MakeSurfaceLights(const bsp2_t *bsp);
|
static void MakeSurfaceLights(const bsp2_t *bsp);
|
||||||
|
|
||||||
using strings = std::vector<std::string>;
|
using strings = std::vector<std::string>;
|
||||||
using entdict_t = std::map<std::string, std::string>;
|
|
||||||
|
|
||||||
std::vector<entdict_t> entdicts;
|
std::vector<entdict_t> entdicts;
|
||||||
|
|
||||||
|
|
@ -891,7 +890,7 @@ EntData_Write(const std::vector<entdict_t> &ents)
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string
|
std::string
|
||||||
EntDict_StringForKey(const entdict_t &dict, const std::string key)
|
EntDict_StringForKey(const entdict_t &dict, const std::string key)
|
||||||
{
|
{
|
||||||
auto it = dict.find(key);
|
auto it = dict.find(key);
|
||||||
|
|
@ -901,7 +900,7 @@ EntDict_StringForKey(const entdict_t &dict, const std::string key)
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static float
|
float
|
||||||
EntDict_FloatForKey(const entdict_t &dict, const std::string key)
|
EntDict_FloatForKey(const entdict_t &dict, const std::string key)
|
||||||
{
|
{
|
||||||
auto s = EntDict_StringForKey(dict, key);
|
auto s = EntDict_StringForKey(dict, key);
|
||||||
|
|
@ -1164,21 +1163,14 @@ ValueForKey(const entity_t *ent, const char *key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entity_t *
|
const entdict_t *FindEntDictWithKeyPair(const std::string &key, const std::string &value)
|
||||||
FindEntityWithKeyPair(const char *key, const char *value)
|
|
||||||
{
|
{
|
||||||
entity_t *ent;
|
for (const auto &entdict : entdicts) {
|
||||||
std::string value_stdstring { value };
|
if (EntDict_StringForKey(entdict, key) == value) {
|
||||||
|
return &entdict;
|
||||||
for (ent = entities; ent; ent = ent->next) {
|
|
||||||
auto iter = ent->epairs.find(key);
|
|
||||||
if (iter != ent->epairs.end()) {
|
|
||||||
if ((*iter).second == value_stdstring) {
|
|
||||||
return ent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -330,7 +330,6 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
|
||||||
{
|
{
|
||||||
int i, numshadowmodels, numselfshadowmodels;
|
int i, numshadowmodels, numselfshadowmodels;
|
||||||
entity_t *entity;
|
entity_t *entity;
|
||||||
char modelname[20];
|
|
||||||
const char *attribute;
|
const char *attribute;
|
||||||
const modelinfo_t **shadowmodels;
|
const modelinfo_t **shadowmodels;
|
||||||
const modelinfo_t **selfshadowmodels;
|
const modelinfo_t **selfshadowmodels;
|
||||||
|
|
@ -382,14 +381,17 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
|
||||||
info.lightmapscale = lightmapscale;
|
info.lightmapscale = lightmapscale;
|
||||||
|
|
||||||
/* Find the entity for the model */
|
/* Find the entity for the model */
|
||||||
snprintf(modelname, sizeof(modelname), "*%d", i);
|
std::stringstream ss;
|
||||||
entity = FindEntityWithKeyPair("model", modelname);
|
ss << "*" << i;
|
||||||
if (!entity)
|
std::string modelname = ss.str();
|
||||||
|
|
||||||
|
const entdict_t *entdict = FindEntDictWithKeyPair("model", modelname);
|
||||||
|
if (entdict == nullptr)
|
||||||
Error("%s: Couldn't find entity for model %s.\n", __func__,
|
Error("%s: Couldn't find entity for model %s.\n", __func__,
|
||||||
modelname);
|
modelname.c_str());
|
||||||
|
|
||||||
// apply settings
|
// apply settings
|
||||||
info.settings.setSettings(entity->epairs, false);
|
info.settings.setSettings(*entdict, false);
|
||||||
|
|
||||||
/* Check if this model will cast shadows (shadow => shadowself) */
|
/* Check if this model will cast shadows (shadow => shadowself) */
|
||||||
if (info.shadow.boolValue()) {
|
if (info.shadow.boolValue()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue