diff --git a/include/RE/B/BGSKeywordForm.h b/include/RE/B/BGSKeywordForm.h index 2ae40869c..29d23dafb 100644 --- a/include/RE/B/BGSKeywordForm.h +++ b/include/RE/B/BGSKeywordForm.h @@ -27,7 +27,7 @@ namespace RE bool AddKeyword(BGSKeyword* a_keyword); bool AddKeywords(const std::vector& a_keywords); [[nodiscard]] bool ContainsKeywordString(std::string_view a_editorID) const; - void ForEachKeyword(std::function a_callback) const; + void ForEachKeyword(std::function a_callback) const; [[nodiscard]] std::optional GetKeywordAt(std::uint32_t a_idx) const; [[nodiscard]] std::optional GetKeywordIndex(BGSKeyword* a_keyword) const; [[nodiscard]] std::uint32_t GetNumKeywords() const; @@ -35,7 +35,7 @@ namespace RE [[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& a_keywords); + bool RemoveKeywords(const std::vector& a_keywords); // members BGSKeyword** keywords; // 08 - KWDA diff --git a/include/RE/B/BGSListForm.h b/include/RE/B/BGSListForm.h index e70fc5048..978367d95 100644 --- a/include/RE/B/BGSListForm.h +++ b/include/RE/B/BGSListForm.h @@ -43,7 +43,7 @@ namespace RE void AddForm(TESForm* a_form); [[nodiscard]] bool ContainsOnlyType(FormType a_formType) const; - void ForEachForm(std::function a_callback) const; + void ForEachForm(std::function a_callback) const; [[nodiscard]] bool HasForm(const TESForm* a_form) const; [[nodiscard]] bool HasForm(FormID a_formID) const; diff --git a/include/RE/B/BGSOutfit.h b/include/RE/B/BGSOutfit.h index 55d00a9f2..36002ad66 100644 --- a/include/RE/B/BGSOutfit.h +++ b/include/RE/B/BGSOutfit.h @@ -30,10 +30,10 @@ namespace RE bool Load(TESFile* a_mod) override; // 06 void InitItemImpl() override; // 13 - void ForEachItem(std::function a_callback) const + void ForEachItem(std::function a_callback) const { for (auto& item : outfitItems) { - if (item && a_callback(*item) == BSContainer::ForEachResult::kStop) { + if (item && a_callback(item) == BSContainer::ForEachResult::kStop) { return; } } diff --git a/include/RE/P/ProcessLists.h b/include/RE/P/ProcessLists.h index db8c8b40e..18d9d7ec1 100644 --- a/include/RE/P/ProcessLists.h +++ b/include/RE/P/ProcessLists.h @@ -36,11 +36,11 @@ namespace RE static ProcessLists* GetSingleton(); void ClearCachedFactionFightReactions() const; - void ForAllActors(std::function a_callback); - void ForEachHighActor(std::function a_callback); - void ForEachMagicTempEffect(std::function a_callback); - void ForEachModelEffect(std::function a_callback); - void ForEachShaderEffect(std::function a_callback); + void ForAllActors(std::function a_callback); + void ForEachHighActor(std::function a_callback); + void ForEachMagicTempEffect(std::function a_callback); + void ForEachModelEffect(std::function a_callback); + void ForEachShaderEffect(std::function a_callback); float GetSystemTimeClock(); std::int16_t RequestHighestDetectionLevelAgainstActor(Actor* a_actor, std::uint32_t& a_LOSCount); void StopAllMagicEffects(TESObjectREFR& a_ref); diff --git a/include/RE/T/TES.h b/include/RE/T/TES.h index 73387d824..e586f9ef1 100644 --- a/include/RE/T/TES.h +++ b/include/RE/T/TES.h @@ -66,8 +66,8 @@ namespace RE static TES* GetSingleton(); - void ForEachReference(std::function a_callback); - void ForEachReferenceInRange(TESObjectREFR* a_origin, float a_radius, std::function a_callback); + void ForEachReference(std::function a_callback); + void ForEachReferenceInRange(TESObjectREFR* a_origin, float a_radius, std::function a_callback); TESObjectCELL* GetCell(const NiPoint3& a_position) const; MATERIAL_ID GetLandMaterialType(const NiPoint3& a_position) const; diff --git a/include/RE/T/TESObjectCELL.h b/include/RE/T/TESObjectCELL.h index eb6c58399..eb5ee231b 100644 --- a/include/RE/T/TESObjectCELL.h +++ b/include/RE/T/TESObjectCELL.h @@ -194,8 +194,8 @@ namespace RE TESNPC* GetActorOwner(); bhkWorld* GetbhkWorld() const; - void ForEachReference(std::function a_callback) const; - void ForEachReferenceInRange(const NiPoint3& a_origin, float a_radius, std::function a_callback) const; + void ForEachReference(std::function a_callback) const; + void ForEachReferenceInRange(const NiPoint3& a_origin, float a_radius, std::function a_callback) const; EXTERIOR_DATA* GetCoordinates(); TESFaction* GetFactionOwner(); INTERIOR_DATA* GetLighting(); diff --git a/src/RE/B/BGSKeywordForm.cpp b/src/RE/B/BGSKeywordForm.cpp index 93154b46b..14a2c15c8 100644 --- a/src/RE/B/BGSKeywordForm.cpp +++ b/src/RE/B/BGSKeywordForm.cpp @@ -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; } @@ -52,11 +52,11 @@ namespace RE return result; } - void BGSKeywordForm::ForEachKeyword(std::function a_callback) const + void BGSKeywordForm::ForEachKeyword(std::function 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; } } @@ -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; } @@ -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; } @@ -129,7 +129,7 @@ namespace RE return index ? RemoveKeyword(*index) : false; } - bool BGSKeywordForm::RemoveKeywords(const std::vector& a_keywords) + bool BGSKeywordForm::RemoveKeywords(const std::vector& a_keywords) { std::vector copiedData{ keywords, keywords + numKeywords }; if (std::erase_if(copiedData, [&](auto& keyword) { return std::ranges::find(a_keywords, keyword) != a_keywords.end(); }) > 0) { diff --git a/src/RE/B/BGSListForm.cpp b/src/RE/B/BGSListForm.cpp index 15361c080..5433b8c97 100644 --- a/src/RE/B/BGSListForm.cpp +++ b/src/RE/B/BGSListForm.cpp @@ -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; } @@ -47,17 +47,17 @@ namespace RE return HasForm(form); } - void BGSListForm::ForEachForm(std::function a_callback) const + void BGSListForm::ForEachForm(std::function 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; } } diff --git a/src/RE/P/ProcessLists.cpp b/src/RE/P/ProcessLists.cpp index cd861fd0e..acf86dfd4 100644 --- a/src/RE/P/ProcessLists.cpp +++ b/src/RE/P/ProcessLists.cpp @@ -21,13 +21,13 @@ namespace RE return func(this); } - void ProcessLists::ForAllActors(std::function a_callback) + void ProcessLists::ForAllActors(std::function 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; } } @@ -35,44 +35,44 @@ namespace RE } } - void ProcessLists::ForEachHighActor(std::function a_callback) + void ProcessLists::ForEachHighActor(std::function 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 a_callback) + void ProcessLists::ForEachMagicTempEffect(std::function 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 a_callback) + void ProcessLists::ForEachModelEffect(std::function a_callback) { - ForEachMagicTempEffect([a_callback](BSTempEffect& a_tempEffect) { - const auto modelEffect = a_tempEffect.As(); - if (modelEffect && a_callback(*modelEffect) == BSContainer::ForEachResult::kStop) { + ForEachMagicTempEffect([a_callback](BSTempEffect* a_tempEffect) { + const auto modelEffect = a_tempEffect->As(); + if (modelEffect && a_callback(modelEffect) == BSContainer::ForEachResult::kStop) { return BSContainer::ForEachResult::kStop; } return BSContainer::ForEachResult::kContinue; }); } - void ProcessLists::ForEachShaderEffect(std::function a_callback) + void ProcessLists::ForEachShaderEffect(std::function a_callback) { - ForEachMagicTempEffect([a_callback](BSTempEffect& a_tempEffect) { - const auto shaderEffect = a_tempEffect.As(); - if (shaderEffect && a_callback(*shaderEffect) == BSContainer::ForEachResult::kStop) { + ForEachMagicTempEffect([a_callback](BSTempEffect* a_tempEffect) { + const auto shaderEffect = a_tempEffect->As(); + if (shaderEffect && a_callback(shaderEffect) == BSContainer::ForEachResult::kStop) { return BSContainer::ForEachResult::kStop; } return BSContainer::ForEachResult::kContinue; @@ -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(); + ForEachMagicTempEffect([&](BSTempEffect* a_tempEffect) { + const auto referenceEffect = a_tempEffect->As(); if (referenceEffect && referenceEffect->target == handle) { referenceEffect->finished = true; } diff --git a/src/RE/T/TES.cpp b/src/RE/T/TES.cpp index 485a3620f..8e6305308 100644 --- a/src/RE/T/TES.cpp +++ b/src/RE/T/TES.cpp @@ -15,10 +15,10 @@ namespace RE return *singleton; } - void TES::ForEachReference(std::function a_callback) + void TES::ForEachReference(std::function a_callback) { if (interiorCell) { - interiorCell->ForEachReference([&](TESObjectREFR& a_ref) { + interiorCell->ForEachReference([&](TESObjectREFR* a_ref) { return a_callback(a_ref); }); } else { @@ -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); }); } @@ -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 a_callback) + void TES::ForEachReferenceInRange(TESObjectREFR* a_origin, float a_radius, std::function 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 { @@ -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); }); } @@ -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); }); } diff --git a/src/RE/T/TESForm.cpp b/src/RE/T/TESForm.cpp index d280c2869..68b67cd00 100644 --- a/src/RE/T/TESForm.cpp +++ b/src/RE/T/TESForm.cpp @@ -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; } @@ -122,8 +122,8 @@ namespace RE bool hasKeyword = false; - a_keywordList->ForEachForm([&](const TESForm& a_form) { - const auto keyword = a_form.As(); + a_keywordList->ForEachForm([&](const TESForm* a_form) { + const auto keyword = a_form->As(); hasKeyword = keyword && keywordForm->HasKeyword(keyword); if (a_matchAll && !hasKeyword || hasKeyword) { return BSContainer::ForEachResult::kStop; diff --git a/src/RE/T/TESObjectCELL.cpp b/src/RE/T/TESObjectCELL.cpp index e93c657c9..779df2405 100644 --- a/src/RE/T/TESObjectCELL.cpp +++ b/src/RE/T/TESObjectCELL.cpp @@ -10,21 +10,21 @@ namespace RE { - void TESObjectCELL::ForEachReference(std::function a_callback) const + void TESObjectCELL::ForEachReference(std::function 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 a_callback) const + void TESObjectCELL::ForEachReferenceInRange(const NiPoint3& a_origin, float a_radius, std::function 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; diff --git a/src/RE/T/TESObjectREFR.cpp b/src/RE/T/TESObjectREFR.cpp index f7a782f8d..9d83840dd 100644 --- a/src/RE/T/TESObjectREFR.cpp +++ b/src/RE/T/TESObjectREFR.cpp @@ -578,8 +578,8 @@ namespace RE bool hasKeyword = false; - a_keywordList->ForEachForm([&](TESForm& a_form) { - const auto keyword = a_form.As(); + a_keywordList->ForEachForm([&](TESForm* a_form) { + const auto keyword = a_form->As(); hasKeyword = keyword && HasKeyword(keyword); if (a_matchAll && !hasKeyword || hasKeyword) { return BSContainer::ForEachResult::kStop;