From 12a7752a57e11b5984d107d0f225a6fad0c94359 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Wed, 29 Oct 2025 14:52:25 -0500 Subject: [PATCH] feat(model): implement CM2Shared::Release --- src/model/CM2Shared.cpp | 20 +++++++++++++++++--- src/model/CM2Shared.hpp | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/model/CM2Shared.cpp b/src/model/CM2Shared.cpp index 3dcd607..5a910e0 100644 --- a/src/model/CM2Shared.cpp +++ b/src/model/CM2Shared.cpp @@ -53,7 +53,9 @@ void CM2Shared::SkinProfileLoadedCallback(void* arg) { } void CM2Shared::AddRef() { - // TODO + // TODO free list management etc + + this->m_refCount++; } int32_t CM2Shared::CallbackWhenLoaded(CM2Model* model) { @@ -595,8 +597,20 @@ int32_t CM2Shared::LoadSkinProfile(uint32_t profile) { return 1; } -void CM2Shared::Release() { - // TODO +uint32_t CM2Shared::Release() { + STORM_ASSERT(this->m_refCount > 0); + + this->m_refCount--; + + if (this->m_refCount > 0) { + return this->m_refCount; + } + + // TODO free list management etc + + delete this; + + return 0; } int32_t CM2Shared::SetIndices() { diff --git a/src/model/CM2Shared.hpp b/src/model/CM2Shared.hpp index 91d4f2e..da66753 100644 --- a/src/model/CM2Shared.hpp +++ b/src/model/CM2Shared.hpp @@ -26,6 +26,7 @@ class CM2Shared { static void SkinProfileLoadedCallback(void* param); // Member variables + uint32_t m_refCount = 1; CM2Cache* m_cache; uint32_t m_m2DataLoaded : 1; uint32_t m_skinProfileLoaded : 1; @@ -73,7 +74,7 @@ class CM2Shared { int32_t InitializeSkinProfile(); int32_t Load(SFile* file, int32_t a3, CAaBox* a4); int32_t LoadSkinProfile(uint32_t profile); - void Release(); + uint32_t Release(); int32_t SetIndices(); int32_t SetVertices(uint32_t a2); void SubstituteSimpleShaders();