From 0e8d1acb0507172fb82a0059f2c85d4c4a9771e2 Mon Sep 17 00:00:00 2001 From: Spoike Date: Fri, 24 Apr 2020 12:11:29 +0000 Subject: [PATCH] Try to fix load times with certain q3bsps, by deferring phs calcs. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5679 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/common/gl_q2bsp.c | 115 ++++++++++++++++++++++++++++++--------- 1 file changed, 88 insertions(+), 27 deletions(-) diff --git a/engine/common/gl_q2bsp.c b/engine/common/gl_q2bsp.c index 7cb0fd4e4..f4df427c7 100644 --- a/engine/common/gl_q2bsp.c +++ b/engine/common/gl_q2bsp.c @@ -361,6 +361,7 @@ typedef struct cminfo_s q2dvis_t *q2vis; q3dvis_t *q3pvs; q3dvis_t *q3phs; + qbyte *phscalced; int numareas; int floodvalid; @@ -4139,6 +4140,49 @@ static void CM_OpenAllPortals(model_t *mod, char *ents) //this is a compleate ha #if !defined(CLIENTONLY) && defined(Q3BSPS) +static void CalcClusterPHS(cminfo_t *prv, int cluster) +{ + int j, k, l, index; + int bitbyte; + unsigned int *dest, *src; + qbyte *scan; + + int numclusters = prv->q3pvs->numclusters; + int rowbytes = prv->q3pvs->rowsize; + int rowwords = rowbytes / sizeof(int); + + scan = (qbyte *)prv->q3pvs->data; + dest = (unsigned int *)(prv->q3phs->data); + + dest += rowwords*cluster; + scan += rowbytes*cluster; + for (j=0 ; j= numclusters) + { +// if (!buggytools) +// Con_Printf ("CM_CalcPHS: Bad bit(s) in PVS (%i >= %i)\n", index, numclusters); // pad bits should be 0 +// buggytools = true; + } + else + { + src = (unsigned int *)(prv->q3pvs->data) + index*rowwords; + for (l=0 ; lphscalced[cluster>>3] |= 1<<(cluster&7); +} static void CMQ3_CalcPHS (model_t *mod) { cminfo_t *prv = (cminfo_t*)mod->meshinfo; @@ -4150,6 +4194,7 @@ static void CMQ3_CalcPHS (model_t *mod) int count, vcount; int numclusters; qboolean buggytools = false; + extern cvar_t sv_calcphs; Con_DPrintf ("Building PHS...\n"); @@ -4182,41 +4227,55 @@ static void CMQ3_CalcPHS (model_t *mod) scan = (qbyte *)prv->q3pvs->data; dest = (unsigned int *)(prv->q3phs->data); - for (i=0 ; i= 2) + { //delay-calculate it. + prv->phscalced = ZG_Malloc(&mod->memgroup, (prv->q3pvs->numclusters+7)/8); + memcpy(dest, scan, rowbytes*numclusters); + Con_DPrintf ("Average clusters visible / total: %i / %i\n" + , vcount/numclusters, numclusters); + } + else if (!sv_calcphs.ival) + { //disable calcs (behaves like broadcast so just fill with 1s) + memset(dest, 0xff, rowbytes*numclusters); + } + else + { //the original slow logic like q3. + for (i=0 ; i= numclusters) + for (k=0 ; k<8 ; k++) { - if (!buggytools) - Con_Printf ("CM_CalcPHS: Bad bit(s) in PVS (%i >= %i)\n", index, numclusters); // pad bits should be 0 - buggytools = true; - } - else - { - src = (unsigned int *)(prv->q3pvs->data) + index*rowwords; - for (l=0 ; l= numclusters) + { + if (!buggytools) + Con_Printf ("CM_CalcPHS: Bad bit(s) in PVS (%i >= %i)\n", index, numclusters); // pad bits should be 0 + buggytools = true; + } + else + { + src = (unsigned int *)(prv->q3pvs->data) + index*rowwords; + for (l=0 ; l>3] & (1<<(j&7)) ) + count++; } - for (j=0 ; j>3] & (1<<(j&7)) ) - count++; - } - Con_DPrintf ("Average clusters visible / hearable / total: %i / %i / %i\n" - , vcount/numclusters, count/numclusters, numclusters); + Con_DPrintf ("Average clusters visible / hearable / total: %i / %i / %i\n" + , vcount/numclusters, count/numclusters, numclusters); + } } #endif @@ -7291,6 +7350,8 @@ qbyte *CM_ClusterPHS (model_t *mod, int cluster, pvsbuffer_t *buffer) { if (cluster != -1 && prv->q3phs->numclusters) { + if (prv->phscalced && !(prv->phscalced[cluster>>3] & (1<<(cluster&7)))) + CalcClusterPHS(prv, cluster); return (qbyte *)prv->q3phs->data + cluster * prv->q3phs->rowsize; } else