Skip to content
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
17 changes: 17 additions & 0 deletions Client/game_sa/CBuildingRemovalSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,12 @@ bool CBuildingRemovalSA::RestoreBuilding(uint16_t usModelToRestore, float fRange
}
}
}

// Remove the building from the list
m_pBuildingRemovals->erase(iter++);

delete pFind;

// Success! don't return incase there are any others to delete
bSuccess = true;
}
Expand All @@ -268,6 +271,7 @@ bool CBuildingRemovalSA::RestoreBuilding(uint16_t usModelToRestore, float fRange
else
iter++;
}

std::pair<std::multimap<uint16_t, sDataBuildingRemovalItem*>::iterator, std::multimap<uint16_t, sDataBuildingRemovalItem*>::iterator>
dataBuildingIterators = m_pDataBuildings->equal_range(usModelToRestore);
std::multimap<uint16_t, sDataBuildingRemovalItem*>::const_iterator iterator = dataBuildingIterators.first;
Expand Down Expand Up @@ -367,6 +371,7 @@ bool CBuildingRemovalSA::IsRemovedModelInRadius(SIPLInst* pInst)
}
}
}

return false;
}

Expand Down Expand Up @@ -400,6 +405,7 @@ bool CBuildingRemovalSA::IsObjectRemoved(CEntitySAInterface* pInterface)
}

float fDistance = sqrt(fDistanceX * fDistanceX + fDistanceY * fDistanceY + fDistanceZ * fDistanceZ);

// is it in the removal spheres radius if so return else keep looking
if (fDistance <= pFind->m_fRadius)
{
Expand All @@ -408,6 +414,7 @@ bool CBuildingRemovalSA::IsObjectRemoved(CEntitySAInterface* pInterface)
}
}
}

return false;
}

Expand Down Expand Up @@ -500,6 +507,7 @@ void CBuildingRemovalSA::ClearRemovedBuildingLists(uint* pOutAmount)
else
iter++;
}

// Init some variables
std::multimap<uint16_t, sDataBuildingRemovalItem*>::const_iterator iterator = m_pDataBuildings->begin();
// Loop through the data building list
Expand All @@ -512,6 +520,7 @@ void CBuildingRemovalSA::ClearRemovedBuildingLists(uint* pOutAmount)
pFound->m_iCount = 0;
}
}

// Init some variables
std::multimap<uint16_t, sBuildingRemovalItem*>::const_iterator iteratorBinary = m_pBinaryBuildings->begin();
// Loop through the data building list
Expand All @@ -524,10 +533,13 @@ void CBuildingRemovalSA::ClearRemovedBuildingLists(uint* pOutAmount)
pFoundBinary->m_iCount = 0;
}
}

// Delete old building lists
delete m_pBuildingRemovals;

// Create new
m_pBuildingRemovals = new std::multimap<uint16_t, SBuildingRemoval*>;

m_pRemovedEntities.clear();
m_pAddedEntities.clear();

Expand Down Expand Up @@ -579,10 +591,13 @@ sDataBuildingRemovalItem* CBuildingRemovalSA::AddDataBuilding(CEntitySAInterface

// Create a new building removal
sDataBuildingRemovalItem* pBuildingRemoval = new sDataBuildingRemovalItem(pInterface, true);

// Insert it with the model index so we can fast lookup
m_pDataBuildings->insert(std::pair<uint16_t, sDataBuildingRemovalItem*>((uint16_t)pInterface->m_nModelIndex, pBuildingRemoval));

m_pAddedEntities[(DWORD)pInterface] = true;
m_pRemovedEntities[(DWORD)pInterface] = false;

return pBuildingRemoval;
}

