generate ep3 map list on demand

This commit is contained in:
Martin Michelsen
2022-06-02 23:43:02 -07:00
parent fc7a9dcbc9
commit 7efa6374ea
2 changed files with 57 additions and 56 deletions
+16 -19
View File
@@ -802,10 +802,24 @@ Ep3DataIndex::Ep3DataIndex(const string& directory) {
} }
} }
} }
}
const string& Ep3DataIndex::get_compressed_card_definitions() const {
if (this->compressed_card_definitions.empty()) {
throw runtime_error("card definitions are not available");
}
return this->compressed_card_definitions;
}
shared_ptr<const Ep3DataIndex::CardEntry> Ep3DataIndex::get_card_definition(
uint32_t id) const {
return this->card_definitions.at(id);
}
const string& Ep3DataIndex::get_compressed_map_list() const {
if (this->compressed_map_list.empty()) {
// TODO: Write a version of prs_compress that takes iovecs (or something // TODO: Write a version of prs_compress that takes iovecs (or something
// similar) so we can eliminate all this string copying here. At least this // similar) so we can eliminate all this string copying here.
// only happens once at load time...
StringWriter entries_w; StringWriter entries_w;
StringWriter strings_w; StringWriter strings_w;
@@ -857,23 +871,6 @@ Ep3DataIndex::Ep3DataIndex(const string& directory) {
log(INFO, "Generated Episode 3 compressed map list (%zu -> %zu bytes)", log(INFO, "Generated Episode 3 compressed map list (%zu -> %zu bytes)",
w.size(), this->compressed_map_list.size()); w.size(), this->compressed_map_list.size());
} }
const string& Ep3DataIndex::get_compressed_card_definitions() const {
if (this->compressed_card_definitions.empty()) {
throw runtime_error("card definitions are not available");
}
return this->compressed_card_definitions;
}
shared_ptr<const Ep3DataIndex::CardEntry> Ep3DataIndex::get_card_definition(
uint32_t id) const {
return this->card_definitions.at(id);
}
const string& Ep3DataIndex::get_compressed_map_list() const {
if (this->compressed_map_list.empty()) {
throw runtime_error("map list is not available");
}
return this->compressed_map_list; return this->compressed_map_list;
} }
+5 -1
View File
@@ -335,6 +335,10 @@ private:
std::string compressed_card_definitions; std::string compressed_card_definitions;
std::unordered_map<uint32_t, std::shared_ptr<CardEntry>> card_definitions; std::unordered_map<uint32_t, std::shared_ptr<CardEntry>> card_definitions;
std::string compressed_map_list; // The compressed map list is generated on demand from the maps map below.
// It's marked mutable because the logical consistency of the Ep3DataIndex
// object is not violated from the caller's perspective even if we don't
// generate the compressed map list at load time.
mutable std::string compressed_map_list;
std::map<uint32_t, std::shared_ptr<MapEntry>> maps; std::map<uint32_t, std::shared_ptr<MapEntry>> maps;
}; };