Skip to content

Allow unload model with custom col #2866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 3 additions & 41 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ CModelInfoSA::CModelInfoSA()
m_pOriginalColModelInterface = NULL;
m_pCustomClump = NULL;
m_pCustomColModel = NULL;
m_bAddedRefForCollision = false;
}

CBaseModelInfoSAInterface* CModelInfoSA::GetInterface()
Expand Down Expand Up @@ -391,36 +390,15 @@ void CModelInfoSA::Remove()

m_pInterface = ppModelInfo[m_dwModelID];

// Remove ref added for collision
if (m_bAddedRefForCollision)
{
m_bAddedRefForCollision = false;
if (m_pInterface->usNumberOfRefs > 0)
m_pInterface->usNumberOfRefs--;
}

// Remove our reference
if (m_pInterface->usNumberOfRefs > 0)
m_pInterface->usNumberOfRefs--;

// No references left?
if (m_pInterface->usNumberOfRefs == 0)
if (m_pInterface->usNumberOfRefs == 0 && !m_pCustomClump && !m_pCustomColModel)
{
// We have a custom model?
if (m_pCustomClump)
{
// Mark us as unloaded. We manage the clump unloading.
// BYTE *ModelLoaded = (BYTE*)ARRAY_ModelLoaded;
// ModelLoaded[(m_dwModelID+m_dwModelID*4)<<2] = 0;
}
else
{
// Make our collision model original again before we unload.
RestoreColModel();

// Remove the model.
pGame->GetStreaming()->RemoveModel(m_dwModelID);
}
// Remove the model.
pGame->GetStreaming()->RemoveModel(m_dwModelID);
}
}

Expand Down Expand Up @@ -1249,15 +1227,6 @@ void CModelInfoSA::SetColModel(CColModel* pColModel)
// Grab the interfaces
CColModelSAInterface* pColModelInterface = pColModel->GetInterface();

if (!m_bAddedRefForCollision)
{
// Prevent this model from unloading while we have custom collision
ModelAddRef(BLOCKING, "for collision");
m_bAddedRefForCollision = true;
}

// Should always be loaded at this point

// Skip setting if already done
if (m_pCustomColModel == pColModel)
return;
Expand Down Expand Up @@ -1330,13 +1299,6 @@ void CModelInfoSA::RestoreColModel()
m_pCustomColModel = nullptr;
m_pOriginalColModelInterface = nullptr;
m_originalFlags = 0;

// Remove ref added for collision
if (m_bAddedRefForCollision)
{
m_bAddedRefForCollision = false;
RemoveRef();
}
}

void CModelInfoSA::MakeCustomModel()
Expand Down
1 change: 0 additions & 1 deletion Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ class CModelInfoSA : public CModelInfo
static std::map<CTimeInfoSAInterface*, CTimeInfoSAInterface*> ms_ModelDefaultModelTimeInfo;
static std::unordered_map<DWORD, unsigned short> ms_OriginalObjectPropertiesGroups;
static std::unordered_map<DWORD, std::pair<float, float>> ms_VehicleModelDefaultWheelSizes;
bool m_bAddedRefForCollision;
SVehicleSupportedUpgrades m_ModelSupportedUpgrades;

public:
Expand Down