1

Precache books as an unordered map

This commit is contained in:
Eddoursul 2022-06-22 01:30:45 +02:00
parent 58890efc21
commit 1e71ef6032
5 changed files with 14 additions and 18 deletions

View File

@ -3,7 +3,7 @@
// Mostly borrowed from Fix Note icon for SkyUI by 0xC0000005 // Mostly borrowed from Fix Note icon for SkyUI by 0xC0000005
namespace BookCheck namespace BookCheck
{ {
std::vector<RE::TESObjectBOOK*> validBooks; std::unordered_map<RE::FormID, RE::TESObjectBOOK*> validBooks;
void PreloadBookList() void PreloadBookList()
{ {
@ -20,12 +20,12 @@ namespace BookCheck
continue; continue;
} }
if (form->HasKeyword(recipeKeyword) || IsBook(form)) { if (form->HasKeyword(recipeKeyword) || IsBook(form)) {
validBooks.push_back(form); validBooks[form->formID] = form;
} }
} }
} }
std::vector<RE::TESObjectBOOK*> GetBookList() std::unordered_map<RE::FormID, RE::TESObjectBOOK*> GetBookList()
{ {
return validBooks; return validBooks;
} }

View File

@ -5,7 +5,7 @@ namespace BookCheck
{ {
void PreloadBookList(); void PreloadBookList();
std::vector<RE::TESObjectBOOK*> GetBookList(); std::unordered_map<RE::FormID, RE::TESObjectBOOK*> GetBookList();
const char* ExtractFileName(const char* const path, size_t& fileNameLength); const char* ExtractFileName(const char* const path, size_t& fileNameLength);

View File

@ -132,7 +132,7 @@ namespace Papyrus::ArtifactTracker
a_exform.formType == RE::FormType::Armor a_exform.formType == RE::FormType::Armor
|| (a_exform.formType == RE::FormType::Weapon && a_exform.formID != 0x000001F4) || (a_exform.formType == RE::FormType::Weapon && a_exform.formID != 0x000001F4)
|| a_exform.formType == RE::FormType::Misc || a_exform.formType == RE::FormType::Misc
|| (a_exform.formType == RE::FormType::Book && !a_exform.As<RE::TESObjectBOOK>()->TeachesSpell() && (a_exform.As<RE::BGSKeywordForm>()->HasKeyword(recipeKeyword) || BookCheck::IsBook(a_exform.As<RE::TESObjectBOOK>()))) || (a_exform.formType == RE::FormType::Book && BookCheck::GetBookList().contains(a_exform.formID))
) )
&& (excludeOnlyMisc ? (a_exform.formType != RE::FormType::Misc || !is_excluded(&a_exform, a_excludeForm)) : !is_excluded(&a_exform, a_excludeForm)); && (excludeOnlyMisc ? (a_exform.formType != RE::FormType::Misc || !is_excluded(&a_exform, a_excludeForm)) : !is_excluded(&a_exform, a_excludeForm));
}); });
@ -307,14 +307,14 @@ namespace Papyrus::ArtifactTracker
} }
if (a_excludeForm) { if (a_excludeForm) {
for (const auto& book : BookCheck::GetBookList()) { for (auto const& item : BookCheck::GetBookList()) {
if (!is_excluded(book, a_excludeForm)) { if (!is_excluded(item.second, a_excludeForm)) {
a_targetList->AddForm(book); a_targetList->AddForm(item.second);
} }
} }
} else { } else {
for (const auto& book : BookCheck::GetBookList()) { for (const auto& item : BookCheck::GetBookList()) {
a_targetList->AddForm(book); a_targetList->AddForm(item.second);
} }
} }

View File

@ -27,15 +27,11 @@ namespace {
} }
void InitializeMessaging() { void InitializeMessaging() {
if (!GetMessagingInterface()->RegisterListener([](MessagingInterface::Message* message) { GetMessagingInterface()->RegisterListener([](MessagingInterface::Message* message) {
if (message->type == MessagingInterface::kDataLoaded) {
if (message->type == MessagingInterface::kDataLoaded) {
BookCheck::PreloadBookList(); BookCheck::PreloadBookList();
} }
});
})) {
stl::report_and_fail("Unable to register message listener.");
}
} }
} }