- optimize P_ShouldPassThroughPlayer checks - move down in the check list, move thing->player check out of the function

This commit is contained in:
Rachael Alexanderson 2023-01-09 11:53:24 -05:00
parent 9777cfd500
commit 5aba0c144c

View file

@ -119,22 +119,11 @@ TArray<spechit_t> portalhit;
// //
//========================================================================== //==========================================================================
static inline bool P_ShouldPassThroughPlayer(AActor *self, AActor *other) bool P_ShouldPassThroughPlayer(AActor *self, AActor *other)
{ {
if (!(dmflags3 & DF3_NO_PLAYER_CLIP)) return (dmgflags3 & DF3_NO_PLAYER_CLIP) &&
return false; other->player && other->player->mo == other &&
self->IsFriend(other);
if (!self->player || !other->player)
return false;
// voodoo doll?
if (other->player->mo != other)
return false;
if (!self->IsFriend(other))
return false;
return true;
} }
//========================================================================== //==========================================================================
@ -517,9 +506,6 @@ bool P_TeleportMove(AActor* thing, const DVector3 &pos, bool telefrag, bool modi
if (tmf.thing->flags6 & MF6_THRUSPECIES && tmf.thing->GetSpecies() == th->GetSpecies()) if (tmf.thing->flags6 & MF6_THRUSPECIES && tmf.thing->GetSpecies() == th->GetSpecies())
continue; continue;
if (P_ShouldPassThroughPlayer(tmf.thing, th))
continue;
// [RH] Z-Check // [RH] Z-Check
// But not if not MF2_PASSMOBJ or MF3_DONTOVERLAP are set! // But not if not MF2_PASSMOBJ or MF3_DONTOVERLAP are set!
// Otherwise those things would get stuck inside each other. // Otherwise those things would get stuck inside each other.
@ -540,6 +526,9 @@ bool P_TeleportMove(AActor* thing, const DVector3 &pos, bool telefrag, bool modi
if ((thing->IsKindOf(NAME_Inventory) || (thing->flags2 & MF2_TELESTOMP)) && !(thing->flags & MF_SOLID) && ((th->flags3 & MF3_ISMONSTER) || th->player != nullptr)) if ((thing->IsKindOf(NAME_Inventory) || (thing->flags2 & MF2_TELESTOMP)) && !(thing->flags & MF_SOLID) && ((th->flags3 & MF3_ISMONSTER) || th->player != nullptr))
continue; continue;
if (thing->player && P_ShouldPassThroughPlayer(tmf.thing, th))
continue;
// monsters don't stomp things except on boss level // monsters don't stomp things except on boss level
// [RH] Some Heretic/Hexen monsters can telestomp // [RH] Some Heretic/Hexen monsters can telestomp
// ... and some items can never be telefragged while others will be telefragged by everything that teleports upon them. // ... and some items can never be telefragged while others will be telefragged by everything that teleports upon them.
@ -550,6 +539,7 @@ bool P_TeleportMove(AActor* thing, const DVector3 &pos, bool telefrag, bool modi
P_DamageMobj(th, thing, thing, TELEFRAG_DAMAGE, NAME_Telefrag, DMG_THRUSTLESS); P_DamageMobj(th, thing, thing, TELEFRAG_DAMAGE, NAME_Telefrag, DMG_THRUSTLESS);
continue; continue;
} }
return false; return false;
} }
@ -1399,7 +1389,7 @@ bool PIT_CheckThing(FMultiBlockThingsIterator &it, FMultiBlockThingsIterator::Ch
if ((tm.thing->flags6 & MF6_THRUSPECIES) && (tm.thing->GetSpecies() == thing->GetSpecies())) if ((tm.thing->flags6 & MF6_THRUSPECIES) && (tm.thing->GetSpecies() == thing->GetSpecies()))
return true; return true;
if (P_ShouldPassThroughPlayer(tm.thing, thing)) if (thing->player && P_ShouldPassThroughPlayer(tm.thing, thing))
return true; return true;
tm.thing->BlockingMobj = thing; tm.thing->BlockingMobj = thing;
@ -1583,15 +1573,15 @@ bool PIT_CheckThing(FMultiBlockThingsIterator &it, FMultiBlockThingsIterator::Ch
&& (tm.thing->target->GetSpecies() == thing->GetSpecies())) && (tm.thing->target->GetSpecies() == thing->GetSpecies()))
return true; return true;
if (P_ShouldPassThroughPlayer(tm.thing->target, thing) && (!(tm.thing->flags8 & MF8_HITOWNER) || tm.thing->target->player != thing->player))
return true;
// Check for rippers passing through corpses // Check for rippers passing through corpses
if ((thing->flags & MF_CORPSE) && (tm.thing->flags2 & MF2_RIP) && !(thing->flags & MF_SHOOTABLE)) if ((thing->flags & MF_CORPSE) && (tm.thing->flags2 & MF2_RIP) && !(thing->flags & MF_SHOOTABLE))
{ {
return true; return true;
} }
if (thing->player && P_ShouldPassThroughPlayer(tm.thing->target, thing) && (!(tm.thing->flags8 & MF8_HITOWNER) || tm.thing->target->player != thing->player))
return true;
double clipheight; double clipheight;
if (thing->projectilepassheight > 0) if (thing->projectilepassheight > 0)
@ -2097,10 +2087,6 @@ int P_TestMobjZ(AActor *actor, bool quick, AActor **pOnmobj)
{ {
continue; continue;
} }
if (P_ShouldPassThroughPlayer(actor, thing))
{
continue;
}
if (!(thing->flags & MF_SOLID)) if (!(thing->flags & MF_SOLID))
{ // Can't hit thing { // Can't hit thing
continue; continue;
@ -2142,7 +2128,10 @@ int P_TestMobjZ(AActor *actor, bool quick, AActor **pOnmobj)
{ // If they cannot collide, they cannot block each other. { // If they cannot collide, they cannot block each other.
continue; continue;
} }
if (thing->player && P_ShouldPassThroughPlayer(actor, thing))
{
continue;
}
onmobj = thing; onmobj = thing;
if (quick) break; if (quick) break;
@ -4206,12 +4195,12 @@ struct aim_t
if (th == shootthing) if (th == shootthing)
continue; // can't shoot self continue; // can't shoot self
if (P_ShouldPassThroughPlayer(shootthing, th))
continue;
if (aimtarget != NULL && th != aimtarget) if (aimtarget != NULL && th != aimtarget)
continue; // only care about target, and you're not it continue; // only care about target, and you're not it
if (thing->player && P_ShouldPassThroughPlayer(shootthing, th))
continue;
// If we want to start a conversation anything that has one should be // If we want to start a conversation anything that has one should be
// found, regardless of other settings. // found, regardless of other settings.
if (!(flags & ALF_CHECKCONVERSATION) || th->Conversation == NULL) if (!(flags & ALF_CHECKCONVERSATION) || th->Conversation == NULL)
@ -4504,7 +4493,7 @@ static ETraceStatus CheckForActor(FTraceResults &res, void *userdata)
(data->MThruSpecies && res.Actor->GetSpecies() == data->Caller->GetSpecies()) || (data->MThruSpecies && res.Actor->GetSpecies() == data->Caller->GetSpecies()) ||
(data->ThruSpecies && res.Actor->GetSpecies() == data->PuffSpecies) || (data->ThruSpecies && res.Actor->GetSpecies() == data->PuffSpecies) ||
(data->hitGhosts && res.Actor->flags3 & MF3_GHOST) || (data->hitGhosts && res.Actor->flags3 & MF3_GHOST) ||
P_ShouldPassThroughPlayer(data->Caller, res.Actor)) (thing->player && P_ShouldPassThroughPlayer(data->Caller, res.Actor)))
{ {
return TRACE_Skip; return TRACE_Skip;
} }
@ -5245,7 +5234,7 @@ static ETraceStatus ProcessRailHit(FTraceResults &res, void *userdata)
(data->MThruSpecies && res.Actor->GetSpecies() == data->Caller->GetSpecies()) || (data->MThruSpecies && res.Actor->GetSpecies() == data->Caller->GetSpecies()) ||
(data->ThruSpecies && res.Actor->GetSpecies() == data->PuffSpecies) || (data->ThruSpecies && res.Actor->GetSpecies() == data->PuffSpecies) ||
(data->ThruGhosts && res.Actor->flags3 & MF3_GHOST) || (data->ThruGhosts && res.Actor->flags3 & MF3_GHOST) ||
P_ShouldPassThroughPlayer(data->Caller, res.Actor)) (thing->player && P_ShouldPassThroughPlayer(data->Caller, res.Actor)))
{ {
return TRACE_Skip; return TRACE_Skip;
} }
@ -6060,14 +6049,14 @@ int P_RadiusAttack(AActor *bombspot, AActor *bombsource, int bombdamage, int bom
continue; continue;
// allow rocket splash damage // allow rocket splash damage
if (P_ShouldPassThroughPlayer(bombsource, thing) && thing != bombsource)
continue;
if (!(flags & RADF_HURTSOURCE) && (thing == bombsource || thing == bombspot)) if (!(flags & RADF_HURTSOURCE) && (thing == bombsource || thing == bombspot))
{ // don't damage the source of the explosion { // don't damage the source of the explosion
continue; continue;
} }
if (thing->player && P_ShouldPassThroughPlayer(bombsource, thing) && thing != bombsource)
continue;
// MBF21 // MBF21
auto targetgroup = thing->GetClass()->ActorInfo()->splash_group; auto targetgroup = thing->GetClass()->ActorInfo()->splash_group;
auto sourcegroup = bombspot->GetClass()->ActorInfo()->splash_group; auto sourcegroup = bombspot->GetClass()->ActorInfo()->splash_group;
@ -6476,7 +6465,7 @@ int P_PushUp(AActor *thing, FChangePosition *cpos)
if (!P_CanCollideWith(thing, intersect)) if (!P_CanCollideWith(thing, intersect))
continue; continue;
if (P_ShouldPassThroughPlayer(thing, intersect)) if (thing->player && P_ShouldPassThroughPlayer(thing, intersect))
continue; continue;
if (!(intersect->flags2 & MF2_PASSMOBJ) || if (!(intersect->flags2 & MF2_PASSMOBJ) ||
@ -6543,7 +6532,7 @@ int P_PushDown(AActor *thing, FChangePosition *cpos)
if (!P_CanCollideWith(thing, intersect)) if (!P_CanCollideWith(thing, intersect))
continue; continue;
if (P_ShouldPassThroughPlayer(thing, intersect)) if (thing->player && P_ShouldPassThroughPlayer(thing, intersect))
continue; continue;
if (!(intersect->flags2 & MF2_PASSMOBJ) || if (!(intersect->flags2 & MF2_PASSMOBJ) ||