common: add convenience version of EntData_Parse

This commit is contained in:
Eric Wasylishen 2023-01-30 00:08:45 -07:00
parent e722ff14c9
commit 9edad10b0f
8 changed files with 15 additions and 14 deletions

1
.gitignore vendored
View File

@ -30,3 +30,4 @@ testmaps/quake_map_source/*.bsp.json
**/autosave
CMakeSettings.json
sphinx-venv
*-env

View File

@ -1294,8 +1294,7 @@ static void DecompileEntity(
void DecompileBSP(const mbsp_t *bsp, const decomp_options &options, std::ofstream &file)
{
parser_t parser{bsp->dentdata, { bsp->file.string() }};
auto entdicts = EntData_Parse(parser);
auto entdicts = EntData_Parse(*bsp);
for (size_t i = 0; i < entdicts.size(); ++i) {
// entity 0 is implicitly worldspawn (model 0)

View File

@ -204,6 +204,12 @@ std::vector<entdict_t> EntData_Parse(parser_t &parser)
return result;
}
std::vector<entdict_t> EntData_Parse(const mbsp_t &bsp)
{
parser_t parser{bsp.dentdata, { bsp.file.string() }};
return EntData_Parse(parser);
}
/*
* ================
* EntData_Write

View File

@ -78,5 +78,7 @@ void EntData_ParseInto(parser_t &parser, std::vector<entdict_t> &vector);
* ==================
*/
std::vector<entdict_t> EntData_Parse(parser_t &parser);
struct mbsp_t;
std::vector<entdict_t> EntData_Parse(const mbsp_t &bsp);
std::string EntData_Write(const std::vector<entdict_t> &ents);

View File

@ -866,10 +866,7 @@ void LoadEntities(const settings::worldspawn_keys &cfg, const mbsp_t *bsp)
{
logging::funcheader();
{
parser_t parser{bsp->dentdata, { bsp->file.string() }};
entdicts = EntData_Parse(parser);
}
entdicts = EntData_Parse(*bsp);
// Make warnings
for (auto &entdict : entdicts) {

View File

@ -1434,8 +1434,7 @@ static void LoadTextures(const mbsp_t *bsp)
// gather textures used by _project_texture.
// FIXME: I'm sure we can resolve this so we don't parse entdata twice.
parser_t parser{bsp->dentdata, { bsp->file.string() }};
auto entdicts = EntData_Parse(parser);
auto entdicts = EntData_Parse(*bsp);
for (auto &entdict : entdicts) {
if (entdict.get("classname").find("light") == 0) {
const auto &tex = entdict.get("_project_texture");

View File

@ -1011,8 +1011,7 @@ TEST_CASE("origin" * doctest::test_suite("testmaps_q1"))
REQUIRE(qvec3f(0, 0, 0) == bsp.dmodels[1].origin);
// check that the origin brush updated the entity lump
parser_t parser(bsp.dentdata, {"qbsp_origin.bsp"});
auto ents = EntData_Parse(parser);
auto ents = EntData_Parse(bsp);
auto it = std::find_if(ents.begin(), ents.end(),
[](const entdict_t &dict) -> bool { return dict.get("classname") == "rotate_object"; });
@ -1381,8 +1380,7 @@ TEST_CASE("q1_merge_maps" * doctest::test_suite("testmaps_q1")) {
REQUIRE(BSP_FindFaceAtPoint(&bsp, &bsp.dmodels[0], {-5,0,16}, {0, 0, 1}));
// check that the worldspawn keys from the base map are used
parser_t parser(bsp.dentdata, { "q1_merge_maps_base.bsp" });
auto ents = EntData_Parse(parser);
auto ents = EntData_Parse(bsp);
REQUIRE(ents.size() == 3); // worldspawn, info_player_start, func_wall
REQUIRE(ents[0].get("classname") == "worldspawn");

View File

@ -210,8 +210,7 @@ TEST_CASE("areaportal" * doctest::test_suite("testmaps_q2"))
CHECK(0 == void_leaf->area); // a solid leaf gets the invalid area
// check the func_areaportal entity had its "style" set
parser_t parser(bsp.dentdata, { "qbsp_q2_areaportal.bsp" });
auto ents = EntData_Parse(parser);
auto ents = EntData_Parse(bsp);
auto it = std::find_if(ents.begin(), ents.end(),
[](const entdict_t &dict) { return dict.get("classname") == "func_areaportal"; });