Skip to content

Commit

Permalink
Allow dynamic models to be created as buildings (#3880)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij authored Dec 14, 2024
1 parent 35cb2e7 commit 642438e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
12 changes: 11 additions & 1 deletion Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint1
if (!HasFreeBuildingSlot())
return nullptr;

auto modelInfo = pGame->GetModelInfo(modelId);

// Change the properties group to force dynamic models to be created as buildings instead of dummies
auto prevGroup = modelInfo->GetObjectPropertiesGroup();
if (prevGroup != MODEL_PROPERTIES_GROUP_STATIC)
modelInfo->SetObjectPropertiesGroup(MODEL_PROPERTIES_GROUP_STATIC);

// Load building
SFileObjectInstance instance;
instance.modelID = modelId;
Expand All @@ -70,9 +77,12 @@ CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint1
pBuilding->m_pLod = nullptr;
pBuilding->m_iplIndex = 0;

// Restore changed properties group
if (prevGroup != MODEL_PROPERTIES_GROUP_STATIC)
modelInfo->SetObjectPropertiesGroup(prevGroup);

// Always stream model collosion
// TODO We can setup collison bounding box and use GTA streamer for it
auto modelInfo = pGame->GetModelInfo(modelId);
modelInfo->AddColRef();

// Add building in world
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class CModelInfoSA : public CModelInfo
// Vehicle towing functions
bool IsTowableBy(CModelInfo* towingModel) override;

bool IsDynamic() { return m_pInterface ? m_pInterface->usDynamicIndex != 0xffff : false; };
bool IsDynamic() { return m_pInterface ? m_pInterface->usDynamicIndex != MODEL_PROPERTIES_GROUP_STATIC : false; };

private:
void CopyStreamingInfoFromModel(ushort usCopyFromModelID);
Expand Down
27 changes: 1 addition & 26 deletions Client/mods/deathmatch/logic/CClientBuildingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ bool CClientBuildingManager::IsValidModel(uint16_t modelId)
if (!pModelInfo->IsAllocatedInArchive())
return false;

if (pModelInfo->IsDynamic())
{
return false;
}

eModelInfoType eType = pModelInfo->GetModelType();
return (eType == eModelInfoType::CLUMP || eType == eModelInfoType::ATOMIC || eType == eModelInfoType::WEAPON || eType == eModelInfoType::TIME);
}
Expand Down Expand Up @@ -106,29 +101,9 @@ void CClientBuildingManager::RestoreDestroyed()
{
const CClientBuilding* highLodBuilding = building->GetHighLodBuilding();
if (highLodBuilding && !highLodBuilding->IsValid())
{
hasInvalidLods = true;
}
else
{
CModelInfo* modelInfo = building->GetModelInfo();
const uint16_t physicalGroup = modelInfo->GetObjectPropertiesGroup();

if (physicalGroup == -1)
{
building->Create();
}
else
{
// GTA creates dynamic models as dummies.
// It's possible that the physical group was changes after
// creating a new building. We can avoid crashes in this case.
modelInfo->SetObjectPropertiesGroup(-1);
building->Create();
modelInfo->SetObjectPropertiesGroup(physicalGroup);
}

}
building->Create();
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Client/sdk/game/CModelInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "CAnimBlock.h"
#include "Common.h"

constexpr std::uint16_t MODEL_PROPERTIES_GROUP_STATIC = 0xFFFF;

class CBaseModelInfoSAInterface;
class CColModel;
class CPedModelInfo;
Expand Down Expand Up @@ -131,6 +133,7 @@ struct SVehicleSupportedUpgrades
bool m_bMisc;
bool m_bInitialised;
};

class CModelInfo
{
public:
Expand Down

0 comments on commit 642438e

Please sign in to comment.