Skip to content

Commit 2fe13e8

Browse files
committed
Improve ValveSoftware#1146 implementation
1 parent 6374d0b commit 2fe13e8

File tree

1 file changed

+72
-63
lines changed

1 file changed

+72
-63
lines changed

src/game/shared/particle_property.cpp

Lines changed: 72 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#include "particles_new.h"
1717
#include "engine/ivdebugoverlay.h"
1818
#include "bone_setup.h"
19+
20+
#ifdef TF_CLIENT_DLL
21+
#include "tf_item_wearable.h"
22+
#endif
1923
#else
2024

2125
#include "baseentity.h"
@@ -558,90 +562,95 @@ void CParticleProperty::UpdateControlPoint( ParticleEffectList_t *pEffect, int i
558562
#ifdef TF_CLIENT_DLL
559563

560564
CBaseEntity* pWearable = (CBaseEntity*)pPoint->hEntity.Get();
561-
if (pWearable && GetAttribInterface(pWearable) && !pWearable->IsPlayer() && V_strcmp(pWearable->GetClassname(), "tf_wearable") == 0)
565+
if (pWearable && GetAttribInterface(pWearable) && !pWearable->IsPlayer())
562566
{
563-
C_BaseAnimating* pAnimating = pPoint->hEntity->GetBaseAnimating();
564-
if (pAnimating)
567+
CTFWearable* pTFWearable = dynamic_cast<CTFWearable*>(pWearable);
568+
569+
if (pTFWearable)
565570
{
566-
// Do not use this now. It asks players to use particle from head attachment.
567-
// But unusual particles for wearables are made for head attachment already.
568-
// CALL_ATTRIB_HOOK_INT_ON_OTHER( pAnimating, bUseHeadOrigin, particle_effect_use_head_origin );
569-
570-
// Reference from bone_merge_cache
571-
CUtlVector<CUtlString> BoneNames;
572-
CUtlVector<unsigned short> ParentBones;
573-
574-
int nFollowBoneSetupMask = 0;
575-
CStudioHdr* pWearableHdr = pAnimating->GetModelPtr();
576-
C_BaseAnimating* pFollow = pAnimating->FindFollowedEntity();
577-
CStudioHdr* pFollowHdr = (pFollow ? pFollow->GetModelPtr() : NULL);
578-
579-
bool bIsUnusual = false;
580-
bool bIsUnusualStatic = false;
581-
CALL_ATTRIB_HOOK_INT_ON_OTHER(pAnimating, bIsUnusual, set_attached_particle);
582-
CALL_ATTRIB_HOOK_INT_ON_OTHER(pAnimating, bIsUnusualStatic, set_attached_particle_static);
583-
if (pWearableHdr && pFollowHdr && (bIsUnusual || bIsUnusualStatic))
571+
C_BaseAnimating* pAnimating = pTFWearable->GetBaseAnimating();
572+
if (pAnimating)
584573
{
585-
CUtlVector<unsigned char> BoneMergeBits; // One bit for each bone. The bit is set if the bone gets merged.
586-
BoneMergeBits.SetSize(pWearableHdr->numbones() / 8 + 1);
587-
memset(BoneMergeBits.Base(), 0, BoneMergeBits.Count());
574+
// Do not use this now. It asks players to use particle from head attachment.
575+
// But unusual particles for wearables are made for head attachment already.
576+
// CALL_ATTRIB_HOOK_INT_ON_OTHER( pAnimating, bUseHeadOrigin, particle_effect_use_head_origin );
577+
578+
// Reference from bone_merge_cache
579+
CUtlVector<CUtlString> BoneNames;
580+
CUtlVector<unsigned short> ParentBones;
581+
582+
int nFollowBoneSetupMask = 0;
583+
CStudioHdr* pWearableHdr = pAnimating->GetModelPtr();
584+
C_BaseAnimating* pFollow = pAnimating->FindFollowedEntity();
585+
CStudioHdr* pFollowHdr = (pFollow ? pFollow->GetModelPtr() : NULL);
586+
587+
bool bIsUnusual = false;
588+
bool bIsUnusualStatic = false;
589+
CALL_ATTRIB_HOOK_INT_ON_OTHER(pAnimating, bIsUnusual, set_attached_particle);
590+
CALL_ATTRIB_HOOK_INT_ON_OTHER(pAnimating, bIsUnusualStatic, set_attached_particle_static);
591+
if (pWearableHdr && pFollowHdr && (bIsUnusual || bIsUnusualStatic))
592+
{
593+
CUtlVector<unsigned char> BoneMergeBits; // One bit for each bone. The bit is set if the bone gets merged.
594+
BoneMergeBits.SetSize(pWearableHdr->numbones() / 8 + 1);
595+
memset(BoneMergeBits.Base(), 0, BoneMergeBits.Count());
588596

589-
mstudiobone_t* pWearableBones = pWearableHdr->pBone(0);
597+
mstudiobone_t* pWearableBones = pWearableHdr->pBone(0);
590598

591-
nFollowBoneSetupMask = BONE_USED_BY_BONE_MERGE;
592-
for (int i = 0; i < pWearableHdr->numbones(); i++)
593-
{
594-
const CUtlString sBoneName = pWearableBones[i].pszName();
595-
const int parentBoneIndex = Studio_BoneIndexByName(pFollowHdr, sBoneName);
596-
if (parentBoneIndex < 0)
597-
continue;
599+
nFollowBoneSetupMask = BONE_USED_BY_BONE_MERGE;
600+
for (int i = 0; i < pWearableHdr->numbones(); i++)
601+
{
602+
const CUtlString sBoneName = pWearableBones[i].pszName();
603+
const int parentBoneIndex = Studio_BoneIndexByName(pFollowHdr, sBoneName);
604+
if (parentBoneIndex < 0)
605+
continue;
598606

599-
BoneNames.AddToTail(sBoneName);
600-
ParentBones.AddToTail(parentBoneIndex);
607+
BoneNames.AddToTail(sBoneName);
608+
ParentBones.AddToTail(parentBoneIndex);
601609

602-
BoneMergeBits[i >> 3] |= (1 << (i & 7));
610+
BoneMergeBits[i >> 3] |= (1 << (i & 7));
603611

604-
if ((pFollowHdr->boneFlags(parentBoneIndex) & BONE_USED_BY_BONE_MERGE) == 0)
605-
{
606-
nFollowBoneSetupMask = BONE_USED_BY_ANYTHING;
612+
if ((pFollowHdr->boneFlags(parentBoneIndex) & BONE_USED_BY_BONE_MERGE) == 0)
613+
{
614+
nFollowBoneSetupMask = BONE_USED_BY_ANYTHING;
615+
}
607616
}
608-
}
609617

610-
if (!ParentBones.Count())
618+
if (!ParentBones.Count())
619+
{
620+
nFollowBoneSetupMask = 0;
621+
}
622+
}
623+
else
611624
{
612625
nFollowBoneSetupMask = 0;
613626
}
614-
}
615-
else
616-
{
617-
nFollowBoneSetupMask = 0;
618-
}
619627

620-
if (pWearableHdr && BoneNames.Count())
621-
{
622-
pFollow->SetupBones(NULL, -1, nFollowBoneSetupMask, gpGlobals->curtime);
623-
const char* const pPriorityBones[] = { "bip_head", "prp_helmet", "prp_hat" };
624-
int iBone = -1;
625-
bool bFound = false;
626-
for (int j = 0; j < ARRAYSIZE(pPriorityBones) && !bFound; j++)
628+
if (pWearableHdr && BoneNames.Count())
627629
{
628-
for (int i = 0; i < BoneNames.Count(); i++)
630+
pFollow->SetupBones(NULL, -1, nFollowBoneSetupMask, gpGlobals->curtime);
631+
const char* const pPriorityBones[] = { "bip_head", "prp_helmet", "prp_hat" };
632+
int iBone = -1;
633+
bool bFound = false;
634+
for (int j = 0; j < ARRAYSIZE(pPriorityBones) && !bFound; j++)
629635
{
630-
if (BoneNames[i] == pPriorityBones[j])
636+
for (int i = 0; i < BoneNames.Count(); i++)
631637
{
632-
iBone = i;
633-
bFound = true;
634-
break;
638+
if (BoneNames[i] == pPriorityBones[j])
639+
{
640+
iBone = i;
641+
bFound = true;
642+
break;
643+
}
635644
}
636645
}
637-
}
638646

639-
bUsingUnusual = true;
640-
const matrix3x4_t rootBone = iBone >= 0 ? pFollow->GetBone(ParentBones[iBone]) : pFollow->GetBone(ParentBones[0]);
641-
MatrixVectors(rootBone, &vecForward, &vecRight, &vecUp);
642-
MatrixPosition(rootBone, vecOrigin);
647+
bUsingUnusual = true;
648+
const matrix3x4_t rootBone = iBone >= 0 ? pFollow->GetBone(ParentBones[iBone]) : pFollow->GetBone(ParentBones[0]);
649+
MatrixVectors(rootBone, &vecForward, &vecRight, &vecUp);
650+
MatrixPosition(rootBone, vecOrigin);
643651

644-
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER(pAnimating, flOffset, particle_effect_vertical_offset);
652+
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER(pAnimating, flOffset, particle_effect_vertical_offset);
653+
}
645654
}
646655
}
647656
}

0 commit comments

Comments
 (0)