From 18797f81c0c5a29307309d6d484cd38cb5ffa23c Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 8 Sep 2016 15:21:18 -0600 Subject: [PATCH] light: fix for -dirt not implying -minlight_dirt, -sunlight_dirt, -sunlight2_dirt --- include/light/light.hh | 1 + light/entities.cc | 2 ++ light/light.cc | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/include/light/light.hh b/include/light/light.hh index fb5cdd1f..2879a28d 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -388,6 +388,7 @@ extern char mapfilename[1024]; lockable_setting_t *FindSetting(std::string name); void SetGlobalSetting(std::string name, std::string value, bool cmdline); +void FixupGlobalSettings(void); void GetFileSpace(byte **lightdata, byte **colordata, byte **deluxdata, int size); const modelinfo_t *ModelInfoForFace(const bsp2_t *bsp, int facenum); const vec_t *GetSurfaceVertexNormal(const bsp2_t *bsp, const bsp2_dface_t *f, const int v); diff --git a/light/entities.cc b/light/entities.cc index 869851f6..3de1af5f 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -864,6 +864,8 @@ LoadEntities(const globalconfig_t &cfg, const bsp2_t *bsp) for (const auto &epair : WorldEnt()) { SetGlobalSetting(epair.first, epair.second, false); } + /* apply side effects of settings (in particular "dirt") */ + FixupGlobalSettings(); assert(all_lights.size() == 0); if (nolights) { diff --git a/light/light.cc b/light/light.cc index 50fec2c0..89ababeb 100644 --- a/light/light.cc +++ b/light/light.cc @@ -110,6 +110,31 @@ void SetGlobalSetting(std::string name, std::string value, bool cmdline) { sd.setSetting(name, value, cmdline); } +void FixupGlobalSettings() { + static bool once = false; + assert(!once); + once = true; + + // NOTE: This is confusing.. Setting "dirt" "1" implies "minlight_dirt" "1" + // (and sunlight_dir/sunlight2_dirt as well), unless those variables were + // set by the user to "0". + // + // We can't just default "minlight_dirt" to "1" because that would enable + // dirtmapping by default. + + if (cfg_static.globalDirt.boolValue()) { + if (!cfg_static.minlightDirt.isChanged()) { + cfg_static.minlightDirt.setBoolValue(true); + } + if (!cfg_static.sunlight_dirt.isChanged()) { + cfg_static.sunlight_dirt.setFloatValue(1); + } + if (!cfg_static.sunlight2_dirt.isChanged()) { + cfg_static.sunlight2_dirt.setFloatValue(1); + } + } +} + static void PrintOptionsSummary(void) {