diff --git a/Source/Contents/Async/AsyncWorkRecycleObjectPoolMgr.cpp b/Source/Contents/Async/AsyncWorkRecycleObjectPoolMgr.cpp index 03782740..e1806ab5 100644 --- a/Source/Contents/Async/AsyncWorkRecycleObjectPoolMgr.cpp +++ b/Source/Contents/Async/AsyncWorkRecycleObjectPoolMgr.cpp @@ -13,7 +13,7 @@ #include "Contents/Party/RegisterPartyAsyncWork.h" #include "Contents/Party/StopRecruitingAsyncWork.h" -#include +#include #include // OFFSET: 0x00576660 @@ -34,24 +34,47 @@ CAsyncWorkRecycleObjectPoolMgr::~CAsyncWorkRecycleObjectPoolMgr() { // OFFSET: 0x00578F30 // FUNCTION: fn_02566 bool CAsyncWorkRecycleObjectPoolMgr::RegisterPools() { - const auto insert = [&](const char* name) { - std::unique_ptr pool(new (std::nothrow) NRecycleObjectPool(2)); - if (!this->m_pools.emplace(name, pool.get()).second) { - return false; - } - - (void) pool.release(); - return true; - }; - - return insert.operator()("AccountLinkedUserData_Load") && - insert.operator()("AccountLinkedUserData_Save") && - insert.operator()("CharacterLinkedUserData_Load") && - insert.operator()("CharacterLinkedUserData_Save") && - insert.operator()("Emblem_Upload") && insert.operator()("Emblem_Download") && - insert.operator()("MerchantStoreInformation_Load") && - insert.operator()("MerchantStoreInformation_Save") && insert.operator()("PartyList_Load") && - insert.operator()("MyParty_Load") && insert.operator()("Register_Party") && - insert.operator()("Stop_Recruiting") && insert.operator()("Change_PartyMaster") && - insert.operator()("PartyInfo_Load"); + if (!this->m_pools.insert(std::make_pair("AccountLinkedUserData_Load", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("AccountLinkedUserData_Save", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("CharacterLinkedUserData_Load", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("CharacterLinkedUserData_Save", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("Emblem_Upload", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("Emblem_Download", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("MerchantStoreInformation_Load", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("MerchantStoreInformation_Save", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("PartyList_Load", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("MyParty_Load", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("Register_Party", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("Stop_Recruiting", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("Change_PartyMaster", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + if (!this->m_pools.insert(std::make_pair("PartyInfo_Load", new (std::nothrow) NRecycleObjectPool(2))).second) { + return false; + } + return true; } diff --git a/Source/Utility/Async/NRecycleObject.h b/Source/Utility/Async/NRecycleObject.h index 4c6f29eb..f3151482 100644 --- a/Source/Utility/Async/NRecycleObject.h +++ b/Source/Utility/Async/NRecycleObject.h @@ -41,7 +41,8 @@ template class NRecycleObjectPool : public NRecycleObjectPoolInter { public: // OFFSET: 0x00575AC0 // FUNCTION: fn_02529 - explicit NRecycleObjectPool(std::uint32_t minimumFree) : m_enabled(false), m_minimumFree(minimumFree) { + explicit NRecycleObjectPool(std::uint32_t minimumFree) : m_minimumFree(minimumFree) { + this->m_enabled = false; InitializeCriticalSection(&this->m_criticalSection); this->m_enabled = true; } @@ -85,18 +86,17 @@ public: T* Acquire() override { NSyncObject held(&this->m_criticalSection); T* object; - if (this->m_free.size() >= this->m_minimumFree) { + if (this->m_free.size() < this->m_minimumFree) { + object = new (std::nothrow) T; + if (object == nullptr) { + return nullptr; + } + this->m_objects.push_back(object); + } else { object = this->m_free.front(); this->m_free.pop_front(); - } else { - object = new (std::nothrow) T; - if (object) { - this->m_objects.push_back(object); - } - } - if (object) { - object->Reset(); } + object->Reset(); return object; } @@ -133,8 +133,7 @@ public: if (object) { auto owned = std::find(this->m_objects.begin(), this->m_objects.end(), object); if (owned != this->m_objects.end()) { - - this->m_free.push_back(*owned); + this->m_free.push_back(static_cast(object)); } } }