Expand Down Expand Up @@ -618,8 +633,10 @@ void CBuildingRemovalSA::AddBinaryBuilding(CEntitySAInterface* pInterface)
{
// Create a new building removal
sBuildingRemovalItem* pBuildingRemoval = new sBuildingRemovalItem(pInterface, false);

// Insert it with the model index so we can fast lookup
m_pBinaryBuildings->insert(std::pair<uint16_t, sBuildingRemovalItem*>((uint16_t)pInterface->m_nModelIndex, pBuildingRemoval));

m_pAddedEntities[(DWORD)pInterface] = true;
m_pRemovedEntities[(DWORD)pInterface] = false;
}
Expand Down
3 changes: 3 additions & 0 deletions Client/game_sa/CBuildingSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void CBuildingSA::SetLod(CBuilding* pLod)
else
{
CEntitySAInterface* pCurrentLod = m_pInterface->m_pLod;

if (pCurrentLod)
{
pGame->GetWorld()->Remove(pCurrentLod, CBuilding_SetLod);
Expand Down Expand Up @@ -91,6 +92,7 @@ void CBuildingSA::ReallocateMatrix()
newMatrix->m_pNext = nullptr;

m_pInterface->RemoveMatrix();

m_pInterface->matrix = reinterpret_cast<CMatrix_Padded*>(newMatrix);
}

Expand All @@ -106,5 +108,6 @@ void CBuildingSA::RemoveAllocatedMatrix()

g_matrixPool.RemoveItem(reinterpret_cast<CMatrixLinkSAInterface*>(m_pInterface->matrix));
g_matrixPool.SetCapacity(0);

m_pInterface->matrix = nullptr;
}
3 changes: 3 additions & 0 deletions Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ inline bool CBuildingsPoolSA::AddBuildingToPool(CClientBuilding* pClientBuilding
return false;

std::int32_t iElementIndexInPool = (*m_ppBuildingPoolInterface)->GetObjectIndexSafe(pInterface);

if (iElementIndexInPool == -1)
return false;

Expand Down Expand Up @@ -82,6 +83,7 @@ CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint1

// 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);

Expand Down Expand Up @@ -140,6 +142,7 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding)
CBuildingSAInterface* pInterface = pBuilding->GetBuildingInterface();

std::int32_t iElementIndexInPool = (*m_ppBuildingPoolInterface)->GetObjectIndexSafe(pInterface);

if (iElementIndexInPool == -1)
return;

Expand Down
8 changes: 8 additions & 0 deletions Client/game_sa/CFileLoaderSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,19 @@ bool CFileLoader_LoadAtomicFile(RwStream* stream, unsigned int modelId)
auto pAtomicModelInfo = reinterpret_cast<CAtomicModelInfo*>(pBaseModelInfo);

bool bUseCommonVehicleTexDictionary = false;

if (pAtomicModelInfo && pBaseModelInfo->bWetRoadReflection)
{
bUseCommonVehicleTexDictionary = true;
CVehicleModelInfo_UseCommonVehicleTexDicationary();
}

const unsigned int rwID_CLUMP = 16;

if (RwStreamFindChunk(stream, rwID_CLUMP, nullptr, nullptr))
{
RpClump* pReadClump = RpClumpStreamRead(stream);

if (!pReadClump)
{
if (bUseCommonVehicleTexDictionary)
Expand All @@ -169,6 +172,7 @@ bool CFileLoader_LoadAtomicFile(RwStream* stream, unsigned int modelId)
}

gAtomicModelId = modelId;

SRelatedModelInfo relatedModelInfo = {0};
relatedModelInfo.pClump = pReadClump;
relatedModelInfo.bDeleteOldRwObject = false;
Expand All @@ -186,6 +190,7 @@ bool CFileLoader_LoadAtomicFile(RwStream* stream, unsigned int modelId)
{
CVehicleModelInfo_StopUsingCommonVehicleTexDicationary();
}

return true;
}

