Factorized a duplicate part of CPed::RenderWeapon into a lambda function

This commit is contained in:
Silent 2019-05-18 11:46:49 +02:00
parent 60c4eb3b66
commit 515afe5daf
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1

View File

@ -51,15 +51,10 @@ void CPed::RenderWeapon(bool bWeapon, bool bMuzzleFlash, bool bForShadow)
RwFrame* pFrame = RpClumpGetFrame(reinterpret_cast<RpClump*>(m_pWeaponObject));
*RwFrameGetMatrix(pFrame) = RpHAnimHierarchyGetMatrixArray(pAnimHierarchy)[RpHAnimIDGetIndex(pAnimHierarchy, bHasParachute ? 3 : 24)];
if ( bHasParachute )
auto renderOneWeapon = [this](bool bWeapon, bool bMuzzleFlash, bool bForShadow, bool bRightGun)
{
const RwV3d vecParachuteTranslation = { 0.1f, -0.15f, 0.0f };
const RwV3d vecParachuteRotation = { 0.0f, 1.0f, 0.0f };
RwMatrixTranslate(RwFrameGetMatrix(pFrame), &vecParachuteTranslation, rwCOMBINEPRECONCAT);
RwMatrixRotate(RwFrameGetMatrix(pFrame), &vecParachuteRotation, 90.0f, rwCOMBINEPRECONCAT);
}
RwFrameUpdateObjects(RpClumpGetFrame(reinterpret_cast<RpClump*>(m_pWeaponObject)));
RwFrameUpdateObjects(pFrame);
if ( bForShadow )
RpClumpForAllAtomics(reinterpret_cast<RpClump*>(m_pWeaponObject), ShadowCameraRenderCB);
else
@ -74,11 +69,22 @@ void CPed::RenderWeapon(bool bWeapon, bool bMuzzleFlash, bool bForShadow)
RwScopedRenderState zWrite(rwRENDERSTATEZWRITEENABLE);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
SetGunFlashAlpha(false);
SetGunFlashAlpha(bRightGun);
RpAtomic* atomic = reinterpret_cast<RpAtomic*>(GetFirstObject(m_pMuzzleFlashFrame));
RpAtomicRender( atomic );
}
}
};
if ( bHasParachute )
{
const RwV3d vecParachuteTranslation = { 0.1f, -0.15f, 0.0f };
const RwV3d vecParachuteRotation = { 0.0f, 1.0f, 0.0f };
RwMatrixTranslate(RwFrameGetMatrix(pFrame), &vecParachuteTranslation, rwCOMBINEPRECONCAT);
RwMatrixRotate(RwFrameGetMatrix(pFrame), &vecParachuteRotation, 90.0f, rwCOMBINEPRECONCAT);
}
renderOneWeapon(bWeapon, bMuzzleFlash, bForShadow, false);
// Dual weapons
if ( CWeaponInfo::GetWeaponInfo(weaponSlots[m_bActiveWeapon].m_eWeaponType, GetWeaponSkillForRenderWeaponPedsForPC())->hexFlags >> 11 & 1 )
@ -90,26 +96,7 @@ void CPed::RenderWeapon(bool bWeapon, bool bMuzzleFlash, bool bForShadow)
RwMatrixRotate(RwFrameGetMatrix(pFrame), &vecParachuteRotation, 180.0f, rwCOMBINEPRECONCAT);
RwMatrixTranslate(RwFrameGetMatrix(pFrame), &vecParachuteTranslation, rwCOMBINEPRECONCAT);
RwFrameUpdateObjects(pFrame);
if ( bForShadow )
RpClumpForAllAtomics(reinterpret_cast<RpClump*>(m_pWeaponObject), ShadowCameraRenderCB);
else
{
if ( bWeapon )
{
RpClumpRender(reinterpret_cast<RpClump*>(m_pWeaponObject));
}
if ( bMuzzleFlash && m_pMuzzleFlashFrame != nullptr )
{
RwScopedRenderState zWrite(rwRENDERSTATEZWRITEENABLE);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
SetGunFlashAlpha(true);
RpAtomic* atomic = reinterpret_cast<RpAtomic*>(GetFirstObject(m_pMuzzleFlashFrame));
RpAtomicRender( atomic );
}
}
renderOneWeapon(bWeapon, bMuzzleFlash, bForShadow, true);
}
if ( bMuzzleFlash )
ResetGunFlashAlpha();