diff --git a/common/entdata.cc b/common/entdata.cc index 6da36b36..881caccd 100644 --- a/common/entdata.cc +++ b/common/entdata.cc @@ -35,7 +35,7 @@ entdict_t::entdict_t(std::initializer_list l) : keyvalues(l) { } entdict_t::entdict_t() = default; -const std::string &entdict_t::get(const std::string_view &key) const +std::string entdict_t::get(const std::string_view &key) const { if (auto it = find(key); it != keyvalues.end()) { return it->second; diff --git a/include/common/entdata.h b/include/common/entdata.h index e64ad940..156b157f 100644 --- a/include/common/entdata.h +++ b/include/common/entdata.h @@ -41,7 +41,7 @@ public: entdict_t(); inline entdict_t(parser_base_t &parser) { parse(parser); } - const std::string &get(const std::string_view &key) const; + std::string get(const std::string_view &key) const; vec_t get_float(const std::string_view &key) const; int32_t get_int(const std::string_view &key) const; // returns number of vector components read diff --git a/include/light/entities.hh b/include/light/entities.hh index 78366232..96279c0b 100644 --- a/include/light/entities.hh +++ b/include/light/entities.hh @@ -98,7 +98,7 @@ public: settings::setting_string suntexture{this, "suntexture", ""}; settings::setting_bool nostaticlight{this, "nostaticlight", false}; - const std::string &classname() const; + std::string classname() const; const light_formula_t &getFormula() const { return formula.value(); } diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index a2166696..f2a63077 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -255,9 +255,11 @@ public: fs::path map_path; fs::path bsp_path; std::unordered_map>> loaded_texture_defs; + std::unordered_map loaded_entity_defs; private: void load_texture_def(const std::string &pathname); + void load_entity_def(const std::string &pathname); }; }; // namespace settings diff --git a/light/entities.cc b/light/entities.cc index 045b3e96..ede8d868 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -49,7 +49,7 @@ static void MakeSurfaceLights(const mbsp_t *bsp); // light_t -const std::string &light_t::classname() const +std::string light_t::classname() const { return epairs->get("classname"); } diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 889423d2..b07907b3 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -138,6 +138,35 @@ void qbsp_settings::load_texture_def(const std::string &pathname) } } +void qbsp_settings::load_entity_def(const std::string &pathname) +{ + if (!fs::exists(pathname)) { + FError("can't find aliasdef file {}", pathname); + } + + fs::data data = fs::load(pathname); + parser_t parser(data); + + while (true) { + if (!parser.parse_token() || parser.at_end()) { + break; + } + + std::string classname = std::move(parser.token); + + if (!parser.parse_token(PARSE_PEEK)) { + FError("expected {{ in alias def {}, got end of file", pathname); + } + + if (parser.token != "{") { + FError("expected {{ in alias def {}, got {}", pathname, parser.token); + } + + // parse ent dict + loaded_entity_defs[classname] = parser; + } +} + void qbsp_settings::postinitialize(int argc, const char **argv) { // side effects from common @@ -220,6 +249,10 @@ void qbsp_settings::postinitialize(int argc, const char **argv) load_texture_def(def); } + for (auto &def : aliasdefs.values()) { + load_entity_def(def); + } + common_settings::postinitialize(argc, argv); } }; // namespace settings