From b46cba40a4961462b335e612178114069344916e Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 24 Nov 2016 17:10:15 -0700 Subject: [PATCH] light: entity warnings: print bbox for bmodel entities fixes https://github.com/ericwa/tyrutils-ericw/issues/120 --- common/bsputils.cc | 15 ++++++++++++++ include/common/bsputils.hh | 2 ++ include/light/entities.hh | 6 +++--- light/entities.cc | 42 ++++++++++++++++++++++++++++---------- light/test_entities.cc | 26 +++++++++++------------ 5 files changed, 64 insertions(+), 27 deletions(-) diff --git a/common/bsputils.cc b/common/bsputils.cc index 87cc79ba..d2230948 100644 --- a/common/bsputils.cc +++ b/common/bsputils.cc @@ -126,3 +126,18 @@ Face_Contents(const bsp2_t *bsp, const bsp2_dface_t *face) const char *texname = Face_TextureName(bsp, face); return TextureName_Contents(texname); } + +const dmodel_t *BSP_DModelForModelString(const bsp2_t *bsp, const std::string &submodel_str) +{ + int submodel = -1; + if (1 == sscanf(submodel_str.c_str(), "*%d", &submodel)) { + + if (submodel < 0 || submodel >= bsp->nummodels) { + return nullptr; + } + + return &bsp->dmodels[submodel]; + + } + return nullptr; +} diff --git a/include/common/bsputils.hh b/include/common/bsputils.hh index 8c383000..5f37152d 100644 --- a/include/common/bsputils.hh +++ b/include/common/bsputils.hh @@ -22,6 +22,7 @@ #include #include +#include int Face_GetNum(const bsp2_t *bsp, const bsp2_dface_t *f); int Face_VertexAtIndex(const bsp2_t *bsp, const bsp2_dface_t *f, int v); @@ -32,5 +33,6 @@ const char *Face_TextureName(const bsp2_t *bsp, const bsp2_dface_t *face); const float *GetSurfaceVertexPoint(const bsp2_t *bsp, const bsp2_dface_t *f, int v); int TextureName_Contents(const char *texname); int Face_Contents(const bsp2_t *bsp, const bsp2_dface_t *face); +const dmodel_t *BSP_DModelForModelString(const bsp2_t *bsp, const std::string &submodel_str); #endif /* __COMMON_BSPUTILS_HH__ */ diff --git a/include/light/entities.hh b/include/light/entities.hh index d4017df4..27c5835e 100644 --- a/include/light/entities.hh +++ b/include/light/entities.hh @@ -173,10 +173,10 @@ bool Light_PointInSolid(const bsp2_t *bsp, const vec3_t point ); void EstimateVisibleBoundsAtPoint(const vec3_t point, vec3_t mins, vec3_t maxs); -bool EntDict_CheckNoEmptyValues(const entdict_t &entdict); +bool EntDict_CheckNoEmptyValues(const bsp2_t *bsp, const entdict_t &entdict); -bool EntDict_CheckTargetKeysMatched(const entdict_t &entity, const std::vector &all_edicts); +bool EntDict_CheckTargetKeysMatched(const bsp2_t *bsp, const entdict_t &entity, const std::vector &all_edicts); -bool EntDict_CheckTargetnameKeyMatched(const entdict_t &entity, const std::vector &all_edicts); +bool EntDict_CheckTargetnameKeyMatched(const bsp2_t *bsp, const entdict_t &entity, const std::vector &all_edicts); #endif /* __LIGHT_ENTITIES_H__ */ diff --git a/light/entities.cc b/light/entities.cc index dd67230a..9199e92f 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -156,8 +156,28 @@ MatchTargets(void) } static std::string -EntDict_PrettyDescription(const entdict_t &entity) +EntDict_PrettyDescription(const bsp2_t *bsp, const entdict_t &entity) { + // get the submodel's bbox if it's a brush entity + if (bsp != nullptr + && EntDict_StringForKey(entity, "origin") == "" + && EntDict_StringForKey(entity, "model") != "") { + + const std::string submodel_str = EntDict_StringForKey(entity, "model"); + const dmodel_t *info = BSP_DModelForModelString(bsp, submodel_str); + + if (info) { + std::stringstream s; + s << "brush entity with mins ("; + s << VecStrf(info->mins); + s << ") maxs ("; + s << VecStrf(info->maxs); + s << ") (" << + EntDict_StringForKey(entity, "classname") << ")"; + return s.str(); + } + } + std::stringstream s; s << "entity at (" << EntDict_StringForKey(entity, "origin") << ") (" << @@ -166,14 +186,14 @@ EntDict_PrettyDescription(const entdict_t &entity) } bool -EntDict_CheckNoEmptyValues(const entdict_t &entdict) +EntDict_CheckNoEmptyValues(const bsp2_t *bsp, const entdict_t &entdict) { bool ok = true; // empty values warning for (const auto &keyval : entdict) { if (keyval.first.empty() || keyval.second.empty()) { logprint("WARNING: %s has empty key/value \"%s\" \"%s\"\n", - EntDict_PrettyDescription(entdict).c_str(), + EntDict_PrettyDescription(bsp, entdict).c_str(), keyval.first.c_str(), keyval.second.c_str()); ok = false; } @@ -185,7 +205,7 @@ EntDict_CheckNoEmptyValues(const entdict_t &entdict) * Checks `edicts` for unmatched targets/targetnames and prints warnings */ bool -EntDict_CheckTargetKeysMatched(const entdict_t &entity, const std::vector &all_edicts) +EntDict_CheckTargetKeysMatched(const bsp2_t *bsp, const entdict_t &entity, const std::vector &all_edicts) { bool ok = true; @@ -205,7 +225,7 @@ EntDict_CheckTargetKeysMatched(const entdict_t &entity, const std::vector &all_edicts) +EntDict_CheckTargetnameKeyMatched(const bsp2_t *bsp, const entdict_t &entity, const std::vector &all_edicts) { // search for "targetname" values such that no entity has a matching "target" // accept any key name as a target, so we don't print false positive @@ -266,7 +286,7 @@ EntDict_CheckTargetnameKeyMatched(const entdict_t &entity, const std::vector