From d7ba0330a6986c487027da08edac8c98863c363c Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sat, 10 Sep 2016 10:10:06 -0600 Subject: [PATCH] light: restore "unmatched target" warning --- light/entities.cc | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/light/entities.cc b/light/entities.cc index 3de1af5f..a418a303 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -98,6 +98,8 @@ LightStyleForTargetname(const std::string &targetname) * ================== * MatchTargets * + * sets light_t.targetent + * * entdicts should not be modified after this (saves pointers to elements) * ================== */ @@ -117,11 +119,33 @@ MatchTargets(void) break; } } - if (!found) { - logprint("WARNING: entity at (%s) (%s) has unmatched " - "target (%s)\n", VecStr(*entity.origin.vec3Value()), - entity.classname(), ValueForKey(&entity, "target")); + } +} + +/** + * Checks `entdicts` for unmatched targets and prints warnings + */ +static void +CheckTargets(void) +{ + for (entdict_t &entity : entdicts) { + const auto targetstr = EntDict_StringForKey(entity, "target"); + if (!targetstr.length()) continue; + + bool found = false; + for (const entdict_t &target : entdicts) { + if (targetstr == EntDict_StringForKey(target, "targetname")) { + found = true; + break; + } + } + + if (!found) { + logprint("WARNING: entity at (%s) (%s) has unmatched target (%s)\n", + EntDict_StringForKey(entity, "origin").c_str(), + EntDict_StringForKey(entity, "classname").c_str(), + EntDict_StringForKey(entity, "target").c_str()); } } } @@ -830,6 +854,8 @@ LoadEntities(const globalconfig_t &cfg, const bsp2_t *bsp) } } + CheckTargets(); + // First pass: make permanent changes to the bsp entdata that we will write out // at the end of the light process. for (auto &entdict : entdicts) {