qbsp: drop mapentity_t::epair_order and std::map for epairs
just store as a std::vector of pairs. Lookups aren't done much in qbsp so linear search performance should be fine. epair_order approach gets messy because we sometimes add epairs
This commit is contained in:
parent
402c18bad0
commit
f6e9ba4eb2
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <unordered_map>
|
||||
|
||||
struct mapface_t
|
||||
|
|
@ -92,10 +93,8 @@ public:
|
|||
brush_t *solid = nullptr, *sky = nullptr, *detail = nullptr, *detail_illusionary = nullptr, *detail_fence = nullptr,
|
||||
*liquid = nullptr;
|
||||
|
||||
// tree of key/value pairs
|
||||
std::map<std::string, std::string, case_insensitive_less> epairs;
|
||||
// order of parse
|
||||
std::vector<std::string> epair_order;
|
||||
// key/value pairs in the order they were parsed
|
||||
std::vector<std::pair<std::string, std::string>> epairs;
|
||||
|
||||
aabb3d bounds;
|
||||
brush_t *brushes = nullptr; /* NULL terminated list */
|
||||
|
|
|
|||
29
qbsp/map.cc
29
qbsp/map.cc
|
|
@ -495,7 +495,8 @@ static void ParseEpair(parser_t &parser, mapentity_t *entity)
|
|||
goto parse_error;
|
||||
|
||||
{
|
||||
std::string &value = (entity->epairs[key] = parser.token);
|
||||
std::string value = parser.token;
|
||||
SetKeyValue(entity, key.c_str(), value.c_str());
|
||||
|
||||
if (!Q_strcasecmp(key.c_str(), "origin")) {
|
||||
GetVectorForKey(entity, key.c_str(), entity->origin);
|
||||
|
|
@ -514,8 +515,6 @@ static void ParseEpair(parser_t &parser, mapentity_t *entity)
|
|||
}
|
||||
}
|
||||
|
||||
entity->epair_order.push_back(std::move(key));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -2186,8 +2185,8 @@ static void ConvertEntity(std::ofstream &f, const mapentity_t *entity, const con
|
|||
{
|
||||
f << "{\n";
|
||||
|
||||
for (const auto &key : entity->epair_order) {
|
||||
fmt::print(f, "\"{}\" \"{}\"\n", key, entity->epairs.at(key));
|
||||
for (const auto &[key, value] : entity->epairs) {
|
||||
fmt::print(f, "\"{}\" \"{}\"\n", key, value);
|
||||
}
|
||||
|
||||
for (int i = 0; i < entity->nummapbrushes; i++) {
|
||||
|
|
@ -2235,17 +2234,23 @@ void PrintEntity(const mapentity_t *entity)
|
|||
|
||||
const char *ValueForKey(const mapentity_t *entity, const char *key)
|
||||
{
|
||||
auto it = entity->epairs.find(key);
|
||||
|
||||
if (it == entity->epairs.end())
|
||||
return "";
|
||||
|
||||
return it->second.c_str();
|
||||
for (auto &epair : entity->epairs) {
|
||||
if (!Q_strcasecmp(key, epair.first.c_str())) {
|
||||
return epair.second.c_str();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void SetKeyValue(mapentity_t *entity, const char *key, const char *value)
|
||||
{
|
||||
entity->epairs[key] = value;
|
||||
for (auto &epair : entity->epairs) {
|
||||
if (!Q_strcasecmp(key, epair.first.c_str())) {
|
||||
epair.second = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
entity->epairs.emplace_back(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue