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