Skip to content

Commit

Permalink
Events: better fix avoid entity events from recently freed/reused ent…
Browse files Browse the repository at this point in the history
…ities. causes issues at large timescales such as during cutscene skipping when the event time is before the entity free time and cent->gent is used. Also remove unnecessary setting of NPC->count on takeoff/landing for boba and rockettrooper.
  • Loading branch information
redsaurus committed Jul 1, 2020
1 parent dcae040 commit ce011d3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
39 changes: 35 additions & 4 deletions code/cgame/cg_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,35 @@ static void CG_UseItem( centity_t *cent )

}

/*
==============
CG_UnsafeEventType
Returns qtrue for event types that access cent->gent directly (and don't require it
to be the player / entity 0).
==============
*/
qboolean CG_UnsafeEventType(int eventType)
{
switch (eventType)
{
case EV_CHANGE_WEAPON:
case EV_DISRUPTOR_SNIPER_SHOT:
case EV_DISRUPTOR_SNIPER_MISS:
case EV_CONC_ALT_MISS:
case EV_DISINTEGRATION:
case EV_GRENADE_BOUNCE:
case EV_MISSILE_HIT:
case EV_MISSILE_MISS:
case EV_PAIN:
case EV_PLAY_EFFECT:
case EV_TARGET_BEAM_DRAW:
return qtrue;
break;
default:
return qfalse;
}
}
/*
==============
CG_EntityEvent
Expand Down Expand Up @@ -297,10 +325,13 @@ void CG_EntityEvent( centity_t *cent, vec3_t position ) {
return;
}

if ( cg_skippingcin.integer )
{
return;
}
//When skipping a cutscene the timescale is drastically increased, causing entities to be freed
//and possibly reused between the snapshot currentState and the actual state of the gent when accessed.
//We try to avoid this issue by ignoring events on entities that have been freed since the snapshot.
if (cent->gent->freetime > cg.snap->serverTime && CG_UnsafeEventType(event))
{
return;
}

//ci = &cent->gent->client->clientInfo;
clientNum = cent->gent->s.number;
Expand Down
5 changes: 0 additions & 5 deletions code/game/AI_BobaFett.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,6 @@ void Boba_FlyStart( gentity_t *self )
G_SoundOnEnt( self, CHAN_ITEM, "sound/chars/boba/bf_blast-off.wav" );
//jet loop sound
self->s.loopSound = G_SoundIndex( "sound/chars/boba/bf_jetpack_lp.wav" );
if ( self->NPC )
{
self->count = Q3_INFINITE; // SEEKER shot ammo count
}
}
}

Expand Down Expand Up @@ -461,7 +457,6 @@ void Boba_FlyStop( gentity_t *self )
self->s.loopSound = 0;
if ( self->NPC )
{
self->count = 0; // SEEKER shot ammo count
TIMER_Set( self, "jetRecharge", Q_irand( 1000, 5000 ) );
TIMER_Set( self, "jumpChaseDebounce", Q_irand( 500, 2000 ) );
}
Expand Down
5 changes: 0 additions & 5 deletions code/game/AI_RocketTrooper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,6 @@ void RT_FlyStart( gentity_t *self )
G_SoundOnEnt( self, CHAN_ITEM, "sound/chars/boba/bf_blast-off.wav" );
//jet loop sound
self->s.loopSound = G_SoundIndex( "sound/chars/boba/bf_jetpack_lp.wav" );
if ( self->NPC )
{
self->count = Q3_INFINITE; // SEEKER shot ammo count
}
}
}

Expand All @@ -417,7 +413,6 @@ void RT_FlyStop( gentity_t *self )

if ( self->NPC )
{
self->count = 0; // SEEKER shot ammo count
TIMER_Set( self, "jetRecharge", Q_irand( 1000, 5000 ) );
TIMER_Set( self, "jumpChaseDebounce", Q_irand( 500, 2000 ) );
}
Expand Down

0 comments on commit ce011d3

Please sign in to comment.