From 55899b435a18d54587bb043a7217f1e6ac76a9bd Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Wed, 22 Feb 2023 02:22:37 +1000 Subject: [PATCH] Add cvars that disable linking of SOLID_NOT entities: [cl|sv]_areagrid_link_SOLID_NOT This also removes the partial solution added in b1d6f1dfb96bedba50fbe394ca3f0c710f99381b https://gitlab.com/xonotic/darkplaces/-/merge_requests/78 Signed-off-by: bones_was_here --- cl_collision.c | 2 +- cl_main.c | 4 ++++ client.h | 2 ++ clvm_cmds.c | 2 -- csprogs.c | 2 +- server.h | 1 + sv_main.c | 4 +++- sv_phys.c | 2 +- sv_save.c | 2 +- svvm_cmds.c | 3 +-- world.c | 6 +++++- world.h | 2 +- 12 files changed, 21 insertions(+), 11 deletions(-) diff --git a/cl_collision.c b/cl_collision.c index ad6e5600..2ba9dc49 100644 --- a/cl_collision.c +++ b/cl_collision.c @@ -169,7 +169,7 @@ void CL_LinkEdict(prvm_edict_t *ent) VectorCopy(mins, PRVM_clientedictvector(ent, absmin)); VectorCopy(maxs, PRVM_clientedictvector(ent, absmax)); - World_LinkEdict(&cl.world, ent, mins, maxs); + World_LinkEdict(&cl.world, ent, mins, maxs, cl_areagrid_link_SOLID_NOT.integer); } int CL_GenericHitSuperContentsMask(const prvm_edict_t *passedict) diff --git a/cl_main.c b/cl_main.c index a403f3e6..c1141563 100644 --- a/cl_main.c +++ b/cl_main.c @@ -107,6 +107,8 @@ cvar_t cl_maxfps = {CF_CLIENT | CF_ARCHIVE, "cl_maxfps", "0", "maximum fps cap, cvar_t cl_maxfps_alwayssleep = {CF_CLIENT | CF_ARCHIVE, "cl_maxfps_alwayssleep","1", "gives up some processing time to other applications each frame, value in milliseconds, disabled if cl_maxfps is 0"}; cvar_t cl_maxidlefps = {CF_CLIENT | CF_ARCHIVE, "cl_maxidlefps", "20", "maximum fps cap when the game is not the active window (makes cpu time available to other programs"}; +cvar_t cl_areagrid_link_SOLID_NOT = {CF_CLIENT, "cl_areagrid_link_SOLID_NOT", "1", "set to 0 to prevent SOLID_NOT entities from being linked to the area grid, and unlink any that are already linked (in the code paths that would otherwise link them), for better performance"}; + client_static_t cls; client_state_t cl; @@ -3134,6 +3136,8 @@ void CL_Init (void) Cvar_RegisterVariable (&cl_maxfps_alwayssleep); Cvar_RegisterVariable (&cl_maxidlefps); + Cvar_RegisterVariable (&cl_areagrid_link_SOLID_NOT); + CL_Parse_Init(); CL_Particles_Init(); CL_Screen_Init(); diff --git a/client.h b/client.h index 2006e61f..313ba97c 100644 --- a/client.h +++ b/client.h @@ -1201,6 +1201,8 @@ extern cvar_t cl_prydoncursor_notrace; extern cvar_t cl_locs_enable; +extern cvar_t cl_areagrid_link_SOLID_NOT; + extern client_state_t cl; extern void CL_AllocLightFlash (entity_render_t *ent, matrix4x4_t *matrix, float radius, float red, float green, float blue, float decay, float lifetime, char *cubemapname, int style, int shadowenable, vec_t corona, vec_t coronasizescale, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int flags); diff --git a/clvm_cmds.c b/clvm_cmds.c index 44e62aee..6778f274 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -2641,8 +2641,6 @@ static void VM_CL_copyentity (prvm_prog_t *prog) } memcpy(out->fields.fp, in->fields.fp, prog->entityfields * sizeof(prvm_vec_t)); - if (VectorCompare(PRVM_clientedictvector(out, absmin), PRVM_clientedictvector(out, absmax))) - return; CL_LinkEdict(out); } diff --git a/csprogs.c b/csprogs.c index 4bacb563..20c318a8 100644 --- a/csprogs.c +++ b/csprogs.c @@ -883,7 +883,7 @@ static void CLVM_end_increase_edicts(prvm_prog_t *prog) // link every entity except world for (i = 1, ent = prog->edicts;i < prog->num_edicts;i++, ent++) - if (!ent->free && !VectorCompare(PRVM_clientedictvector(ent, absmin), PRVM_clientedictvector(ent, absmax))) + if (!ent->free) CL_LinkEdict(ent); } diff --git a/server.h b/server.h index 9b97054a..635eb72b 100644 --- a/server.h +++ b/server.h @@ -415,6 +415,7 @@ extern cvar_t sv_allowdownloads_archive; extern cvar_t sv_allowdownloads_config; extern cvar_t sv_allowdownloads_dlcache; extern cvar_t sv_allowdownloads_inarchive; +extern cvar_t sv_areagrid_link_SOLID_NOT; extern cvar_t sv_areagrid_mingridsize; extern cvar_t sv_checkforpacketsduringsleep; extern cvar_t sv_clmovement_enable; diff --git a/sv_main.c b/sv_main.c index fd6a624b..16fd612b 100644 --- a/sv_main.c +++ b/sv_main.c @@ -72,6 +72,7 @@ cvar_t sv_allowdownloads_archive = {CF_SERVER, "sv_allowdownloads_archive", "0", cvar_t sv_allowdownloads_config = {CF_SERVER, "sv_allowdownloads_config", "0", "whether to allow downloads of config files (cfg)"}; cvar_t sv_allowdownloads_dlcache = {CF_SERVER, "sv_allowdownloads_dlcache", "0", "whether to allow downloads of dlcache files (dlcache/)"}; cvar_t sv_allowdownloads_inarchive = {CF_SERVER, "sv_allowdownloads_inarchive", "0", "whether to allow downloads from archives (pak/pk3)"}; +cvar_t sv_areagrid_link_SOLID_NOT = {CF_SERVER | CF_NOTIFY, "sv_areagrid_link_SOLID_NOT", "1", "set to 0 to prevent SOLID_NOT entities from being linked to the area grid, and unlink any that are already linked (in the code paths that would otherwise link them), for better performance"}; cvar_t sv_areagrid_mingridsize = {CF_SERVER | CF_NOTIFY, "sv_areagrid_mingridsize", "128", "minimum areagrid cell size, smaller values work better for lots of small objects, higher values for large objects"}; cvar_t sv_checkforpacketsduringsleep = {CF_SERVER, "sv_checkforpacketsduringsleep", "0", "uses select() function to wait between frames which can be interrupted by packets being received, instead of Sleep()/usleep()/SDL_Sleep() functions which do not check for packets"}; cvar_t sv_clmovement_enable = {CF_SERVER, "sv_clmovement_enable", "1", "whether to allow clients to use cl_movement prediction, which can cause choppy movement on the server which may annoy other players"}; @@ -551,6 +552,7 @@ void SV_Init (void) Cvar_RegisterVariable (&sv_allowdownloads_config); Cvar_RegisterVariable (&sv_allowdownloads_dlcache); Cvar_RegisterVariable (&sv_allowdownloads_inarchive); + Cvar_RegisterVariable (&sv_areagrid_link_SOLID_NOT); Cvar_RegisterVariable (&sv_areagrid_mingridsize); Cvar_RegisterVariable (&sv_checkforpacketsduringsleep); Cvar_RegisterVariable (&sv_clmovement_enable); @@ -2155,7 +2157,7 @@ static void SVVM_end_increase_edicts(prvm_prog_t *prog) // link every entity except world for (i = 1, ent = prog->edicts;i < prog->num_edicts;i++, ent++) - if (!ent->free && !VectorCompare(PRVM_serveredictvector(ent, absmin), PRVM_serveredictvector(ent, absmax))) + if (!ent->free) SV_LinkEdict(ent); } diff --git a/sv_phys.c b/sv_phys.c index 562c0ea9..3e1e2749 100644 --- a/sv_phys.c +++ b/sv_phys.c @@ -904,7 +904,7 @@ void SV_LinkEdict (prvm_edict_t *ent) VectorCopy(mins, PRVM_serveredictvector(ent, absmin)); VectorCopy(maxs, PRVM_serveredictvector(ent, absmax)); - World_LinkEdict(&sv.world, ent, mins, maxs); + World_LinkEdict(&sv.world, ent, mins, maxs, sv_areagrid_link_SOLID_NOT.integer); } /* diff --git a/sv_save.c b/sv_save.c index b90f7487..4c0eca7d 100644 --- a/sv_save.c +++ b/sv_save.c @@ -437,7 +437,7 @@ void SV_Loadgame_f(cmd_state_t *cmd) PRVM_ED_ParseEdict (prog, start, ent); // link it into the bsp tree - if (!ent->free && !VectorCompare(PRVM_serveredictvector(ent, absmin), PRVM_serveredictvector(ent, absmax))) + if (!ent->free) SV_LinkEdict(ent); } diff --git a/svvm_cmds.c b/svvm_cmds.c index e77f9650..a8ed3836 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -1790,8 +1790,7 @@ static void VM_SV_copyentity(prvm_prog_t *prog) return; } memcpy(out->fields.fp, in->fields.fp, prog->entityfields * sizeof(prvm_vec_t)); - if (VectorCompare(PRVM_serveredictvector(out, absmin), PRVM_serveredictvector(out, absmax))) - return; + SV_LinkEdict(out); } diff --git a/world.c b/world.c index 4f7cb48c..229fbe7e 100644 --- a/world.c +++ b/world.c @@ -317,13 +317,17 @@ World_LinkEdict =============== */ -void World_LinkEdict(world_t *world, prvm_edict_t *ent, const vec3_t mins, const vec3_t maxs) +void World_LinkEdict(world_t *world, prvm_edict_t *ent, const vec3_t mins, const vec3_t maxs, qbool link_solid_not) { prvm_prog_t *prog = world->prog; // unlink from old position first if (ent->priv.server->areagrid[0].list.prev) World_UnlinkEdict(ent); + // some games don't want SOLID_NOT entities linked + if (!link_solid_not && PRVM_serveredictfloat(ent, solid) == SOLID_NOT) + return; + // don't add the world if (ent == prog->edicts) return; diff --git a/world.h b/world.h index 1b60ac6c..9e0e0101 100644 --- a/world.h +++ b/world.h @@ -112,7 +112,7 @@ void World_PrintAreaStats(world_t *world, const char *worldname); void World_UnlinkEdict(struct prvm_edict_s *ent); /// Needs to be called any time an entity changes origin, mins, maxs -void World_LinkEdict(world_t *world, struct prvm_edict_s *ent, const vec3_t mins, const vec3_t maxs); +void World_LinkEdict(world_t *world, struct prvm_edict_s *ent, const vec3_t mins, const vec3_t maxs, qbool link_solid_not); /// \returns list of entities touching a box int World_EntitiesInBox(world_t *world, const vec3_t mins, const vec3_t maxs, int maxlist, struct prvm_edict_s **list); -- 2.39.2