Skip to content

Commit

Permalink
Added manual counter for processed forms to properly count inferred f…
Browse files Browse the repository at this point in the history
…orms.
  • Loading branch information
adya committed Mar 30, 2024
1 parent 31216b3 commit 7747d4b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
42 changes: 31 additions & 11 deletions SPID/include/FormData.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,15 @@ namespace Forms
std::size_t GetSize() const;
std::size_t GetLeveledSize() const;

std::size_t GetLookupCount() const;

RECORD::TYPE GetType() const;

DataVec<Form>& GetForms(bool a_onlyLevelEntries);
DataVec<Form>& GetForms();

void LookupForms(RE::TESDataHandler* a_dataHandler, std::string_view a_type, INI::DataVec& a_INIDataVec);
void EmplaceForm(bool isValid, Form*, const IndexOrCount&, const FilterData&, const std::string& path);

// Init formsWithLevels and formsNoLevels
void FinishLookupForms();
Expand All @@ -428,6 +431,10 @@ namespace Forms
DataVec<Form> forms{};
DataVec<Form> formsWithLevels{};

/// Total number of entries that were matched to this Distributable, including invalid.
/// This counter is used for logging purposes.
std::size_t lookupCount{ 0 };

void LookupForm(RE::TESDataHandler* a_dataHandler, INI::Data& rawForm);
};

Expand Down Expand Up @@ -473,7 +480,7 @@ namespace Forms
/// <param name="rawForm">A raw form entry that needs to be looked up.</param>
/// <param name="callback">A callback to be called with validated data after successful lookup.</param>
template <class Form = RE::TESForm*>
void LookupGenericForm(RE::TESDataHandler* const dataHandler, INI::Data& rawForm, std::function<void(Form*, IndexOrCount&, FilterData&, std::string& path)> callback);
void LookupGenericForm(RE::TESDataHandler* const dataHandler, INI::Data& rawForm, std::function<void(bool isValid, Form*, const IndexOrCount&, const FilterData&, const std::string& path)> callback);
}

template <class Form>
Expand Down Expand Up @@ -503,6 +510,12 @@ std::size_t Forms::Distributables<Form>::GetLeveledSize() const
return formsWithLevels.size();
}

template <class Form>
std::size_t Forms::Distributables<Form>::GetLookupCount() const
{
return lookupCount;
}

