diff --git a/dlls/client.cpp b/dlls/client.cpp index 3a562bfb..7525901c 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -1391,6 +1391,63 @@ int AddToFullPack( struct entity_state_s *state, int e, edict_t *ent, edict_t *h if( ent->v.movetype == MOVETYPE_WALK || ent->v.movetype == MOVETYPE_STEP ) //state->effects |= EF_NOINTERP; state->movetype = MOVETYPE_TOSS; + + if( mp_serverdistclip.value ) + { + bool bmodel = false, trash = false; + const char *classname = ""; + + if( ent->v.model && STRING(ent->v.model) && *STRING(ent->v.model) == '*' ) + bmodel = true; + + if( ent->v.classname && STRING(ent->v.classname) ) + classname = STRING( ent->v.classname ); + + if( !strcmp( classname, "gib" ) || !strncmp( classname, "weapon_", 7) || !strncmp( classname, "ammo_", 5) || !strncmp( classname, "item_", 5) ) + trash = true; + + Vector delta = VecBModelOrigin(&ent->v) - host->v.origin; + + float dist = 0; + if( abs(delta.x) > dist ) + dist = abs(delta.x); + if( abs(delta.y) > dist ) + dist = abs(delta.y); + if( abs(delta.z) > dist ) + dist = abs(delta.z); + + float size = 0; + + if( ent->v.size.x > size ) + size = ent->v.size.x; + if( ent->v.size.y > size ) + size = ent->v.size.y; + if( ent->v.size.z > size ) + size = ent->v.size.z; + + dist -= size; + + bool hide = false; + + if( bmodel ) + { + if( dist > mp_maxbmodeldist.value ) + hide = true; + } + else if( trash && dist > mp_maxtrashdist.value ) + hide = true; + else if( dist > mp_maxotherdist.value ) + hide = true; + + // func_water renders too slow + if( !strcmp( classname, "func_water" ) && dist > mp_maxwaterdist.value ) + hide = true; + else if( size > 512 ) // big brushes may be rotated, but dist check does not cover this + hide = false; + + if( hide ) + state->effects |= EF_NODRAW; + } // gravgun hacks if( ent->pvPrivateData && CBaseEntity::Instance( ent)->m_fireState == ENTINDEX(host) ) { diff --git a/dlls/gravgunmod.cpp b/dlls/gravgunmod.cpp index 4703e584..4b0a4fb9 100644 --- a/dlls/gravgunmod.cpp +++ b/dlls/gravgunmod.cpp @@ -23,6 +23,11 @@ cvar_t mp_checkentities = { "mp_checkentities", "0", FCVAR_SERVER }; cvar_t mp_touchmenu = { "mp_touchmenu", "1", FCVAR_SERVER }; cvar_t mp_touchname = { "mp_touchname", "", FCVAR_SERVER }; cvar_t mp_touchcommand = { "mp_touchcommand", "", FCVAR_SERVER }; +cvar_t mp_serverdistclip = { "mp_serverdistclip", "0", FCVAR_SERVER}; +cvar_t mp_maxbmodeldist = { "mp_maxbmodeldist", "4096", FCVAR_SERVER}; +cvar_t mp_maxtrashdist = { "mp_maxtrashdist", "4096", FCVAR_SERVER}; +cvar_t mp_maxwaterdist = { "mp_maxwaterdist", "4096", FCVAR_SERVER}; +cvar_t mp_maxotherdist = { "mp_maxotherdist", "4096", FCVAR_SERVER}; void Ent_RunGC_f( void ); @@ -91,6 +96,12 @@ void GGM_RegisterCVars( void ) CVAR_REGISTER( &mp_touchmenu ); CVAR_REGISTER( &mp_touchname ); CVAR_REGISTER( &mp_touchcommand ); + CVAR_REGISTER( &mp_serverdistclip ); + CVAR_REGISTER( &mp_maxbmodeldist ); + CVAR_REGISTER( &mp_maxtrashdist ); + CVAR_REGISTER( &mp_maxwaterdist ); + CVAR_REGISTER( &mp_maxotherdist ); + g_engfuncs.pfnAddServerCommand( "ent_rungc", Ent_RunGC_f ); } diff --git a/dlls/gravgunmod.h b/dlls/gravgunmod.h index f731f31f..71a749f6 100644 --- a/dlls/gravgunmod.h +++ b/dlls/gravgunmod.h @@ -19,6 +19,13 @@ extern cvar_t mp_fixhornetbug; extern cvar_t mp_checkentities; extern cvar_t mp_touchmenu; +// distance clipping (client.cpp) +extern cvar_t mp_serverdistclip; +extern cvar_t mp_maxbmodeldist; +extern cvar_t mp_maxtrashdist; +extern cvar_t mp_maxwaterdist; +extern cvar_t mp_maxotherdist; + void GGM_RegisterCVars( void ); void Ent_RunGC( bool common, bool enttools, const char *userid, const char *pattern = NULL ); bool Q_stricmpext( const char *pattern, const char *text );