Browse Source

Smarter distance clipping

gravgun
mittorn 6 years ago
parent
commit
12c094abb5
  1. 64
      dlls/client.cpp
  2. 2
      dlls/gravgunmod.cpp
  3. 1
      dlls/gravgunmod.h

64
dlls/client.cpp

@ -1243,29 +1243,23 @@ int AddToFullPack( struct entity_state_s *state, int e, edict_t *ent, edict_t *h
if( mp_serverdistclip.value ) if( mp_serverdistclip.value )
{ {
bool bmodel = false, trash = false; bool isbmodel = false, istrash = false, ismonster = false;
const char *classname = ""; const char *classname = "";
if( ent->v.model && STRING(ent->v.model) && *STRING(ent->v.model) == '*' ) if( ent->v.model && STRING(ent->v.model) && *STRING(ent->v.model) == '*' )
bmodel = true; isbmodel = true;
if( ent->v.classname && STRING(ent->v.classname) ) if( ent->v.classname && STRING(ent->v.classname) )
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) ) if( !strcmp( classname, "gib" ) || !strncmp( classname, "weapon_", 7) || !strncmp( classname, "ammo_", 5) || !strncmp( classname, "item_", 5) )
trash = true; istrash = true;
else if( !strncmp( classname, "monster_", 8 ) )
ismonster = true;
Vector delta = VecBModelOrigin(&ent->v) - host->v.origin; Vector delta = ( ent->v.absmin + ent->v.absmax ) / 2 - host->v.origin;
float dist = 0; float size = 0, 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 ) if( ent->v.size.x > size )
size = ent->v.size.x; size = ent->v.size.x;
@ -1274,23 +1268,39 @@ int AddToFullPack( struct entity_state_s *state, int e, edict_t *ent, edict_t *h
if( ent->v.size.z > size ) if( ent->v.size.z > size )
size = ent->v.size.z; size = ent->v.size.z;
dist -= size; if( size > 512 ) // big brushes may be rotated, but dist check does not cover this
dist = abs(delta.z), size = ent->v.size.z;
else
{
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);
}
dist -= size / 2;
if( bmodel ) // brushes needed to pmove prediction if( size <= 32 && ismonster )
istrash = true; // we can hide small monsters like trash
//printf("%s %s %f %f %f %f %f\n", classname, STRING(ent->v.model), size, dist, delta.z,ent->v.origin.z, host->v.origin.z );
if( isbmodel ) // brushes needed to pmove prediction
{ {
if( dist > mp_maxbmodeldist.value ) // water renders too slow
if( ent->v.skin == -3 && dist > mp_maxwaterdist.value )
hide = true;
else if( dist > mp_maxbmodeldist.value )
hide = true; hide = true;
} // low priority models. Nothing will break if we hide it, so hide if packet full }
else if( trash && ( dist > mp_maxtrashdist.value || counter > 480 ) ) else if( istrash && ( dist > mp_maxtrashdist.value || counter > 448 ) ) // reserve 64 visents
hide = true; // other entities. May break beams, etc... hide = true; // low priority models.
else if( dist > mp_maxotherdist.value ) // Nothing will break if we hide it, so hide if packet full
hide = true; else if( ismonster && dist > mp_maxmonsterdist.value )
// func_water renders too slow
if( !strcmp( classname, "func_water" ) && dist > mp_maxwaterdist.value )
hide = true; hide = true;
else if( size > 512 ) // big brushes may be rotated, but dist check does not cover this else if( dist > mp_maxotherdist.value )
hide = false; hide = true; // other entities. May break beams, etc...
if( hide ) if( hide )
{ {
@ -1299,7 +1309,7 @@ int AddToFullPack( struct entity_state_s *state, int e, edict_t *ent, edict_t *h
// attachments/sounds, so we may just skip adding it to packet // attachments/sounds, so we may just skip adding it to packet
// but left it just hidden if we have enough visents to prevent // but left it just hidden if we have enough visents to prevent
// sending big delta packets, but reserve 256 slots for visible // sending big delta packets, but reserve 256 slots for visible
if( counter > 128 && !trash || counter > 256 ) if( counter > 128 && !istrash || counter > 256 )
return 0; return 0;
} }

2
dlls/gravgunmod.cpp

@ -28,6 +28,7 @@ cvar_t mp_maxbmodeldist = { "mp_maxbmodeldist", "4096", FCVAR_SERVER};
cvar_t mp_maxtrashdist = { "mp_maxtrashdist", "4096", FCVAR_SERVER}; cvar_t mp_maxtrashdist = { "mp_maxtrashdist", "4096", FCVAR_SERVER};
cvar_t mp_maxwaterdist = { "mp_maxwaterdist", "4096", FCVAR_SERVER}; cvar_t mp_maxwaterdist = { "mp_maxwaterdist", "4096", FCVAR_SERVER};
cvar_t mp_maxotherdist = { "mp_maxotherdist", "4096", FCVAR_SERVER}; cvar_t mp_maxotherdist = { "mp_maxotherdist", "4096", FCVAR_SERVER};
cvar_t mp_maxmonsterdist = { "mp_maxmonsterdist", "4096", FCVAR_SERVER};
cvar_t mp_servercliptents = { "mp_servercliptents", "0", FCVAR_SERVER}; cvar_t mp_servercliptents = { "mp_servercliptents", "0", FCVAR_SERVER};
cvar_t mp_maxtentdist = { "mp_maxtentdist", "4096", FCVAR_SERVER}; cvar_t mp_maxtentdist = { "mp_maxtentdist", "4096", FCVAR_SERVER};
@ -102,6 +103,7 @@ void GGM_RegisterCVars( void )
CVAR_REGISTER( &mp_maxbmodeldist ); CVAR_REGISTER( &mp_maxbmodeldist );
CVAR_REGISTER( &mp_maxtrashdist ); CVAR_REGISTER( &mp_maxtrashdist );
CVAR_REGISTER( &mp_maxwaterdist ); CVAR_REGISTER( &mp_maxwaterdist );
CVAR_REGISTER( &mp_maxmonsterdist );
CVAR_REGISTER( &mp_maxotherdist ); CVAR_REGISTER( &mp_maxotherdist );
CVAR_REGISTER( &mp_servercliptents ); CVAR_REGISTER( &mp_servercliptents );
CVAR_REGISTER( &mp_maxtentdist ); CVAR_REGISTER( &mp_maxtentdist );

1
dlls/gravgunmod.h

@ -24,6 +24,7 @@ extern cvar_t mp_serverdistclip;
extern cvar_t mp_maxbmodeldist; extern cvar_t mp_maxbmodeldist;
extern cvar_t mp_maxtrashdist; extern cvar_t mp_maxtrashdist;
extern cvar_t mp_maxwaterdist; extern cvar_t mp_maxwaterdist;
extern cvar_t mp_maxmonsterdist;
extern cvar_t mp_maxotherdist; extern cvar_t mp_maxotherdist;
extern cvar_t mp_servercliptents; extern cvar_t mp_servercliptents;
extern cvar_t mp_maxtentdist; extern cvar_t mp_maxtentdist;

Loading…
Cancel
Save