template <class Form>
RECORD::TYPE Forms::Distributables<Form>::GetType() const
{
Expand All @@ -525,15 +538,15 @@ Forms::DataVec<Form>& Forms::Distributables<Form>::GetForms(bool a_onlyLevelEntr
}

template <class Form>
void Forms::Distributables<Form>::LookupForm(RE::TESDataHandler* a_dataHandler, INI::Data& rawForm)
void Forms::Distributables<Form>::LookupForm(RE::TESDataHandler* dataHandler, INI::Data& rawForm)
{
Forms::LookupGenericForm<Form>(a_dataHandler, rawForm, [&](Form* form, auto& idxOrCount, auto& filters, std::string& path) {
forms.emplace_back(forms.size(), form, idxOrCount, filters, path);
Forms::LookupGenericForm<Form>(dataHandler, rawForm, [&](bool isValid, Form* form, const auto& idxOrCount, const auto& filters, const auto& path) {
EmplaceForm(isValid, form, idxOrCount, filters, path);
});
}

template <class Form>
void Forms::Distributables<Form>::LookupForms(RE::TESDataHandler* a_dataHandler, std::string_view a_type, INI::DataVec& a_INIDataVec)
void Forms::Distributables<Form>::LookupForms(RE::TESDataHandler* dataHandler, std::string_view a_type, INI::DataVec& a_INIDataVec)
{
if (a_INIDataVec.empty()) {
return;
Expand All @@ -544,10 +557,19 @@ void Forms::Distributables<Form>::LookupForms(RE::TESDataHandler* a_dataHandler,
forms.reserve(a_INIDataVec.size());

for (auto& rawForm : a_INIDataVec) {
LookupForm(a_dataHandler, rawForm);
LookupForm(dataHandler, rawForm);
}
}

template <class Form>
void Forms::Distributables<Form>::EmplaceForm(bool isValid, Form* form, const IndexOrCount& idxOrCount, const FilterData& filters, const std::string& path)
{
if (isValid) {
forms.emplace_back(forms.size(), form, idxOrCount, filters, path);
}
lookupCount++;
}

template <class Form>
void Forms::Distributables<Form>::FinishLookupForms()
{
Expand All @@ -572,7 +594,7 @@ void Forms::Distributables<Form>::FinishLookupForms()
}

template <class Form>
void Forms::LookupGenericForm(RE::TESDataHandler* const dataHandler, INI::Data& rawForm, std::function<void(Form*, IndexOrCount&, FilterData&, std::string& path)> callback)
void Forms::LookupGenericForm(RE::TESDataHandler* const dataHandler, INI::Data& rawForm, std::function<void(bool isValid, Form*, const IndexOrCount&, const FilterData&, const std::string& path)> callback)
{
auto& [formOrEditorID, strings, filterIDs, level, traits, idxOrCount, chance, path] = rawForm;

Expand All @@ -588,10 +610,8 @@ void Forms::LookupGenericForm(RE::TESDataHandler* const dataHandler, INI::Data&
validEntry = detail::formID_to_form(dataHandler, filterIDs.MATCH, filterForms.MATCH, path);
}

if (validEntry) {
FilterData filters{ strings, filterForms, level, traits, chance };
callback(form, idxOrCount, filters, path);
}
FilterData filters{ strings, filterForms, level, traits, chance };
callback(validEntry, form, idxOrCount, filters, path);
}
} catch (const Lookup::UnknownFormIDException& e) {
buffered_logger::error("\t[{}] [0x{:X}] ({}) FAIL - formID doesn't exist", e.path, e.formID, e.modName.value_or(""));
Expand Down
24 changes: 12 additions & 12 deletions SPID/src/LookupForms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ bool LookupDistributables(RE::TESDataHandler* const dataHandler)

for (auto& rawForm : genericForms) {
// Add to appropriate list. (Note that type inferring doesn't recognize SleepOutfit or DeathItems)
LookupGenericForm<RE::TESForm>(dataHandler, rawForm, [&](auto form, auto& idxOrCount, auto& filters, std::string& path) {
LookupGenericForm<RE::TESForm>(dataHandler, rawForm, [&](bool isValid, auto form, const auto& idxOrCount, const auto& filters, const auto& path) {
if (const auto keyword = form->As<RE::BGSKeyword>(); keyword) {
keywords.GetForms().emplace_back(keywords.GetSize(), keyword, idxOrCount, filters, path);
keywords.EmplaceForm(isValid, keyword, idxOrCount, filters, path);
} else if (const auto spell = form->As<RE::SpellItem>(); spell) {
spells.GetForms().emplace_back(spells.GetSize(), spell, idxOrCount, filters, path);
spells.EmplaceForm(isValid, spell, idxOrCount, filters, path);
} else if (const auto perk = form->As<RE::BGSPerk>(); perk) {
perks.GetForms().emplace_back(perks.GetSize(), perk, idxOrCount, filters, path);
perks.EmplaceForm(isValid, perk, idxOrCount, filters, path);
} else if (const auto shout = form->As<RE::TESShout>(); shout) {
shouts.GetForms().emplace_back(shouts.GetSize(), shout, idxOrCount, filters, path);
shouts.EmplaceForm(isValid, shout, idxOrCount, filters, path);
} else if (const auto item = form->As<RE::TESBoundObject>(); item) {
items.GetForms().emplace_back(items.GetSize(), item, idxOrCount, filters, path);
items.EmplaceForm(isValid, item, idxOrCount, filters, path);
} else if (const auto outfit = form->As<RE::BGSOutfit>(); outfit) {
outfits.GetForms().emplace_back(outfits.GetSize(), outfit, idxOrCount, filters, path);
outfits.EmplaceForm(isValid, outfit, idxOrCount, filters, path);
} else if (const auto faction = form->As<RE::TESFaction>(); faction) {
factions.GetForms().emplace_back(factions.GetSize(), faction, idxOrCount, filters, path);
factions.EmplaceForm(isValid, faction, idxOrCount, filters, path);
} else if (const auto skin = form->As<RE::TESObjectARMO>(); skin) {
skins.GetForms().emplace_back(skins.GetSize(), skin, idxOrCount, filters, path);
skins.EmplaceForm(isValid, skin, idxOrCount, filters, path);
} else {
auto type = form->GetFormType();
if (type == RE::FormType::Package || type == RE::FormType::FormList) {
Expand All @@ -49,7 +49,7 @@ bool LookupDistributables(RE::TESDataHandler* const dataHandler)
} else {
packageIndex = std::get<Index>(idxOrCount);
}
packages.GetForms().emplace_back(packages.GetSize(), form, packageIndex, filters, path);
packages.EmplaceForm(isValid, form, packageIndex, filters, path);
}
}
});
Expand Down Expand Up @@ -78,12 +78,12 @@ void LogDistributablesLookup()
ForEachDistributable([]<typename Form>(Distributables<Form>& a_distributable) {
const auto& recordName = RECORD::GetTypeName(a_distributable.GetType());

const auto all = INI::configs[a_distributable.GetType()].size();
const auto added = a_distributable.GetSize();
const auto all = a_distributable.GetLookupCount();

// Only log entries that are actually present in INIs.
if (all > 0) {
logger::info("Registered {}/{} {}s:", added, all, recordName);
logger::info("Registered {}/{} {}s", added, all, recordName);
}
});

Expand Down

0 comments on commit 7747d4b

Please sign in to comment.