Expand Down Expand Up @@ -213,6 +218,7 @@ RpAtomic* CFileLoader_SetRelatedModelInfoCB(RpAtomic* atomic, SRelatedModelInfo*
CVisibilityPlugins_SetAtomicRenderCallback(atomic, 0);

RpAtomic* pOldAtomic = reinterpret_cast<RpAtomic*>(pBaseModelInfo->pRwObject);

if (bDamage)
{
auto pDamagableModelInfo = reinterpret_cast<CDamagableModelInfo*>(pAtomicModelInfo);
Expand All @@ -224,6 +230,7 @@ RpAtomic* CFileLoader_SetRelatedModelInfoCB(RpAtomic* atomic, SRelatedModelInfo*
}

RpClumpRemoveAtomic(pRelatedModelInfo->pClump, atomic);

RwFrame* newFrame = RwFrameCreate();
RpAtomicSetFrame(atomic, newFrame);
CVisibilityPlugins_SetAtomicId(atomic, gAtomicModelId);
Expand Down Expand Up @@ -265,6 +272,7 @@ CEntitySAInterface* CFileLoader_LoadObjectInstance(const char* szLine)
but custom exporters might not contain the normalization. And we must do it instead.
*/
const float fLenSq = inst.rotation.LengthSquared();

if (fLenSq > 0.0f && std::fabs(fLenSq - 1.0f) > std::numeric_limits<float>::epsilon())
{
const float fLength = std::sqrt(fLenSq);
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/TaskAttackSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,5 @@ class CTaskSimpleStealthKillSAInterface : public CTaskSimpleSAInterface
CAnimBlendAssociation* m_anim;
unsigned int m_spentWaitingMs;
};

static_assert(sizeof(CTaskSimpleStealthKillSAInterface) == 0x20, "Invalid CTaskSimpleStealthKillSAInterface size");
5 changes: 5 additions & 0 deletions Client/mods/deathmatch/logic/CBassAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ bool CBassAudio::BeginLoadingMedia()
if (it == ms_FailedAudioFiles.end() || (dwCurrentTime - it->second) >= FAILED_LOAD_RETRY_DELAY)
{
bShouldTry = true;

// Mark as failed/in-progress immediately
// and to ensure failure is cached if ConvertFileToMono fails
ms_FailedAudioFiles[m_strPath] = dwCurrentTime;
Expand Down Expand Up @@ -331,12 +332,15 @@ bool CBassAudio::BeginLoadingMedia()
g_pCore->GetConsole()->Printf("BASS ERROR %d in BASS_FX_BPM_BeatCallbackSet path:%s 3d:%d loop:%d", BASS_ErrorGetCode(), *m_strPath, m_b3D,
m_bLoop);
}

m_pSound = BASS_FX_TempoCreate(m_pSound, lFlags | BASS_FX_FREESOURCE);

if (!m_pSound)
{
g_pCore->GetConsole()->Printf("BASS ERROR %d in CreateTempo path:%s 3d:%d loop:%d", BASS_ErrorGetCode(), *m_strPath, m_b3D, m_bLoop);
return false;
}

BASS_ChannelGetAttribute(m_pSound, BASS_ATTRIB_TEMPO, &m_fTempo);
BASS_ChannelGetAttribute(m_pSound, BASS_ATTRIB_TEMPO_PITCH, &m_fPitch);
BASS_ChannelGetAttribute(m_pSound, BASS_ATTRIB_TEMPO_FREQ, &m_fSampleRate);
Expand Down Expand Up @@ -1077,6 +1081,7 @@ float* CBassAudio::GetWaveData(int iLength)
}
return NULL;
}

DWORD CBassAudio::GetLevelData()
{
if (m_pSound)
Expand Down
10 changes: 10 additions & 0 deletions Client/mods/deathmatch/logic/CClientBuilding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ void CClientBuilding::Unlink()
{
m_pHighBuilding->SetLowLodBuilding();
}

if (m_pLowBuilding)
{
SetLowLodBuilding();
}

Destroy();
}

Expand All @@ -57,6 +59,7 @@ void CClientBuilding::SetPosition(const CVector& vecPosition)

if (m_vPos == vecPosition)
return;

m_vPos = vecPosition;
Recreate();
UpdateSpatialData();
Expand All @@ -66,6 +69,7 @@ void CClientBuilding::SetRotationRadians(const CVector& vecRadians)
{
if (m_vRot == vecRadians)
return;

m_vRot = vecRadians;
Recreate();
}
Expand Down Expand Up @@ -94,6 +98,7 @@ void CClientBuilding::SetInterior(uint8_t ucInterior)
{
if (m_interior == ucInterior)
return;

m_interior = ucInterior;
Recreate();
}
Expand Down Expand Up @@ -172,8 +177,10 @@ void CClientBuilding::Create()
{
m_pBuilding->SetUsesCollision(m_usesCollision);
}

