Skip to content

Commit

Permalink
Deduplicate sending breakmodel message in func_breakable and func_bre…
Browse files Browse the repository at this point in the history
…akable_effect
  • Loading branch information
FreeSlave committed Aug 6, 2023
1 parent acdf3fb commit c6b14f2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 66 deletions.
108 changes: 42 additions & 66 deletions dlls/func_break.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,43 @@ static char PlayBreakableBustSound( entvars_t* pev, Materials material, float fv
return 0;
}

void CBreakable::BreakModel(const Vector& vecSpot, const Vector& size, const Vector& vecVelocity, int shardModelIndex, int iGibs, char cFlag)
{
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot );
WRITE_BYTE( TE_BREAKMODEL );

// position
WRITE_COORD( vecSpot.x );
WRITE_COORD( vecSpot.y );
WRITE_COORD( vecSpot.z );

// size
WRITE_COORD( size.x );
WRITE_COORD( size.y );
WRITE_COORD( size.z );

// velocity
WRITE_COORD( vecVelocity.x );
WRITE_COORD( vecVelocity.y );
WRITE_COORD( vecVelocity.z );

// randomization
WRITE_BYTE( 10 );

// Model
WRITE_SHORT( shardModelIndex ); //model id#

// # of shards
WRITE_BYTE( iGibs ); // if 0, let client decide

// duration
WRITE_BYTE( 25 );// 2.5 seconds

// flags
WRITE_BYTE( cFlag );
MESSAGE_END();
}

void CBreakable::Die()
{
DieToActivator(NULL);
Expand Down Expand Up @@ -775,39 +812,7 @@ void CBreakable::DieToActivator( CBaseEntity* pActivator )

if (m_iGibs >= 0)
{
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot );
WRITE_BYTE( TE_BREAKMODEL );

// position
WRITE_COORD( vecSpot.x );
WRITE_COORD( vecSpot.y );
WRITE_COORD( vecSpot.z );

// size
WRITE_COORD( pev->size.x );
WRITE_COORD( pev->size.y );
WRITE_COORD( pev->size.z );

// velocity
WRITE_COORD( vecVelocity.x );
WRITE_COORD( vecVelocity.y );
WRITE_COORD( vecVelocity.z );

// randomization
WRITE_BYTE( 10 );

// Model
WRITE_SHORT( m_idShard ); //model id#

// # of shards
WRITE_BYTE( m_iGibs ); // let client decide

// duration
WRITE_BYTE( 25 );// 2.5 seconds

// flags
WRITE_BYTE( cFlag );
MESSAGE_END();
BreakModel(vecSpot, pev->size, vecVelocity, m_idShard, m_iGibs, cFlag);
}

/*float size = pev->size.x;
Expand Down Expand Up @@ -1254,39 +1259,10 @@ void CFuncBreakableEffect::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, US

Vector vecSpot = pev->origin + ( pev->mins + pev->maxs ) * 0.5f;

MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot );
WRITE_BYTE( TE_BREAKMODEL );

// position
WRITE_COORD( vecSpot.x );
WRITE_COORD( vecSpot.y );
WRITE_COORD( vecSpot.z );

// size
WRITE_COORD( pev->size.x );
WRITE_COORD( pev->size.y );
WRITE_COORD( pev->size.z );

// velocity
WRITE_COORD( 0 );
WRITE_COORD( 0 );
WRITE_COORD( 0 );

// randomization
WRITE_BYTE( 10 );

// Model
WRITE_SHORT( m_idShard ); //model id#

// # of shards
WRITE_BYTE( m_iGibs ); // let client decide

// duration
WRITE_BYTE( 25 );// 2.5 seconds

// flags
WRITE_BYTE( cFlag );
MESSAGE_END();
if (m_iGibs >= 0)
{
CBreakable::BreakModel(vecSpot, pev->size, g_vecZero, m_idShard, m_iGibs, cFlag);
}

if (!FBitSet(pev->spawnflags, ENV_BREAKABLE_REPEATABLE))
UTIL_Remove(this);
Expand Down
2 changes: 2 additions & 0 deletions dlls/func_break.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class CBreakable : public CBaseDelay
NODE_LINKENT HandleLinkEnt(int afCapMask, bool nodeQueryStatic);
void DamageSound( void );

static void BreakModel(const Vector& vecSpot, const Vector& size, const Vector &vecVelocity, int shardModelIndex, int iGibs, char cFlag);

// breakables use an overridden takedamage
virtual int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
// To spark when hit
Expand Down

0 comments on commit c6b14f2

Please sign in to comment.