From 9079f610d0aa191bf293ac1757833105e967c77e Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 21 Dec 2024 16:53:38 +0200 Subject: [PATCH] maps: make visibility entity optional Based on q2pro. Checked with n64jam_chnuckierdbeer map from https://www.moddb.com/games/quake-2/addons/quake-2-re-release-n64-sp-map-jam --- src/client/refresh/gl1/gl1_model.c | 14 +++++++++++++- src/client/refresh/gl3/gl3_model.c | 14 +++++++++++++- src/client/refresh/gl4/gl4_model.c | 14 +++++++++++++- src/client/refresh/soft/sw_model.c | 14 +++++++++++++- src/client/refresh/vk/vk_model.c | 15 +++++++++++++-- src/common/collision.c | 15 ++++++++++++--- 6 files changed, 77 insertions(+), 9 deletions(-) diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index 2f8f5d2c..05ecd412 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -65,11 +65,23 @@ Mod_HasFreeSpace(void) const byte * Mod_ClusterPVS(int cluster, const model_t *model) { - if ((cluster == -1) || !model->vis) + if (!model->vis) { + memset(mod_novis, 0xFF, sizeof(mod_novis)); return mod_novis; } + if (cluster == -1) + { + memset(mod_novis, 0, sizeof(mod_novis)); + return mod_novis; + } + + if (cluster < 0 || cluster >= model->numvisibility) + { + Com_Error(ERR_DROP, "%s: bad cluster", __func__); + } + return Mod_DecompressVis((byte *)model->vis + model->vis->bitofs[cluster][DVIS_PVS], (byte *)model->vis + model->numvisibility, diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index 83b1861a..9e72eab1 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -66,11 +66,23 @@ Mod_HasFreeSpace(void) const byte * GL3_Mod_ClusterPVS(int cluster, const gl3model_t *model) { - if ((cluster == -1) || !model->vis) + if (!model->vis) { + memset(mod_novis, 0xFF, sizeof(mod_novis)); return mod_novis; } + if (cluster == -1) + { + memset(mod_novis, 0, sizeof(mod_novis)); + return mod_novis; + } + + if (cluster < 0 || cluster >= model->numvisibility) + { + Com_Error(ERR_DROP, "%s: bad cluster", __func__); + } + return Mod_DecompressVis((byte *)model->vis + model->vis->bitofs[cluster][DVIS_PVS], (byte *)model->vis + model->numvisibility, diff --git a/src/client/refresh/gl4/gl4_model.c b/src/client/refresh/gl4/gl4_model.c index 495e5959..4c9275d2 100644 --- a/src/client/refresh/gl4/gl4_model.c +++ b/src/client/refresh/gl4/gl4_model.c @@ -66,11 +66,23 @@ Mod_HasFreeSpace(void) const byte * GL4_Mod_ClusterPVS(int cluster, const gl4model_t *model) { - if ((cluster == -1) || !model->vis) + if (!model->vis) { + memset(mod_novis, 0xFF, sizeof(mod_novis)); return mod_novis; } + if (cluster == -1) + { + memset(mod_novis, 0, sizeof(mod_novis)); + return mod_novis; + } + + if (cluster < 0 || cluster >= model->numvisibility) + { + Com_Error(ERR_DROP, "%s: bad cluster", __func__); + } + return Mod_DecompressVis((byte *)model->vis + model->vis->bitofs[cluster][DVIS_PVS], (byte *)model->vis + model->numvisibility, diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index 2795a64d..b4447021 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -69,11 +69,23 @@ Mod_HasFreeSpace(void) const byte * Mod_ClusterPVS(int cluster, const model_t *model) { - if ((cluster == -1) || !model->vis) + if (!model->vis) { + memset(mod_novis, 0xFF, sizeof(mod_novis)); return mod_novis; } + if (cluster == -1) + { + memset(mod_novis, 0, sizeof(mod_novis)); + return mod_novis; + } + + if (cluster < 0 || cluster >= model->numvisibility) + { + Com_Error(ERR_DROP, "%s: bad cluster", __func__); + } + return Mod_DecompressVis((byte *)model->vis + model->vis->bitofs[cluster][DVIS_PVS], (byte *)model->vis + model->numvisibility, diff --git a/src/client/refresh/vk/vk_model.c b/src/client/refresh/vk/vk_model.c index 5ab96c4c..2e552161 100644 --- a/src/client/refresh/vk/vk_model.c +++ b/src/client/refresh/vk/vk_model.c @@ -39,18 +39,29 @@ int registration_sequence; const byte * Mod_ClusterPVS(int cluster, const model_t *model) { - if ((cluster == -1) || !model->vis) + if (!model->vis) { + memset(mod_novis, 0xFF, sizeof(mod_novis)); return mod_novis; } + if (cluster == -1) + { + memset(mod_novis, 0, sizeof(mod_novis)); + return mod_novis; + } + + if (cluster < 0 || cluster >= model->numvisibility) + { + Com_Error(ERR_DROP, "%s: bad cluster", __func__); + } + return Mod_DecompressVis((byte *)model->vis + model->vis->bitofs[cluster][DVIS_PVS], (byte *)model->vis + model->numvisibility, (model->vis->numclusters + 7) >> 3); } - //=============================================================================== static void diff --git a/src/common/collision.c b/src/common/collision.c index 5df0e2c8..2ad404c7 100644 --- a/src/common/collision.c +++ b/src/common/collision.c @@ -1851,11 +1851,11 @@ CM_LoadCachedMap(const char *name, model_t *mod) if (!mod->map_vis) { - Com_Error(ERR_DROP, "%s: Map %s has no visual clusters.", + Com_Printf("%s: Map %s has no visual clusters.", __func__, name); } - if (mod->numclusters != mod->map_vis->numclusters) + if (mod->map_vis && mod->numclusters != mod->map_vis->numclusters) { Com_Error(ERR_DROP, "%s: Map %s has incorrect number of clusters %d != %d", __func__, name, mod->numclusters, mod->map_vis->numclusters); @@ -2112,12 +2112,21 @@ CM_DecompressVis(byte *in, byte *out) byte * CM_ClusterPVS(int cluster) { - if (cluster == -1 || !cmod->map_vis) + if (!cmod->map_vis) + { + memset(pvsrow, 0xFF, (cmod->numclusters + 7) >> 3); + } + else if (cluster == -1) { memset(pvsrow, 0, (cmod->numclusters + 7) >> 3); } else { + if (cluster < 0 || cluster >= cmod->numclusters) + { + Com_Error(ERR_DROP, "%s: bad cluster", __func__); + } + CM_DecompressVis((byte *)cmod->map_vis + cmod->map_vis->bitofs[cluster][DVIS_PVS], pvsrow); }