diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index 7cd7c71e..4d8bfdc4 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -158,14 +158,14 @@ struct mapdata_t const std::string &miptexTextureName(int mt) const { return miptex.at(mt).name; } const std::string &texinfoTextureName(int texinfo) const { return miptexTextureName(mtexinfos.at(texinfo).miptex); } + + mapentity_t *world_entity(); }; extern mapdata_t map; void CalculateWorldExtent(void); -extern mapentity_t *pWorldEnt(); - bool ParseEntity(parser_t &parser, mapentity_t *entity); void EnsureTexturesLoaded(); diff --git a/qbsp/brush.cc b/qbsp/brush.cc index 5cb1a258..9a741d94 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -764,7 +764,7 @@ static void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int const mapbrush_t *mapbrush = &src->mapbrush(i); const contentflags_t contents = Brush_GetContents(mapbrush); if (contents.is_origin()) { - if (dst == pWorldEnt()) { + if (dst == map.world_entity()) { logging::print("WARNING: Ignoring origin brush in worldspawn\n"); continue; } @@ -911,7 +911,7 @@ static void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int } /* entities in some games never use water merging */ - if (dst != pWorldEnt() && !options.target_game->allow_contented_bmodels) { + if (dst != map.world_entity() && !options.target_game->allow_contented_bmodels) { contents = options.target_game->create_solid_contents(); /* Hack to turn bmodels with "_mirrorinside" into func_detail_fence in hull 0. @@ -969,7 +969,7 @@ static void Brush_LoadEntity(mapentity_t *dst, const mapentity_t *src, const int dst->bounds += brush->bounds; } - logging::percent(src->nummapbrushes, src->nummapbrushes, src == pWorldEnt()); + logging::percent(src->nummapbrushes, src->nummapbrushes, src == map.world_entity()); } /* @@ -990,7 +990,7 @@ brush_stats_t Brush_LoadEntity(mapentity_t *entity, const int hullnum) * If this is the world entity, find all func_group and func_detail * entities and add their brushes with the appropriate contents flag set. */ - if (entity == pWorldEnt()) { + if (entity == map.world_entity()) { /* * We no longer care about the order of adding func_detail and func_group, * Entity_SortBrushes will sort the brushes diff --git a/qbsp/globals.cc b/qbsp/globals.cc index 56c4066e..fccece31 100644 --- a/qbsp/globals.cc +++ b/qbsp/globals.cc @@ -28,7 +28,7 @@ mapdata_t map; // Useful shortcuts -mapentity_t *pWorldEnt() +mapentity_t *mapdata_t::world_entity() { - return &map.entities.at(0); + return &entities.at(0); } diff --git a/qbsp/map.cc b/qbsp/map.cc index 5e8d05c4..f8dd5e81 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -1909,7 +1909,7 @@ void LoadMapFile(void) logging::print(logging::flag::STAT, "\n"); if (options.expand.value()) { - TestExpandBrushes(pWorldEnt()); + TestExpandBrushes(map.world_entity()); } } diff --git a/qbsp/portals.cc b/qbsp/portals.cc index b0464981..17a843c4 100644 --- a/qbsp/portals.cc +++ b/qbsp/portals.cc @@ -627,7 +627,7 @@ void PortalizeWorld(const mapentity_t *entity, node_t *headnode, const int hulln MakeHeadnodePortals(entity, headnode); CutNodePortals_r(headnode, &state); - logging::percent(splitnodes, splitnodes, entity == pWorldEnt()); + logging::percent(splitnodes, splitnodes, entity == map.world_entity()); if (hullnum <= 0) { /* save portal file for vis tracing */ diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 163eeb46..b1ef3de8 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -586,7 +586,7 @@ static void ProcessEntity(mapentity_t *entity, const int hullnum) /* No map brushes means non-bmodel entity. We need to handle worldspawn containing no brushes, though. */ - if (!entity->nummapbrushes && entity != pWorldEnt()) + if (!entity->nummapbrushes && entity != map.world_entity()) return; /* @@ -602,8 +602,8 @@ static void ProcessEntity(mapentity_t *entity, const int hullnum) map.bsp.dmodels.emplace_back(); } - if (entity != pWorldEnt()) { - if (entity == pWorldEnt() + 1) + if (entity != map.world_entity()) { + if (entity == map.world_entity() + 1) logging::print(logging::flag::PROGRESS, "---- Internal Entities ----\n"); std::string mod = fmt::format("*{}", entity->outputmodelnumber.value()); @@ -652,7 +652,7 @@ static void ProcessEntity(mapentity_t *entity, const int hullnum) if (hullnum > 0) { nodes = SolidBSP(entity, true); - if (entity == pWorldEnt() && !options.nofill.value()) { + if (entity == map.world_entity() && !options.nofill.value()) { // assume non-world bmodels are simple PortalizeWorld(entity, nodes, hullnum); if (FillOutside(entity, nodes, hullnum)) { @@ -683,11 +683,11 @@ static void ProcessEntity(mapentity_t *entity, const int hullnum) if (options.forcegoodtree.value()) nodes = SolidBSP(entity, false); else - nodes = SolidBSP(entity, entity == pWorldEnt()); + nodes = SolidBSP(entity, entity == map.world_entity()); // build all the portals in the bsp tree // some portals are solid polygons, and some are paths to other leafs - if (entity == pWorldEnt()) { + if (entity == map.world_entity()) { // assume non-world bmodels are simple PortalizeWorld(entity, nodes, hullnum); @@ -730,7 +730,7 @@ static void ProcessEntity(mapentity_t *entity, const int hullnum) TJunc(entity, nodes); } - if (options.objexport.value() && entity == pWorldEnt()) { + if (options.objexport.value() && entity == map.world_entity()) { ExportObj_Nodes("pre_makefaceedges_plane_faces", nodes); ExportObj_Marksurfaces("pre_makefaceedges_marksurfaces", nodes); } @@ -935,7 +935,7 @@ static void BSPX_CreateBrushList(void) for (entnum = 0; entnum < map.numentities(); entnum++) { ent = &map.entities.at(entnum); - if (ent == pWorldEnt()) + if (ent == map.world_entity()) modelnum = 0; else { mod = ValueForKey(ent, "model"); @@ -1015,9 +1015,9 @@ void EnsureTexturesLoaded() wadlist_tried_loading = true; - const char *wadstring = ValueForKey(pWorldEnt(), "_wad"); + const char *wadstring = ValueForKey(map.world_entity(), "_wad"); if (!wadstring[0]) - wadstring = ValueForKey(pWorldEnt(), "wad"); + wadstring = ValueForKey(map.world_entity(), "wad"); if (!wadstring[0]) logging::print("WARNING: No wad or _wad key exists in the worldmodel\n"); else diff --git a/qbsp/solidbsp.cc b/qbsp/solidbsp.cc index dfff6a29..bd61c853 100644 --- a/qbsp/solidbsp.cc +++ b/qbsp/solidbsp.cc @@ -968,7 +968,7 @@ node_t *SolidBSP(mapentity_t *entity, bool midsplit) } PartitionBrushes(std::move(brushcopies), headnode); - //logging::percent(csgmergefaces, csgmergefaces, entity == pWorldEnt()); + //logging::percent(csgmergefaces, csgmergefaces, entity == map.pWorldEnt()); logging::print(logging::flag::STAT, " {:8} split nodes\n", splitnodes.load()); logging::print(logging::flag::STAT, " {:8} solid leafs\n", c_solid.load()); diff --git a/qbsp/surfaces.cc b/qbsp/surfaces.cc index b9bd0b52..ef3d7993 100644 --- a/qbsp/surfaces.cc +++ b/qbsp/surfaces.cc @@ -463,7 +463,7 @@ int MakeFaceEdges(mapentity_t *entity, node_t *headnode) firstface = static_cast(map.bsp.dfaces.size()); MakeFaceEdges_r(entity, headnode, 0); - logging::percent(splitnodes, splitnodes, entity == pWorldEnt()); + logging::percent(splitnodes, splitnodes, entity == map.world_entity()); pEdgeFaces0.clear(); pEdgeFaces1.clear();