Skip to content

Commit

Permalink
server: fixed inconsistent material tracing for studiomodels
Browse files Browse the repository at this point in the history
  • Loading branch information
SNMetamorph committed Sep 6, 2023
1 parent 5f16df8 commit 3398c17
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 40 deletions.
2 changes: 2 additions & 0 deletions server/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,9 @@ void CBaseEntity::FireBullets(ULONG cShots, Vector vecSrc, Vector vecDirShooting
Vector vecEnd;

vecEnd = vecSrc + vecDir * flDistance;
SetBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);
UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, ENT(pev)/*pentIgnore*/, &tr);
ClearBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);

tracer = 0;
if (iTracerFreq != 0 && (tracerCount++ % iTracerFreq) == 0)
Expand Down
17 changes: 5 additions & 12 deletions server/monsters/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2618,7 +2618,9 @@ void CBaseMonster :: StepSound( void )
int fWalking;
int cnt = 0;

SetBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);
UTIL_TraceLine(pev->origin + Vector(0, 0, 8), pev->origin - Vector(0, 0, 16), ignore_monsters, ENT(pev), &ptr);
ClearBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);
CBaseEntity *pEntity = CBaseEntity::Instance(ptr.pHit);
memset(rgsz, 0, sizeof(rgsz));

Expand All @@ -2631,18 +2633,9 @@ void CBaseMonster :: StepSound( void )
}
else if (pEntity->pev->solid == SOLID_CUSTOM)
{
// repeat tracing with material trace flag
TraceResult tr;
SetBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);
UTIL_TraceLine(
ptr.vecEndPos + (ptr.vecPlaneNormal * 0.5f),
ptr.vecEndPos + (ptr.vecPlaneNormal * -0.5f),
ignore_monsters, NULL, &tr
);
ClearBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);
if (tr.materialHash)
{
matdesc_t *mat = COM_FindMaterial(tr.materialHash);
if (ptr.materialHash)
{
matdesc_t *mat = COM_FindMaterial(ptr.materialHash);
pMaterial = mat ? mat->effects : nullptr;
}
}
Expand Down
17 changes: 3 additions & 14 deletions server/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1788,20 +1788,9 @@ float TEXTURETYPE_PlaySound(TraceResult *ptr, Vector vecSrc, Vector vecEnd, int
}
else if (pEntity->pev->solid == SOLID_CUSTOM)
{
// repeat tracing with material trace flag
TraceResult tr;
SetBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);
UTIL_TraceLine(
ptr->vecEndPos + ptr->vecPlaneNormal * 0.15f,
ptr->vecEndPos + ptr->vecPlaneNormal * -0.15f,
ignore_monsters, NULL, &tr
);
ClearBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);

if (tr.materialHash) {
matdesc_t *mat = COM_FindMaterial(tr.materialHash);
if (mat)
{
if (ptr->materialHash) {
matdesc_t *mat = COM_FindMaterial(ptr->materialHash);
if (mat) {
pMat = mat->effects;
impactType = IMPACT_MATERIAL;
}
Expand Down
16 changes: 2 additions & 14 deletions server/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ void DecalGunshot( TraceResult *pTrace, int iBulletType, const vec3_t &origin, c

if (UTIL_GetModelType(pTarget->pev->modelindex) == mod_brush)
{
SetBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);
msurface_t *surf = TRACE_SURFACE(pTrace->pHit, origin, vecEnd);
ClearBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);
pMaterial = COM_MatDefFromSurface(surf, pTrace->vecEndPos);
if (pMaterial) {
UTIL_TraceCustomDecal(pTrace, pMaterial->impact_decal, RANDOM_FLOAT(0.0f, 360.0f));
Expand Down Expand Up @@ -203,19 +201,9 @@ void DecalGunshot( TraceResult *pTrace, int iBulletType, const vec3_t &origin, c
}
else if (studiomodelEntity)
{
// repeat tracing with material trace flag
TraceResult tr;
SetBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);
UTIL_TraceLine(
pTrace->vecEndPos + (pTrace->vecPlaneNormal * 0.15f),
pTrace->vecEndPos + (pTrace->vecPlaneNormal * -0.15f),
ignore_monsters, INDEXENT(0), &tr
);
ClearBits(gpGlobals->trace_flags, FTRACE_MATERIAL_TRACE);

if (tr.materialHash)
if (pTrace->materialHash)
{
matdesc_t *mat = COM_FindMaterial(tr.materialHash);
matdesc_t *mat = COM_FindMaterial(pTrace->materialHash);
pMaterial = mat ? mat->effects : nullptr;
if (pMaterial) {
UTIL_StudioDecalTrace(pTrace, pMaterial->impact_decal);
Expand Down

0 comments on commit 3398c17

Please sign in to comment.