From 70f015a36c8082d08be60a767530a9151515fcaf Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 10 Aug 2022 00:48:55 -0400 Subject: [PATCH] move func_areaportal and lmshift from bspbrush_t to mapbrush_t --- include/qbsp/brush.hh | 2 -- include/qbsp/map.hh | 4 ++++ qbsp/brush.cc | 22 ++-------------------- qbsp/brushbsp.cc | 2 -- qbsp/map.cc | 22 ++++++++++++++++++++++ qbsp/portals.cc | 4 ++-- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/include/qbsp/brush.hh b/include/qbsp/brush.hh index 1ed37dbc..7aa711df 100644 --- a/include/qbsp/brush.hh +++ b/include/qbsp/brush.hh @@ -67,8 +67,6 @@ struct bspbrush_t int side, testside; // side of node during construction std::vector sides; contentflags_t contents; /* BSP contents */ - short lmshift; /* lightmap scaling (qu/lightmap pixel), passed to the light util */ - mapentity_t *func_areaportal; qvec3d sphere_origin; double sphere_radius; diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index f6c9573e..82c0c82a 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -73,6 +73,8 @@ enum class brushformat_t BRUSH_PRIMITIVES }; +class mapentity_t; + class mapbrush_t { public: @@ -82,6 +84,8 @@ public: std::optional outputnumber; /* only set for original brushes */ parser_source_location line; contentflags_t contents {}; + short lmshift = 0; /* lightmap scaling (qu/lightmap pixel), passed to the light util */ + mapentity_t *func_areaportal = nullptr; }; struct lumpdata diff --git a/qbsp/brush.cc b/qbsp/brush.cc index ad3f6b99..9f29ec0b 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -355,8 +355,6 @@ static void Brush_LoadEntity(mapentity_t *dst, mapentity_t *src, const int hulln return; } - int i; - int lmshift; bool all_detail, all_detail_fence, all_detail_illusionary; const std::string &classname = src->epairs.get("classname"); @@ -379,16 +377,6 @@ static void Brush_LoadEntity(mapentity_t *dst, mapentity_t *src, const int hulln } } - /* entities with custom lmscales are important for the qbsp to know about */ - i = 16 * src->epairs.get_float("_lmscale"); - if (!i) - i = 16; // if 0, pick a suitable default - lmshift = 0; - while (i > 1) { - lmshift++; // only allow power-of-two scales - i /= 2; - } - /* _mirrorinside key (for func_water etc.) */ std::optional mirrorinside; @@ -406,7 +394,7 @@ static void Brush_LoadEntity(mapentity_t *dst, mapentity_t *src, const int hulln const bool func_illusionary_visblocker = (0 == Q_strcasecmp(classname, "func_illusionary_visblocker")); auto it = src->mapbrushes.begin(); - for (i = 0; i < src->mapbrushes.size(); i++, it++) { + for (size_t i = 0; i < src->mapbrushes.size(); i++, it++) { logging::percent(i, src->mapbrushes.size()); auto &mapbrush = *it; contentflags_t contents = mapbrush.contents; @@ -510,14 +498,8 @@ static void Brush_LoadEntity(mapentity_t *dst, mapentity_t *src, const int hulln continue; } - brush->lmshift = lmshift; - for (auto &face : brush->sides) { - face.lmshift = lmshift; - } - - if (classname == std::string_view("func_areaportal")) { - brush->func_areaportal = const_cast(src); // FIXME: get rid of consts on src in the callers? + face.lmshift = mapbrush.lmshift; } qbsp_options.target_game->count_contents_in_stats(brush->contents, stats); diff --git a/qbsp/brushbsp.cc b/qbsp/brushbsp.cc index b70571cd..9da938c2 100644 --- a/qbsp/brushbsp.cc +++ b/qbsp/brushbsp.cc @@ -494,8 +494,6 @@ static twosided> SplitBrush(std::unique_ptroriginal = brush->original; // fixme-brushbsp: add a bspbrush_t copy constructor to make sure we get all fields result[i]->contents = brush->contents; - result[i]->lmshift = brush->lmshift; - result[i]->func_areaportal = brush->func_areaportal; result[i]->sides.reserve(brush->sides.size() + 1); } diff --git a/qbsp/map.cc b/qbsp/map.cc index 44732d81..5a31e744 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -2268,9 +2268,31 @@ void ProcessMapBrushes() /* Origin brush support */ entity.rotation = rotation_t::none; + + /* entities with custom lmscales are important for the qbsp to know about */ + int i = 16 * entity.epairs.get_float("_lmscale"); + if (!i) { + i = 16; // if 0, pick a suitable default + } + int lmshift = 0; + while (i > 1) { + lmshift++; // only allow power-of-two scales + i /= 2; + } + + mapentity_t *areaportal = nullptr; + + if (entity.epairs.get("classname") == "func_areaportal") { + areaportal = &entity; + } + for (auto it = entity.mapbrushes.begin(); it != entity.mapbrushes.end(); ) { auto &brush = *it; + // set properties calculated above + brush.lmshift = lmshift; + brush.func_areaportal = areaportal; + // calculate brush bounds CalculateBrushBounds(brush); diff --git a/qbsp/portals.cc b/qbsp/portals.cc index 060a06b8..6226916d 100644 --- a/qbsp/portals.cc +++ b/qbsp/portals.cc @@ -573,8 +573,8 @@ static mapentity_t *AreanodeEntityForLeaf(node_t *node) } for (auto &brush : node->original_brushes) { - if (brush->func_areaportal) { - return brush->func_areaportal; + if (brush->mapbrush->func_areaportal) { + return brush->mapbrush->func_areaportal; } } return nullptr;