From 1548f25daff98841652b20c8232970c18bc2c0ac Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 8 May 2023 17:44:32 -0400 Subject: [PATCH] allow individual brush chop control allow passing _surflight_targetname to set targetnames for switchable lights on bmodels --- common/bspfile.cc | 2 +- include/common/bspfile.hh | 3 +++ include/qbsp/map.hh | 1 + light/entities.cc | 2 +- light/light.cc | 3 +++ light/surflight.cc | 6 +++++- qbsp/brushbsp.cc | 8 ++++++++ qbsp/map.cc | 10 ++++++++++ qbsp/portals.cc | 11 ++++++++--- qbsp/writebsp.cc | 3 +++ 10 files changed, 43 insertions(+), 6 deletions(-) diff --git a/common/bspfile.cc b/common/bspfile.cc index befe4f04..a6e0c5eb 100644 --- a/common/bspfile.cc +++ b/common/bspfile.cc @@ -1803,7 +1803,7 @@ static auto as_tuple(const surfflags_t &flags) { return std::tie(flags.native, flags.is_nodraw, flags.is_hintskip, flags.is_hint, flags.no_dirt, flags.no_shadow, flags.no_bounce, flags.no_minlight, flags.no_expand, flags.no_phong, flags.light_ignore, - flags.surflight_rescale, flags.surflight_style, flags.surflight_color, flags.surflight_minlight_scale, flags.phong_angle, flags.phong_angle_concave, flags.phong_group, flags.minlight, + flags.surflight_rescale, flags.surflight_style, flags.surflight_targetname, flags.surflight_color, flags.surflight_minlight_scale, flags.phong_angle, flags.phong_angle_concave, flags.phong_group, flags.minlight, flags.minlight_color, flags.light_alpha, flags.maxlight, flags.lightcolorscale, flags.surflight_group, flags.world_units_per_luxel, flags.object_channel_mask); } diff --git a/include/common/bspfile.hh b/include/common/bspfile.hh index df4f3d92..0f3be82c 100644 --- a/include/common/bspfile.hh +++ b/include/common/bspfile.hh @@ -195,6 +195,9 @@ struct surfflags_t // override surface lighting style std::optional surflight_style; + // override surface lighting targetname + std::optional surflight_targetname; + // override the textures' surflight color std::optional surflight_color; diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index f3927c9e..7130e3a8 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -107,6 +107,7 @@ public: int16_t lmshift = 0; /* lightmap scaling (qu/lightmap pixel), passed to the light util */ mapentity_t *func_areaportal = nullptr; bool is_hint = false; // whether we are a hint brush or not (at least one side is "hint" or SURF_HINT) + bool no_chop = false; // don't chop this }; struct lumpdata diff --git a/light/entities.cc b/light/entities.cc index e66236ef..ce860d34 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -160,7 +160,7 @@ entdict_t &WorldEnt() * * Pass an empty string to generate a new unique lightstyle. */ -static int LightStyleForTargetname(const settings::worldspawn_keys &cfg, const std::string &targetname) +int LightStyleForTargetname(const settings::worldspawn_keys &cfg, const std::string &targetname) { // check if already assigned for (const auto &pr : lightstyleForTargetname) { diff --git a/light/light.cc b/light/light.cc index 351fe15b..f8008788 100644 --- a/light/light.cc +++ b/light/light.cc @@ -1123,6 +1123,9 @@ static void LoadExtendedTexinfoFlags(const fs::path &sourcefilename, const mbsp_ if (val.contains("surflight_style")) { flags.surflight_style = val.at("surflight_style").get(); } + if (val.contains("surflight_targetname")) { + flags.surflight_targetname = val.at("surflight_targetname").get(); + } if (val.contains("surflight_color")) { flags.surflight_color = val.at("surflight_color").get(); } diff --git a/light/surflight.cc b/light/surflight.cc index 259524ea..5eeb2e9a 100644 --- a/light/surflight.cc +++ b/light/surflight.cc @@ -59,6 +59,8 @@ size_t GetSurflightPoints() return total_surflight_points; } +int LightStyleForTargetname(const settings::worldspawn_keys &cfg, const std::string &targetname); + static void MakeSurfaceLight(const mbsp_t *bsp, const settings::worldspawn_keys &cfg, const mface_t *face, std::optional texture_color, bool is_directional, bool is_sky, int32_t style, int32_t light_value) { @@ -138,7 +140,9 @@ static void MakeSurfaceLight(const mbsp_t *bsp, const settings::worldspawn_keys l.surfnormal = facenormal; l.omnidirectional = !is_directional; l.points = std::move(points); - if (extended_flags.surflight_style) { + if (extended_flags.surflight_targetname) { + l.style = LightStyleForTargetname(cfg, extended_flags.surflight_targetname.value()); + } else if (extended_flags.surflight_style) { l.style = extended_flags.surflight_style.value(); } else { l.style = style; diff --git a/qbsp/brushbsp.cc b/qbsp/brushbsp.cc index bb4509ab..1e4c3210 100644 --- a/qbsp/brushbsp.cc +++ b/qbsp/brushbsp.cc @@ -1434,9 +1434,17 @@ newlist: auto &b1 = *b1_it; + if (b1->mapbrush->no_chop) { + continue; + } + for (auto b2_it = next; b2_it != list.end(); b2_it++) { auto &b2 = *b2_it; + if (b2->mapbrush->no_chop) { + continue; + } + if (BrushesDisjoint(*b1, *b2)) { continue; } diff --git a/qbsp/map.cc b/qbsp/map.cc index a9e9ea3e..4c648aa2 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -677,6 +677,8 @@ static surfflags_t SurfFlagsForEntity( } if (entity.epairs.has("_surflight_style") && entity.epairs.get_int("_surflight_style") != 0) flags.surflight_style = entity.epairs.get_int("_surflight_style"); + if (entity.epairs.has("_surflight_targetname")) + flags.surflight_targetname = entity.epairs.get("_surflight_targetname"); if (entity.epairs.has("_surflight_minlight_scale")) flags.surflight_minlight_scale = entity.epairs.get_float("_surflight_minlight_scale"); @@ -2931,6 +2933,10 @@ void ProcessAreaPortal(mapentity_t &entity) } } + if (map.antiregions.size() || map.region) { + return; + } + entity.areaportalnum = ++map.numareaportals; // set the portal number as "style" entity.epairs.set("style", std::to_string(map.numareaportals)); @@ -3114,6 +3120,10 @@ void ProcessMapBrushes() brush.func_areaportal = areaportal; brush.is_hint = MapBrush_IsHint(brush); + if (entity.epairs.has("_chop") && !entity.epairs.get_int("_chop")) { + brush.no_chop = true; + } + // calculate brush bounds CalculateBrushBounds(brush); diff --git a/qbsp/portals.cc b/qbsp/portals.cc index 82663e36..f7c33593 100644 --- a/qbsp/portals.cc +++ b/qbsp/portals.cc @@ -410,7 +410,7 @@ static void CalcTreeBounds_r(node_t *node, logging::percent_clock &clock) } if (node->bounds.mins()[0] >= node->bounds.maxs()[0]) { - logging::print("WARNING: {} without a volume\n", node->is_leaf ? "leaf" : "node"); + //logging::print("WARNING: {} without a volume\n", node->is_leaf ? "leaf" : "node"); // fixme-brushbsp: added this to work around leafs with no portals showing up in "qbspfeatures.map" among other // test maps. Not sure if correct or there's another underlying problem. @@ -615,8 +615,8 @@ static void FloodAreas_r(node_t *node) // note the current area as bounding the portal if (entity->portalareas[1]) { - logging::print("WARNING: areaportal entity {} touches > 2 areas\n Entity Bounds: {} -> {}\n", - entity - map.entities.data(), entity->bounds.mins(), entity->bounds.maxs()); + logging::print("WARNING: {}: areaportal touches > 2 areas\n Entity Bounds: {} -> {}\n", + entity->location, entity->bounds.mins(), entity->bounds.maxs()); return; } @@ -924,6 +924,11 @@ void EmitAreaPortals(node_t *headnode) return; } + if (map.antiregions.size() || map.region) { + map.bsp.dareas.emplace_back(); + return; + } + FindAreas_r(headnode); SetAreaPortalAreas_r(headnode); diff --git a/qbsp/writebsp.cc b/qbsp/writebsp.cc index 305d1c79..dbd107de 100644 --- a/qbsp/writebsp.cc +++ b/qbsp/writebsp.cc @@ -387,6 +387,9 @@ static void WriteExtendedTexinfoFlags(void) if (tx.flags.surflight_style.has_value()) { t["surflight_style"] = tx.flags.surflight_style.value(); } + if (tx.flags.surflight_targetname.has_value()) { + t["surflight_targetname"] = tx.flags.surflight_targetname.value(); + } if (tx.flags.surflight_color.has_value()) { t["surflight_color"] = tx.flags.surflight_color.value(); }