diff --git a/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp b/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp index 6dc661d9..8f1417d6 100644 --- a/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp +++ b/src/ObjLoading/Game/IW4/Menu/LoaderMenuListIW4.cpp @@ -63,7 +63,7 @@ namespace menuLoadQueue.pop_front(); } - auto* menuListAsset = m_memory.Create(); + auto* menuListAsset = m_memory.Alloc(); menuListAsset->name = m_memory.Dup(assetName.c_str()); registration.SetAsset(menuListAsset); diff --git a/src/ObjLoading/Game/IW4/Menu/MenuConversionZoneStateIW4.cpp b/src/ObjLoading/Game/IW4/Menu/MenuConversionZoneStateIW4.cpp index 5bded2c4..68d9ebe8 100644 --- a/src/ObjLoading/Game/IW4/Menu/MenuConversionZoneStateIW4.cpp +++ b/src/ObjLoading/Game/IW4/Menu/MenuConversionZoneStateIW4.cpp @@ -15,8 +15,7 @@ void MenuConversionZoneState::Inject(ZoneAssetCreationInjection& inject) auto* memory = inject.m_zone.GetMemory(); m_zone = &inject.m_zone; - m_supporting_data = memory->Create(); - memset(m_supporting_data, 0, sizeof(ExpressionSupportingData)); + m_supporting_data = memory->Alloc(); } Statement_s* MenuConversionZoneState::FindFunction(const std::string& functionName) diff --git a/src/ObjLoading/Game/IW5/Menu/LoaderMenuListIW5.cpp b/src/ObjLoading/Game/IW5/Menu/LoaderMenuListIW5.cpp index e4058d18..62b27cd5 100644 --- a/src/ObjLoading/Game/IW5/Menu/LoaderMenuListIW5.cpp +++ b/src/ObjLoading/Game/IW5/Menu/LoaderMenuListIW5.cpp @@ -63,7 +63,7 @@ namespace menuLoadQueue.pop_front(); } - auto* menuListAsset = m_memory.Create(); + auto* menuListAsset = m_memory.Alloc(); menuListAsset->name = m_memory.Dup(assetName.c_str()); registration.SetAsset(menuListAsset); diff --git a/src/ObjLoading/Game/IW5/Menu/MenuConversionZoneStateIW5.cpp b/src/ObjLoading/Game/IW5/Menu/MenuConversionZoneStateIW5.cpp index 89f23c85..58234579 100644 --- a/src/ObjLoading/Game/IW5/Menu/MenuConversionZoneStateIW5.cpp +++ b/src/ObjLoading/Game/IW5/Menu/MenuConversionZoneStateIW5.cpp @@ -15,8 +15,7 @@ void MenuConversionZoneState::Inject(ZoneAssetCreationInjection& inject) auto* memory = inject.m_zone.GetMemory(); m_zone = &inject.m_zone; - m_supporting_data = memory->Create(); - memset(m_supporting_data, 0, sizeof(ExpressionSupportingData)); + m_supporting_data = memory->Alloc(); } Statement_s* MenuConversionZoneState::FindFunction(const std::string& functionName) diff --git a/src/ObjLoading/StringTable/StringTableLoader.h b/src/ObjLoading/StringTable/StringTableLoader.h index 1678a404..991f98ec 100644 --- a/src/ObjLoading/StringTable/StringTableLoader.h +++ b/src/ObjLoading/StringTable/StringTableLoader.h @@ -26,7 +26,7 @@ namespace string_table public: StringTableType* LoadFromStream(const std::string& assetName, MemoryManager& memory, std::istream& stream) { - auto* stringTable = memory.Create(); + auto* stringTable = memory.Alloc(); stringTable->name = memory.Dup(assetName.c_str()); std::vector> csvLines; diff --git a/src/Utils/Utils/MemoryManager.cpp b/src/Utils/Utils/MemoryManager.cpp index 94993729..5132d10c 100644 --- a/src/Utils/Utils/MemoryManager.cpp +++ b/src/Utils/Utils/MemoryManager.cpp @@ -3,27 +3,14 @@ #include #include -MemoryManager::AllocationInfo::AllocationInfo(IDestructible* data, void* dataPtr) -{ - m_data = data; - m_data_ptr = dataPtr; -} - MemoryManager::MemoryManager() = default; MemoryManager::~MemoryManager() { - for (auto allocation : m_allocations) - { + for (auto* allocation : m_allocations) free(allocation); - } - m_allocations.clear(); - for (auto destructible : m_destructible) - { - delete destructible.m_data; - } - m_destructible.clear(); + m_allocations.clear(); } void* MemoryManager::AllocRaw(const size_t size) @@ -58,16 +45,3 @@ void MemoryManager::Free(const void* data) } } } - -void MemoryManager::Delete(const void* data) -{ - for (auto iAlloc = m_destructible.begin(); iAlloc != m_destructible.end(); ++iAlloc) - { - if (iAlloc->m_data_ptr == data) - { - delete iAlloc->m_data; - m_destructible.erase(iAlloc); - return; - } - } -} diff --git a/src/Utils/Utils/MemoryManager.h b/src/Utils/Utils/MemoryManager.h index c9eeefb5..dcc03e8f 100644 --- a/src/Utils/Utils/MemoryManager.h +++ b/src/Utils/Utils/MemoryManager.h @@ -14,64 +14,16 @@ public: MemoryManager& operator=(const MemoryManager& other) = delete; MemoryManager& operator=(MemoryManager&& other) noexcept = default; - void* AllocRaw(size_t size); + void* AllocRaw(std::size_t size); char* Dup(const char* str); - template std::add_pointer_t Alloc(const size_t count = 1u) + template std::add_pointer_t Alloc(const std::size_t count = 1u) { return static_cast>(AllocRaw(sizeof(T) * count)); } - template std::add_pointer_t Create(ValType&&... val) - { - Allocation* allocation = new Allocation(std::forward(val)...); - m_destructible.emplace_back(allocation, &allocation->m_entry); - return &allocation->m_entry; - } - void Free(const void* data); - void Delete(const void* data); protected: - class IDestructible - { - public: - IDestructible() = default; - virtual ~IDestructible() = default; - IDestructible(const IDestructible& other) = default; - IDestructible(IDestructible&& other) noexcept = default; - IDestructible& operator=(const IDestructible& other) = default; - IDestructible& operator=(IDestructible&& other) noexcept = default; - }; - - template class Allocation final : public IDestructible - { - public: - T m_entry; - - template - explicit Allocation(ValType&&... val) - : m_entry(std::forward(val)...) - { - } - - ~Allocation() override = default; - - Allocation(const Allocation& other) = delete; - Allocation(Allocation&& other) noexcept = delete; - Allocation& operator=(const Allocation& other) = delete; - Allocation& operator=(Allocation&& other) noexcept = delete; - }; - - class AllocationInfo - { - public: - IDestructible* m_data; - void* m_data_ptr; - - AllocationInfo(IDestructible* data, void* dataPtr); - }; - std::vector m_allocations; - std::vector m_destructible; }; diff --git a/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp b/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp index 9c122db8..887dc3ae 100644 --- a/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp +++ b/src/ZoneLoading/Game/IW4/XAssets/xmodel/xmodel_actions.cpp @@ -13,7 +13,7 @@ void Actions_XModel::SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSur { if (modelSurfs) { - lodInfo->modelSurfs = m_zone->GetMemory()->Create(); + lodInfo->modelSurfs = m_zone->GetMemory()->Alloc(); memcpy(lodInfo->modelSurfs, modelSurfs, sizeof(XModelSurfs)); } } diff --git a/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp b/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp index 7b1590a5..5739c607 100644 --- a/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp +++ b/src/ZoneLoading/Game/IW5/XAssets/xmodel/xmodel_actions.cpp @@ -13,7 +13,7 @@ void Actions_XModel::SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSur { if (modelSurfs) { - lodInfo->modelSurfs = m_zone->GetMemory()->Create(); + lodInfo->modelSurfs = m_zone->GetMemory()->Alloc(); memcpy(lodInfo->modelSurfs, modelSurfs, sizeof(XModelSurfs)); } } diff --git a/test/ObjCommonTestUtils/Utils/TestMemoryManager.h b/test/ObjCommonTestUtils/Utils/TestMemoryManager.h index 3ac27e41..d58221fd 100644 --- a/test/ObjCommonTestUtils/Utils/TestMemoryManager.h +++ b/test/ObjCommonTestUtils/Utils/TestMemoryManager.h @@ -9,6 +9,6 @@ class TestMemoryManager : public MemoryManager public: [[nodiscard]] size_t GetAllocationCount() const { - return m_allocations.size() + m_destructible.size(); + return m_allocations.size(); } }; diff --git a/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp b/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp index 4c231d78..c9029a9c 100644 --- a/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp +++ b/test/ObjLoadingTests/Game/IW4/Menu/LoaderMenuListIW4Test.cpp @@ -51,7 +51,7 @@ namespace test::game::iw4::menu::parsing::it Material* AddMaterial(const std::string& name) { - auto* material = m_zone.GetMemory()->Create(); + auto* material = m_zone.GetMemory()->Alloc(); material->info.name = m_zone.GetMemory()->Dup(name.c_str()); m_context.AddAsset(name, material);