if (m_ucAlpha != 255)
m_pBuilding->SetAlpha(m_ucAlpha);

if (m_pHighBuilding)
{
m_pHighBuilding->GetBuildingEntity()->SetLod(m_pBuilding);
Expand All @@ -189,6 +196,7 @@ void CClientBuilding::Destroy()
{
m_pHighBuilding->GetBuildingEntity()->SetLod(nullptr);
}

g_pGame->GetPools()->GetBuildingsPool().RemoveBuilding(m_pBuilding);
m_pBuilding = nullptr;
}
Expand All @@ -202,6 +210,7 @@ bool CClientBuilding::SetLowLodBuilding(CClientBuilding* pLod)

// Unlink old high lod element
CClientBuilding* pOveridedBuilding = pLod->GetHighLodBuilding();

if (pOveridedBuilding && pOveridedBuilding != this)
{
pOveridedBuilding->SetLowLodBuilding();
Expand All @@ -220,6 +229,7 @@ bool CClientBuilding::SetLowLodBuilding(CClientBuilding* pLod)
{
m_pLowBuilding->SetHighLodBuilding();
}

m_pBuilding->SetLod(nullptr);
m_pLowBuilding = nullptr;
}
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientBuildingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ bool CClientBuildingManager::IsValidModel(uint16_t modelId)
return false;

CModelInfo* pModelInfo = g_pGame->GetModelInfo(modelId);

if (!pModelInfo || !pModelInfo->GetInterface())
return false;

if (!pModelInfo->IsAllocatedInArchive())
return false;

eModelInfoType eType = pModelInfo->GetModelType();

return (eType == eModelInfoType::CLUMP || eType == eModelInfoType::ATOMIC || eType == eModelInfoType::WEAPON || eType == eModelInfoType::TIME);
}

Expand Down
4 changes: 4 additions & 0 deletions Client/mods/deathmatch/logic/CClientModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ bool CClientModel::Allocate(ushort usParentID)
{
bool isValidModel = g_pClientGame->GetObjectManager()->IsValidModel(usParentID);
bool isDamagable = pParentModelInfo->IsDamageableAtomic();

if (isValidModel && isDamagable)
{
pModelInfo->MakeObjectDamageableModel(usParentID);
Expand Down Expand Up @@ -204,6 +205,7 @@ void CClientModel::RestoreDFF(CModelInfo* pModelInfo)
// Restore buildings
CClientBuildingManager* pBuildingsManager = g_pClientGame->GetManager()->GetBuildingManager();
auto& buildingsList = pBuildingsManager->GetBuildings();

unloadModelsAndCallEventsNonStreamed(buildingsList.begin(), buildingsList.end(), usParentID, [=](auto& element) { element.SetModel(usParentID); });

// Restore COL
Expand All @@ -228,11 +230,13 @@ void CClientModel::RestoreDFF(CModelInfo* pModelInfo)
bool CClientModel::AllocateTXD(std::string& strTxdName)
{
std::uint32_t uiSlotID = g_pGame->GetPools()->GetTxdPool().AllocateTextureDictonarySlot(m_iModelID - MAX_MODEL_DFF_ID, strTxdName);

if (uiSlotID != -1)
{
m_bAllocatedByUs = true;
return true;
}

return false;
}

Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5485,8 +5485,10 @@ void CClientPed::SetTargetPosition(const CVector& vecPosition, unsigned long ulD
{
if (m_interp.pTargetOriginSource)
m_interp.pTargetOriginSource->RemoveOriginSourceUser(this);

if (pTargetOriginSource)
pTargetOriginSource->AddOriginSourceUser(this);

m_interp.pTargetOriginSource = pTargetOriginSource;
}

Expand Down
Loading
Loading