collision fixes: fix miami linked list corruption, liberty replica

This commit is contained in:
Stefanos Kornilios Mitsis Poiitidis
2025-03-23 07:39:22 +02:00
committed by Stefanos Kornilios Mitsis Poiitidis
parent aba5bdac62
commit 3b7f5cffc3
6 changed files with 38 additions and 3 deletions

View File

@@ -2287,6 +2287,15 @@ CCollision::DistToLine(const CVector *l0, const CVector *l1, const CVector *poin
return (*point - closest).Magnitude(); return (*point - closest).Magnitude();
} }
void
CCollision::RemoveTrianglePlanes(CColModel *model)
{
if(model->trianglePlanes){
ms_colModelCache.Remove(model->GetLinkPtr());
model->RemoveTrianglePlanes();
}
}
void void
CCollision::CalculateTrianglePlanes(CColModel *model) CCollision::CalculateTrianglePlanes(CColModel *model)
{ {

View File

@@ -41,6 +41,7 @@ public:
static void DrawColModel(const CMatrix &mat, const CColModel &colModel); static void DrawColModel(const CMatrix &mat, const CColModel &colModel);
static void DrawColModel_Coloured(const CMatrix &mat, const CColModel &colModel, int32 id); static void DrawColModel_Coloured(const CMatrix &mat, const CColModel &colModel, int32 id);
static void RemoveTrianglePlanes(CColModel *model);
static void CalculateTrianglePlanes(CColModel *model); static void CalculateTrianglePlanes(CColModel *model);
// all these return true if there's a collision // all these return true if there's a collision

View File

@@ -257,6 +257,24 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
model.boundingBox.max.z = *(float*)(buf+36); model.boundingBox.max.z = *(float*)(buf+36);
model.numSpheres = *(int16*)(buf+40); model.numSpheres = *(int16*)(buf+40);
buf += 44; buf += 44;
if (model.spheres) {
RwFree(model.spheres);
}
if (model.lines) {
RwFree(model.lines);
}
if (model.boxes) {
RwFree(model.boxes);
}
if (model.vertices) {
RwFree(model.vertices);
}
if (model.triangles) {
RwFree(model.triangles);
}
if (model.trianglePlanes) {
CCollision::RemoveTrianglePlanes(&model);
}
if(model.numSpheres > 0){ if(model.numSpheres > 0){
model.spheres = (CColSphere*)RwMalloc(model.numSpheres*sizeof(CColSphere)); model.spheres = (CColSphere*)RwMalloc(model.numSpheres*sizeof(CColSphere));
REGISTER_MEMPTR(&model.spheres); REGISTER_MEMPTR(&model.spheres);

View File

@@ -38,6 +38,14 @@ CBaseModelInfo::DeleteCollisionModel(void)
} }
} }
void CBaseModelInfo::SetColModel(CColModel *col, bool owns) {
if (m_bOwnsColModel) {
delete m_colModel;
}
m_colModel = col;
m_bOwnsColModel = owns;
}
void void
CBaseModelInfo::AddRef(void) CBaseModelInfo::AddRef(void)
{ {

View File

@@ -56,8 +56,7 @@ public:
} }
char *GetModelName(void) { return m_name; } char *GetModelName(void) { return m_name; }
void SetModelName(const char *name) { strncpy(m_name, name, MAX_MODEL_NAME); } void SetModelName(const char *name) { strncpy(m_name, name, MAX_MODEL_NAME); }
void SetColModel(CColModel *col, bool owns = false){ void SetColModel(CColModel *col, bool owns = false);
m_colModel = col; m_bOwnsColModel = owns; }
CColModel *GetColModel(void) { return m_colModel; } CColModel *GetColModel(void) { return m_colModel; }
bool DoesOwnColModel(void) { return m_bOwnsColModel; } bool DoesOwnColModel(void) { return m_bOwnsColModel; }
void DeleteCollisionModel(void); void DeleteCollisionModel(void);

View File

@@ -321,7 +321,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
RwFree(model.triangles); RwFree(model.triangles);
} }
if (model.trianglePlanes) { if (model.trianglePlanes) {
RwFree(model.trianglePlanes); CCollision::RemoveTrianglePlanes(&model);
} }
if(model.numSpheres > 0){ if(model.numSpheres > 0){
model.spheres = (CColSphere*)RwMalloc(model.numSpheres*sizeof(CColSphere)); model.spheres = (CColSphere*)RwMalloc(model.numSpheres*sizeof(CColSphere));