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