don't return string ref, since it can be modified after it's inserted because of the vector growing
This commit is contained in:
parent
78b979d670
commit
17656eff78
|
|
@ -35,7 +35,7 @@ entdict_t::entdict_t(std::initializer_list<keyvalue_t> 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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(); }
|
||||
|
||||
|
|
|
|||
|
|
@ -255,9 +255,11 @@ public:
|
|||
fs::path map_path;
|
||||
fs::path bsp_path;
|
||||
std::unordered_map<std::string, std::tuple<std::string, std::optional<extended_texinfo_t>>> loaded_texture_defs;
|
||||
std::unordered_map<std::string, entdict_t> loaded_entity_defs;
|
||||
|
||||
private:
|
||||
void load_texture_def(const std::string &pathname);
|
||||
void load_entity_def(const std::string &pathname);
|
||||
};
|
||||
}; // namespace settings
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
33
qbsp/qbsp.cc
33
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue