feat(model): implement CM2Model::Release

This commit is contained in:
fallenoak 2025-10-28 08:46:13 -05:00
parent fd7b6fda74
commit e055543167
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 22 additions and 11 deletions

View File

@ -5,12 +5,13 @@
#include "model/CM2Shared.hpp" #include "model/CM2Shared.hpp"
#include "model/M2Animate.hpp" #include "model/M2Animate.hpp"
#include "model/M2Data.hpp" #include "model/M2Data.hpp"
#include "model/M2Internal.hpp"
#include "model/M2Model.hpp" #include "model/M2Model.hpp"
#include <cmath>
#include <new>
#include <common/DataMgr.hpp> #include <common/DataMgr.hpp>
#include <common/ObjectAlloc.hpp> #include <common/ObjectAlloc.hpp>
#include <tempest/Math.hpp> #include <tempest/Math.hpp>
#include <cmath>
#include <new>
// Alignment helpers // Alignment helpers
#define ALIGN(addr, type) ((addr + alignof(type) - 1) & ~(alignof(type) - 1)) #define ALIGN(addr, type) ((addr + alignof(type) - 1) & ~(alignof(type) - 1))
@ -25,13 +26,11 @@ uint32_t CM2Model::s_skinProfileBoneCountMax[] = { 256, 64, 53, 21 };
CM2Model* CM2Model::AllocModel(uint32_t* heapId) { CM2Model* CM2Model::AllocModel(uint32_t* heapId) {
uint32_t memHandle; uint32_t memHandle;
void* object = nullptr; void* mem = nullptr;
if (ObjectAlloc(*heapId, &memHandle, &object, 0)) { if (ObjectAlloc(*heapId, &memHandle, &mem, false)) {
CM2Model* model = new (object) CM2Model(); auto model = new (mem) CM2Model();
model->m_memHandle = memHandle;
// TODO
// model->uint2E8 = memHandle;
return model; return model;
} }
@ -1420,8 +1419,19 @@ void CM2Model::ProcessCallbacksRecursive() {
this->Release(); this->Release();
} }
void CM2Model::Release() { uint32_t CM2Model::Release() {
// TODO STORM_ASSERT(this->m_refCount > 0);
this->m_refCount--;
if (this->m_refCount > 0) {
return this->m_refCount;
}
this->~CM2Model();
ObjectFree(*g_modelPool, this->m_memHandle);
return 0;
} }
void CM2Model::ReplaceTexture(uint32_t textureId, HTEXTURE texture) { void CM2Model::ReplaceTexture(uint32_t textureId, HTEXTURE texture) {

View File

@ -116,6 +116,7 @@ class CM2Model {
void* m_lightingArg = nullptr; void* m_lightingArg = nullptr;
M2ModelCamera* m_cameras = nullptr; M2ModelCamera* m_cameras = nullptr;
void* ptr2D0 = nullptr; void* ptr2D0 = nullptr;
uint32_t m_memHandle;
// Member functions // Member functions
CM2Model() CM2Model()
@ -170,7 +171,7 @@ class CM2Model {
void LinkToCallbackListTail(); void LinkToCallbackListTail();
int32_t ProcessCallbacks(); int32_t ProcessCallbacks();
void ProcessCallbacksRecursive(); void ProcessCallbacksRecursive();
void Release(); uint32_t Release();
void ReplaceTexture(uint32_t textureId, HTEXTURE texture); void ReplaceTexture(uint32_t textureId, HTEXTURE texture);
void SetAnimating(int32_t animating); void SetAnimating(int32_t animating);
void SetBoneSequence(uint32_t boneId, uint32_t sequenceId, uint32_t a4, uint32_t time, float a6, int32_t a7, int32_t a8); void SetBoneSequence(uint32_t boneId, uint32_t sequenceId, uint32_t a4, uint32_t time, float a6, int32_t a7, int32_t a8);