Skip to content
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

Allow dynamic models to be created as buildings #3880

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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;

// Resore changes properties group
TheNormalnij marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -466,7 +466,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; };
TheNormalnij marked this conversation as resolved.
Show resolved Hide resolved

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
Loading