common: add convenience version of EntData_Parse
This commit is contained in:
parent
e722ff14c9
commit
9edad10b0f
|
|
@ -30,3 +30,4 @@ testmaps/quake_map_source/*.bsp.json
|
||||||
**/autosave
|
**/autosave
|
||||||
CMakeSettings.json
|
CMakeSettings.json
|
||||||
sphinx-venv
|
sphinx-venv
|
||||||
|
*-env
|
||||||
|
|
|
||||||
|
|
@ -1294,8 +1294,7 @@ static void DecompileEntity(
|
||||||
|
|
||||||
void DecompileBSP(const mbsp_t *bsp, const decomp_options &options, std::ofstream &file)
|
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(*bsp);
|
||||||
auto entdicts = EntData_Parse(parser);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < entdicts.size(); ++i) {
|
for (size_t i = 0; i < entdicts.size(); ++i) {
|
||||||
// entity 0 is implicitly worldspawn (model 0)
|
// entity 0 is implicitly worldspawn (model 0)
|
||||||
|
|
|
||||||
|
|
@ -204,6 +204,12 @@ std::vector<entdict_t> EntData_Parse(parser_t &parser)
|
||||||
return result;
|
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
|
* EntData_Write
|
||||||
|
|
|
||||||
|
|
@ -78,5 +78,7 @@ void EntData_ParseInto(parser_t &parser, std::vector<entdict_t> &vector);
|
||||||
* ==================
|
* ==================
|
||||||
*/
|
*/
|
||||||
std::vector<entdict_t> EntData_Parse(parser_t &parser);
|
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);
|
std::string EntData_Write(const std::vector<entdict_t> &ents);
|
||||||
|
|
|
||||||
|
|
@ -866,10 +866,7 @@ void LoadEntities(const settings::worldspawn_keys &cfg, const mbsp_t *bsp)
|
||||||
{
|
{
|
||||||
logging::funcheader();
|
logging::funcheader();
|
||||||
|
|
||||||
{
|
entdicts = EntData_Parse(*bsp);
|
||||||
parser_t parser{bsp->dentdata, { bsp->file.string() }};
|
|
||||||
entdicts = EntData_Parse(parser);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make warnings
|
// Make warnings
|
||||||
for (auto &entdict : entdicts) {
|
for (auto &entdict : entdicts) {
|
||||||
|
|
|
||||||
|
|
@ -1434,8 +1434,7 @@ static void LoadTextures(const mbsp_t *bsp)
|
||||||
|
|
||||||
// gather textures used by _project_texture.
|
// gather textures used by _project_texture.
|
||||||
// FIXME: I'm sure we can resolve this so we don't parse entdata twice.
|
// 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(*bsp);
|
||||||
auto entdicts = EntData_Parse(parser);
|
|
||||||
for (auto &entdict : entdicts) {
|
for (auto &entdict : entdicts) {
|
||||||
if (entdict.get("classname").find("light") == 0) {
|
if (entdict.get("classname").find("light") == 0) {
|
||||||
const auto &tex = entdict.get("_project_texture");
|
const auto &tex = entdict.get("_project_texture");
|
||||||
|
|
|
||||||
|
|
@ -1011,8 +1011,7 @@ TEST_CASE("origin" * doctest::test_suite("testmaps_q1"))
|
||||||
REQUIRE(qvec3f(0, 0, 0) == bsp.dmodels[1].origin);
|
REQUIRE(qvec3f(0, 0, 0) == bsp.dmodels[1].origin);
|
||||||
|
|
||||||
// check that the origin brush updated the entity lump
|
// check that the origin brush updated the entity lump
|
||||||
parser_t parser(bsp.dentdata, {"qbsp_origin.bsp"});
|
auto ents = EntData_Parse(bsp);
|
||||||
auto ents = EntData_Parse(parser);
|
|
||||||
auto it = std::find_if(ents.begin(), ents.end(),
|
auto it = std::find_if(ents.begin(), ents.end(),
|
||||||
[](const entdict_t &dict) -> bool { return dict.get("classname") == "rotate_object"; });
|
[](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}));
|
REQUIRE(BSP_FindFaceAtPoint(&bsp, &bsp.dmodels[0], {-5,0,16}, {0, 0, 1}));
|
||||||
|
|
||||||
// check that the worldspawn keys from the base map are used
|
// 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(bsp);
|
||||||
auto ents = EntData_Parse(parser);
|
|
||||||
REQUIRE(ents.size() == 3); // worldspawn, info_player_start, func_wall
|
REQUIRE(ents.size() == 3); // worldspawn, info_player_start, func_wall
|
||||||
|
|
||||||
REQUIRE(ents[0].get("classname") == "worldspawn");
|
REQUIRE(ents[0].get("classname") == "worldspawn");
|
||||||
|
|
|
||||||
|
|
@ -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(0 == void_leaf->area); // a solid leaf gets the invalid area
|
||||||
|
|
||||||
// check the func_areaportal entity had its "style" set
|
// check the func_areaportal entity had its "style" set
|
||||||
parser_t parser(bsp.dentdata, { "qbsp_q2_areaportal.bsp" });
|
auto ents = EntData_Parse(bsp);
|
||||||
auto ents = EntData_Parse(parser);
|
|
||||||
auto it = std::find_if(ents.begin(), ents.end(),
|
auto it = std::find_if(ents.begin(), ents.end(),
|
||||||
[](const entdict_t &dict) { return dict.get("classname") == "func_areaportal"; });
|
[](const entdict_t &dict) { return dict.get("classname") == "func_areaportal"; });
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue