Skip to content

Commit

Permalink
Standardize BSContainer::ForEachResult functions
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Jan 15, 2024
1 parent b30c5f9 commit 78f140e
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 64 deletions.
4 changes: 2 additions & 2 deletions include/RE/B/BGSKeywordForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ namespace RE
bool AddKeyword(BGSKeyword* a_keyword);
bool AddKeywords(const std::vector<BGSKeyword*>& a_keywords);
[[nodiscard]] bool ContainsKeywordString(std::string_view a_editorID) const;
void ForEachKeyword(std::function<BSContainer::ForEachResult(BGSKeyword&)> a_callback) const;
void ForEachKeyword(std::function<BSContainer::ForEachResult(BGSKeyword*)> a_callback) const;
[[nodiscard]] std::optional<BGSKeyword*> GetKeywordAt(std::uint32_t a_idx) const;
[[nodiscard]] std::optional<std::uint32_t> GetKeywordIndex(BGSKeyword* a_keyword) const;
[[nodiscard]] std::uint32_t GetNumKeywords() const;
[[nodiscard]] bool HasKeywordID(FormID a_formID) const;
[[nodiscard]] bool HasKeywordString(std::string_view a_editorID) const;
bool RemoveKeyword(std::uint32_t a_index);
bool RemoveKeyword(BGSKeyword* a_keyword);
bool RemoveKeywords(const std::vector<RE::BGSKeyword*>& a_keywords);
bool RemoveKeywords(const std::vector<BGSKeyword*>& a_keywords);

// members
BGSKeyword** keywords; // 08 - KWDA
Expand Down
2 changes: 1 addition & 1 deletion include/RE/B/BGSListForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace RE

void AddForm(TESForm* a_form);
[[nodiscard]] bool ContainsOnlyType(FormType a_formType) const;
void ForEachForm(std::function<BSContainer::ForEachResult(TESForm&)> a_callback) const;
void ForEachForm(std::function<BSContainer::ForEachResult(TESForm*)> a_callback) const;
[[nodiscard]] bool HasForm(const TESForm* a_form) const;
[[nodiscard]] bool HasForm(FormID a_formID) const;

Expand Down
4 changes: 2 additions & 2 deletions include/RE/B/BGSOutfit.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ namespace RE
bool Load(TESFile* a_mod) override; // 06
void InitItemImpl() override; // 13

void ForEachItem(std::function<BSContainer::ForEachResult(TESForm&)> a_callback) const
void ForEachItem(std::function<BSContainer::ForEachResult(TESForm*)> a_callback) const
{
for (auto& item : outfitItems) {
if (item && a_callback(*item) == BSContainer::ForEachResult::kStop) {
if (item && a_callback(item) == BSContainer::ForEachResult::kStop) {
return;
}
}
Expand Down
10 changes: 5 additions & 5 deletions include/RE/P/ProcessLists.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ namespace RE
static ProcessLists* GetSingleton();

void ClearCachedFactionFightReactions() const;
void ForAllActors(std::function<BSContainer::ForEachResult(Actor&)> a_callback);
void ForEachHighActor(std::function<BSContainer::ForEachResult(Actor&)> a_callback);
void ForEachMagicTempEffect(std::function<BSContainer::ForEachResult(BSTempEffect&)> a_callback);
void ForEachModelEffect(std::function<BSContainer::ForEachResult(ModelReferenceEffect&)> a_callback);
void ForEachShaderEffect(std::function<BSContainer::ForEachResult(ShaderReferenceEffect&)> a_callback);
void ForAllActors(std::function<BSContainer::ForEachResult(Actor*)> a_callback);
void ForEachHighActor(std::function<BSContainer::ForEachResult(Actor*)> a_callback);
void ForEachMagicTempEffect(std::function<BSContainer::ForEachResult(BSTempEffect*)> a_callback);
void ForEachModelEffect(std::function<BSContainer::ForEachResult(ModelReferenceEffect*)> a_callback);
void ForEachShaderEffect(std::function<BSContainer::ForEachResult(ShaderReferenceEffect*)> a_callback);
float GetSystemTimeClock();
std::int16_t RequestHighestDetectionLevelAgainstActor(Actor* a_actor, std::uint32_t& a_LOSCount);
void StopAllMagicEffects(TESObjectREFR& a_ref);
Expand Down
4 changes: 2 additions & 2 deletions include/RE/T/TES.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ namespace RE

static TES* GetSingleton();

void ForEachReference(std::function<BSContainer::ForEachResult(TESObjectREFR& a_ref)> a_callback);
void ForEachReferenceInRange(TESObjectREFR* a_origin, float a_radius, std::function<BSContainer::ForEachResult(TESObjectREFR& a_ref)> a_callback);
void ForEachReference(std::function<BSContainer::ForEachResult(TESObjectREFR*)> a_callback);
void ForEachReferenceInRange(TESObjectREFR* a_origin, float a_radius, std::function<BSContainer::ForEachResult(TESObjectREFR*)> a_callback);

TESObjectCELL* GetCell(const NiPoint3& a_position) const;
MATERIAL_ID GetLandMaterialType(const NiPoint3& a_position) const;
Expand Down
4 changes: 2 additions & 2 deletions include/RE/T/TESObjectCELL.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ namespace RE

TESNPC* GetActorOwner();
bhkWorld* GetbhkWorld() const;
void ForEachReference(std::function<BSContainer::ForEachResult(TESObjectREFR&)> a_callback) const;
void ForEachReferenceInRange(const NiPoint3& a_origin, float a_radius, std::function<BSContainer::ForEachResult(TESObjectREFR&)> a_callback) const;
void ForEachReference(std::function<BSContainer::ForEachResult(TESObjectREFR*)> a_callback) const;
void ForEachReferenceInRange(const NiPoint3& a_origin, float a_radius, std::function<BSContainer::ForEachResult(TESObjectREFR*)> a_callback) const;
EXTERIOR_DATA* GetCoordinates();
TESFaction* GetFactionOwner();
INTERIOR_DATA* GetLighting();
Expand Down
18 changes: 9 additions & 9 deletions src/RE/B/BGSKeywordForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace RE
bool BGSKeywordForm::ContainsKeywordString(std::string_view a_editorID) const
{
bool result = false;
ForEachKeyword([&](const BGSKeyword& a_keyword) {
if (a_keyword.formEditorID.contains(a_editorID)) {
ForEachKeyword([&](const BGSKeyword* a_keyword) {
if (a_keyword->formEditorID.contains(a_editorID)) {
result = true;
return BSContainer::ForEachResult::kStop;
}
Expand All @@ -52,11 +52,11 @@ namespace RE
return result;
}

void BGSKeywordForm::ForEachKeyword(std::function<BSContainer::ForEachResult(BGSKeyword&)> a_callback) const
void BGSKeywordForm::ForEachKeyword(std::function<BSContainer::ForEachResult(BGSKeyword*)> a_callback) const
{
if (keywords) {
for (std::uint32_t idx = 0; idx < numKeywords; ++idx) {
if (keywords[idx] && a_callback(*keywords[idx]) == BSContainer::ForEachResult::kStop) {
if (keywords[idx] && a_callback(keywords[idx]) == BSContainer::ForEachResult::kStop) {
return;
}
}
Expand Down Expand Up @@ -92,8 +92,8 @@ namespace RE
bool BGSKeywordForm::HasKeywordID(FormID a_formID) const
{
bool result = false;
ForEachKeyword([&](const BGSKeyword& a_keyword) {
if (a_keyword.GetFormID() == a_formID) {
ForEachKeyword([&](const BGSKeyword* a_keyword) {
if (a_keyword->GetFormID() == a_formID) {
result = true;
return BSContainer::ForEachResult::kStop;
}
Expand All @@ -105,8 +105,8 @@ namespace RE
bool BGSKeywordForm::HasKeywordString(std::string_view a_editorID) const
{
bool result = false;
ForEachKeyword([&](const BGSKeyword& a_keyword) {
if (a_keyword.formEditorID == a_editorID) {
ForEachKeyword([&](const BGSKeyword* a_keyword) {
if (a_keyword->formEditorID == a_editorID) {
result = true;
return BSContainer::ForEachResult::kStop;
}
Expand All @@ -129,7 +129,7 @@ namespace RE
return index ? RemoveKeyword(*index) : false;
}

bool BGSKeywordForm::RemoveKeywords(const std::vector<RE::BGSKeyword*>& a_keywords)
bool BGSKeywordForm::RemoveKeywords(const std::vector<BGSKeyword*>& a_keywords)
{
std::vector<BGSKeyword*> copiedData{ keywords, keywords + numKeywords };
if (std::erase_if(copiedData, [&](auto& keyword) { return std::ranges::find(a_keywords, keyword) != a_keywords.end(); }) > 0) {
Expand Down
10 changes: 5 additions & 5 deletions src/RE/B/BGSListForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace RE
bool BGSListForm::ContainsOnlyType(FormType a_formType) const
{
bool result = true;
ForEachForm([&](const TESForm& a_form) {
if (a_form.GetFormType() != a_formType) {
ForEachForm([&](const TESForm* a_form) {
if (a_form->GetFormType() != a_formType) {
result = false;
return BSContainer::ForEachResult::kStop;
}
Expand Down Expand Up @@ -47,17 +47,17 @@ namespace RE
return HasForm(form);
}

void BGSListForm::ForEachForm(std::function<BSContainer::ForEachResult(TESForm&)> a_callback) const
void BGSListForm::ForEachForm(std::function<BSContainer::ForEachResult(TESForm*)> a_callback) const
{
for (const auto& form : forms) {
if (form && a_callback(*form) == BSContainer::ForEachResult::kStop) {
if (form && a_callback(form) == BSContainer::ForEachResult::kStop) {
return;
}
}
if (scriptAddedTempForms) {
for (const auto& addedFormID : *scriptAddedTempForms) {
const auto addedForm = TESForm::LookupByID(addedFormID);
if (addedForm && a_callback(*addedForm) == BSContainer::ForEachResult::kStop) {
if (addedForm && a_callback(addedForm) == BSContainer::ForEachResult::kStop) {
return;
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/RE/P/ProcessLists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,58 @@ namespace RE
return func(this);
}

void ProcessLists::ForAllActors(std::function<BSContainer::ForEachResult(Actor&)> a_callback)
void ProcessLists::ForAllActors(std::function<BSContainer::ForEachResult(Actor*)> a_callback)
{
for (auto& list : allProcesses) {
if (list) {
for (auto& actorHandle : *list) {
const auto& actor = actorHandle.get();
if (actor && a_callback(*actor) == BSContainer::ForEachResult::kStop) {
if (actor && a_callback(actor.get()) == BSContainer::ForEachResult::kStop) {
return;
}
}
}
}
}

void ProcessLists::ForEachHighActor(std::function<BSContainer::ForEachResult(Actor&)> a_callback)
void ProcessLists::ForEachHighActor(std::function<BSContainer::ForEachResult(Actor*)> a_callback)
{
for (auto& highActorHandle : highActorHandles) {
const auto& highActor = highActorHandle.get();
if (highActor && a_callback(*highActor) == BSContainer::ForEachResult::kStop) {
if (highActor && a_callback(highActor.get()) == BSContainer::ForEachResult::kStop) {
break;
}
}
}

void ProcessLists::ForEachMagicTempEffect(std::function<BSContainer::ForEachResult(BSTempEffect&)> a_callback)
void ProcessLists::ForEachMagicTempEffect(std::function<BSContainer::ForEachResult(BSTempEffect*)> a_callback)
{
BSSpinLockGuard locker(magicEffectsLock);

for (auto& tempEffectPtr : magicEffects) {
const auto& tempEffect = tempEffectPtr.get();
if (tempEffect && a_callback(*tempEffect) == BSContainer::ForEachResult::kStop) {
if (tempEffect && a_callback(tempEffect) == BSContainer::ForEachResult::kStop) {
break;
}
}
}

void ProcessLists::ForEachModelEffect(std::function<BSContainer::ForEachResult(ModelReferenceEffect&)> a_callback)
void ProcessLists::ForEachModelEffect(std::function<BSContainer::ForEachResult(ModelReferenceEffect*)> a_callback)
{
ForEachMagicTempEffect([a_callback](BSTempEffect& a_tempEffect) {
const auto modelEffect = a_tempEffect.As<ModelReferenceEffect>();
if (modelEffect && a_callback(*modelEffect) == BSContainer::ForEachResult::kStop) {
ForEachMagicTempEffect([a_callback](BSTempEffect* a_tempEffect) {
const auto modelEffect = a_tempEffect->As<ModelReferenceEffect>();
if (modelEffect && a_callback(modelEffect) == BSContainer::ForEachResult::kStop) {
return BSContainer::ForEachResult::kStop;
}
return BSContainer::ForEachResult::kContinue;
});
}

void ProcessLists::ForEachShaderEffect(std::function<BSContainer::ForEachResult(ShaderReferenceEffect&)> a_callback)
void ProcessLists::ForEachShaderEffect(std::function<BSContainer::ForEachResult(ShaderReferenceEffect*)> a_callback)
{
ForEachMagicTempEffect([a_callback](BSTempEffect& a_tempEffect) {
const auto shaderEffect = a_tempEffect.As<ShaderReferenceEffect>();
if (shaderEffect && a_callback(*shaderEffect) == BSContainer::ForEachResult::kStop) {
ForEachMagicTempEffect([a_callback](BSTempEffect* a_tempEffect) {
const auto shaderEffect = a_tempEffect->As<ShaderReferenceEffect>();
if (shaderEffect && a_callback(shaderEffect) == BSContainer::ForEachResult::kStop) {
return BSContainer::ForEachResult::kStop;
}
return BSContainer::ForEachResult::kContinue;
Expand All @@ -96,8 +96,8 @@ namespace RE
void ProcessLists::StopAllMagicEffects(TESObjectREFR& a_ref)
{
const auto handle = a_ref.CreateRefHandle();
ForEachMagicTempEffect([&](BSTempEffect& a_tempEffect) {
const auto referenceEffect = a_tempEffect.As<ReferenceEffect>();
ForEachMagicTempEffect([&](BSTempEffect* a_tempEffect) {
const auto referenceEffect = a_tempEffect->As<ReferenceEffect>();
if (referenceEffect && referenceEffect->target == handle) {
referenceEffect->finished = true;
}
Expand Down
18 changes: 9 additions & 9 deletions src/RE/T/TES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace RE
return *singleton;
}

void TES::ForEachReference(std::function<BSContainer::ForEachResult(TESObjectREFR& a_ref)> a_callback)
void TES::ForEachReference(std::function<BSContainer::ForEachResult(TESObjectREFR* a_ref)> a_callback)
{
if (interiorCell) {
interiorCell->ForEachReference([&](TESObjectREFR& a_ref) {
interiorCell->ForEachReference([&](TESObjectREFR* a_ref) {
return a_callback(a_ref);
});
} else {
Expand All @@ -28,7 +28,7 @@ namespace RE
std::uint32_t y = 0;
do {
if (const auto cell = gridCells->GetCell(x, y); cell && cell->IsAttached()) {
cell->ForEachReference([&](TESObjectREFR& a_ref) {
cell->ForEachReference([&](TESObjectREFR* a_ref) {
return a_callback(a_ref);
});
}
Expand All @@ -39,19 +39,19 @@ namespace RE
}
}
if (const auto skyCell = worldSpace ? worldSpace->GetSkyCell() : nullptr; skyCell) {
skyCell->ForEachReference([&](TESObjectREFR& a_ref) {
skyCell->ForEachReference([&](TESObjectREFR* a_ref) {
return a_callback(a_ref);
});
}
}

void TES::ForEachReferenceInRange(TESObjectREFR* a_origin, float a_radius, std::function<BSContainer::ForEachResult(TESObjectREFR& a_ref)> a_callback)
void TES::ForEachReferenceInRange(TESObjectREFR* a_origin, float a_radius, std::function<BSContainer::ForEachResult(TESObjectREFR* a_ref)> a_callback)
{
if (a_origin && a_radius > 0.0f) {
const auto originPos = a_origin->GetPosition();

if (interiorCell) {
interiorCell->ForEachReferenceInRange(originPos, a_radius, [&](TESObjectREFR& a_ref) {
interiorCell->ForEachReferenceInRange(originPos, a_radius, [&](TESObjectREFR* a_ref) {
return a_callback(a_ref);
});
} else {
Expand All @@ -69,7 +69,7 @@ namespace RE
if (const auto cellCoords = cell->GetCoordinates(); cellCoords) {
const NiPoint2 worldPos{ cellCoords->worldX, cellCoords->worldY };
if (worldPos.x < xPlus && (worldPos.x + 4096.0f) > xMinus && worldPos.y < yPlus && (worldPos.y + 4096.0f) > yMinus) {
cell->ForEachReferenceInRange(originPos, a_radius, [&](TESObjectREFR& a_ref) {
cell->ForEachReferenceInRange(originPos, a_radius, [&](TESObjectREFR* a_ref) {
return a_callback(a_ref);
});
}
Expand All @@ -83,12 +83,12 @@ namespace RE
}

if (const auto skyCell = worldSpace ? worldSpace->GetSkyCell() : nullptr; skyCell) {
skyCell->ForEachReferenceInRange(originPos, a_radius, [&](TESObjectREFR& a_ref) {
skyCell->ForEachReferenceInRange(originPos, a_radius, [&](TESObjectREFR* a_ref) {
return a_callback(a_ref);
});
}
} else {
ForEachReference([&](TESObjectREFR& a_ref) {
ForEachReference([&](TESObjectREFR* a_ref) {
return a_callback(a_ref);
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/RE/T/TESForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ namespace RE
// Iterate through the keywords
bool hasKeyword = false;

keywordForm->ForEachKeyword([&](const BGSKeyword& a_keyword) {
if (std::ranges::find(editorIDs, a_keyword.GetFormEditorID()) != editorIDs.end()) {
keywordForm->ForEachKeyword([&](const BGSKeyword* a_keyword) {
if (std::ranges::find(editorIDs, a_keyword->GetFormEditorID()) != editorIDs.end()) {
hasKeyword = true;
return BSContainer::ForEachResult::kStop;
}
Expand Down Expand Up @@ -122,8 +122,8 @@ namespace RE

bool hasKeyword = false;

a_keywordList->ForEachForm([&](const TESForm& a_form) {
const auto keyword = a_form.As<BGSKeyword>();
a_keywordList->ForEachForm([&](const TESForm* a_form) {
const auto keyword = a_form->As<BGSKeyword>();
hasKeyword = keyword && keywordForm->HasKeyword(keyword);
if (a_matchAll && !hasKeyword || hasKeyword) {
return BSContainer::ForEachResult::kStop;
Expand Down
10 changes: 5 additions & 5 deletions src/RE/T/TESObjectCELL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@

namespace RE
{
void TESObjectCELL::ForEachReference(std::function<BSContainer::ForEachResult(TESObjectREFR&)> a_callback) const
void TESObjectCELL::ForEachReference(std::function<BSContainer::ForEachResult(TESObjectREFR*)> a_callback) const
{
BSSpinLockGuard locker(spinLock);
for (const auto& ref : references) {
if (ref && a_callback(*ref) == BSContainer::ForEachResult::kStop) {
if (ref && a_callback(ref.get()) == BSContainer::ForEachResult::kStop) {
break;
}
}
}

void TESObjectCELL::ForEachReferenceInRange(const NiPoint3& a_origin, float a_radius, std::function<BSContainer::ForEachResult(TESObjectREFR&)> a_callback) const
void TESObjectCELL::ForEachReferenceInRange(const NiPoint3& a_origin, float a_radius, std::function<BSContainer::ForEachResult(TESObjectREFR*)> a_callback) const
{
const float squaredRadius = a_radius * a_radius;
ForEachReference([&](TESObjectREFR& ref) {
const auto distance = a_origin.GetSquaredDistance(ref.GetPosition());
ForEachReference([&](TESObjectREFR* ref) {
const auto distance = a_origin.GetSquaredDistance(ref->GetPosition());
return distance <= squaredRadius ?
a_callback(ref) :
BSContainer::ForEachResult::kContinue;
Expand Down
4 changes: 2 additions & 2 deletions src/RE/T/TESObjectREFR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ namespace RE

bool hasKeyword = false;

a_keywordList->ForEachForm([&](TESForm& a_form) {
const auto keyword = a_form.As<BGSKeyword>();
a_keywordList->ForEachForm([&](TESForm* a_form) {
const auto keyword = a_form->As<BGSKeyword>();
hasKeyword = keyword && HasKeyword(keyword);
if (a_matchAll && !hasKeyword || hasKeyword) {
return BSContainer::ForEachResult::kStop;
Expand Down

0 comments on commit 78f140e

Please sign in to comment.