From 9465dcfa02862e947b418cbca68df93e74428be9 Mon Sep 17 00:00:00 2001 From: terminx Date: Wed, 30 Jul 2008 11:01:39 +0000 Subject: [PATCH] I think this speeds up software occlusion checking a bit git-svn-id: https://svn.eduke32.com/eduke32@925 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/include/build.h | 2 +- polymer/build/src/engine.c | 9 ++- polymer/build/src/polymost.c | 126 ++++++++++++++------------------ polymer/eduke32/source/config.c | 4 +- polymer/eduke32/source/game.c | 8 +- polymer/eduke32/source/menus.c | 22 +++--- 6 files changed, 82 insertions(+), 89 deletions(-) diff --git a/polymer/build/include/build.h b/polymer/build/include/build.h index 3d9fc7d0f..019527b03 100644 --- a/polymer/build/include/build.h +++ b/polymer/build/include/build.h @@ -551,7 +551,7 @@ extern int r_vbocount; extern int r_animsmoothing; extern int r_parallaxskyclamping; extern int r_parallaxskypanning; -extern int r_cullobstructedmodels; +extern int r_modelocclusionchecking; extern int r_fullbrights; extern int r_downsize; extern int mdtims, omdtims; diff --git a/polymer/build/src/engine.c b/polymer/build/src/engine.c index 5f0958849..a70f8804e 100644 --- a/polymer/build/src/engine.c +++ b/polymer/build/src/engine.c @@ -6345,7 +6345,12 @@ killsprite: if (tspriteptr[spritesortcnt] != NULL) drawsprite(spritesortcnt); } - +#if defined(USE_OPENGL) && defined(POLYMOST) + if (totalclock < lastcullcheck - CULL_DELAY) + lastcullcheck = totalclock; + if (totalclock >= lastcullcheck + CULL_DELAY) + lastcullcheck = (totalclock + CULL_DELAY); +#endif } /* depthpeeling */ #if defined(USE_OPENGL) && defined(POLYMOST) else @@ -6356,6 +6361,8 @@ killsprite: while (j > 0) drawsprite(--j); while (k > 0) drawmaskwall(--k); + if (totalclock >= lastcullcheck + CULL_DELAY) + lastcullcheck = (totalclock + CULL_DELAY); } #endif diff --git a/polymer/build/src/polymost.c b/polymer/build/src/polymost.c index 0d0c7762e..bd9e9fb2d 100644 --- a/polymer/build/src/polymost.c +++ b/polymer/build/src/polymost.c @@ -175,9 +175,9 @@ int r_parallaxskyclamping = 1; int r_parallaxskypanning = 0; // line of sight checks before mddraw() -int r_cullobstructedmodels = 0; -#define CULL_DELAY 5 +int r_modelocclusionchecking = 0; #define CULL_OFFSET 384 +#define CULL_DELAY 3 // fullbright cvar int r_fullbrights = 1; @@ -4439,35 +4439,38 @@ void polymost_drawmaskwall(int damaskwallcnt) drawpoly(dpx,dpy,n,method); } -// int lastcullcheck[MAXSPRITES]; +int lastcullcheck = 0; char cullmodel[MAXSPRITES]; int polymost_checkcoordinates(int x, int y, spritetype *tspr) { short datempsectnum = tspr->sectnum; - int i; + int oldx = x, i, j = (tilesizy[tspr->picnum]*tspr->yrepeat); +RECHECK: updatesector(tspr->x+x,tspr->y+y,&datempsectnum); + if (datempsectnum == -1) - return 0; - /* if (cansee(globalposx, globalposy, globalposz, globalcursectnum, - tspr->x+x, tspr->y+y, sector[datempsectnum].floorz, datempsectnum)) - return 1; - if (cansee(globalposx, globalposy, globalposz, globalcursectnum, - tspr->x+x, tspr->y+y, sector[datempsectnum].ceilingz, datempsectnum)) - return 1; */ - if (cansee(globalposx, globalposy, globalposz, globalcursectnum, - tspr->x+x, tspr->y+y, tspr->z, datempsectnum)) - return 1; + { + if (x == y || x != oldx) + return 0; + swaplong(&x,&y); + updatesector(tspr->x+x,tspr->y+y,&datempsectnum); + } + for (i=4;i>-1;i--) { if (cansee(globalposx, globalposy, globalposz, globalcursectnum, - tspr->x+x, tspr->y+y, tspr->z-((tilesizy[tspr->picnum]*tspr->yrepeat)*i)-512, datempsectnum)) + tspr->x+x, tspr->y+y, tspr->z-(j*i)-512, datempsectnum)) return 1; -/* if (cansee(globalposx, globalposy, globalposz, globalcursectnum, - tspr->x+x, tspr->y+y, tspr->z+((tilesizy[tspr->picnum]*tspr->yrepeat)*i), datempsectnum)) - return 1; */ } + + if (x != y && x == oldx) + { + swaplong(&x,&y); + goto RECHECK; + } + return 0; } @@ -4481,7 +4484,6 @@ void polymost_drawsprite(int snum) int posx,posy; int oldsizx, oldsizy; int tsizx, tsizy; - md2model *modelptr = NULL; tspr = tspriteptr[snum]; if (tspr->owner < 0 || tspr->picnum < 0) return; @@ -4530,57 +4532,41 @@ void polymost_drawsprite(int snum) if (mddraw(tspr)) return; break; // else, render as flat sprite } - modelptr = (md2model *)models[tile2model[Ptile2tile(tspr->picnum,tspr->pal)].modelid]; - if (r_cullobstructedmodels == 1 || (r_cullobstructedmodels == 2 && (modelptr->usesalpha))) + if (r_modelocclusionchecking) { - do // this is so gay + if (totalclock >= lastcullcheck + CULL_DELAY) { - if (/*totalclock < lastcullcheck[tspr->owner] ||*/ tspr->statnum == TSPR_TEMP) + do // this is so gay + { + // don't bother with shadows because processing its owner will take care of it + if (tspr->statnum == TSPR_TEMP) + break; + cullmodel[tspr->owner] = 1; + + if (cansee(globalposx, globalposy, globalposz, globalcursectnum, + tspr->x, tspr->y, tspr->z,tspr->sectnum)) + { cullmodel[tspr->owner] = 0; break; } + + if (polymost_checkcoordinates(-CULL_OFFSET, 0, tspr)) + { cullmodel[tspr->owner] = 0; break; } + if (polymost_checkcoordinates(-CULL_OFFSET, -CULL_OFFSET, tspr)) + { cullmodel[tspr->owner] = 0; break; } + + if (polymost_checkcoordinates(CULL_OFFSET, 0, tspr)) + { cullmodel[tspr->owner] = 0; break; } + if (polymost_checkcoordinates(CULL_OFFSET, CULL_OFFSET, tspr)) + { cullmodel[tspr->owner] = 0; break; } + + if (polymost_checkcoordinates(-CULL_OFFSET, CULL_OFFSET, tspr)) + { cullmodel[tspr->owner] = 0; break; } + + if (polymost_checkcoordinates(0, 0, tspr)) + { cullmodel[tspr->owner] = 0; break; } + break; - cullmodel[tspr->owner] = 1; -/* if (cansee(globalposx, globalposy, sector[globalcursectnum].ceilingz, globalcursectnum, - tspr->x, tspr->y, tspr->z, tspr->sectnum)) - { cullmodel[tspr->owner] = 0; break; } - if (cansee(globalposx, globalposy, globalposz, globalcursectnum, - tspr->x, tspr->y, tspr->z-((tilesizy[tspr->picnum]*tspr->yrepeat)<<2),tspr->sectnum)) - { cullmodel[tspr->owner] = 0; break; } */ - if (cansee(globalposx, globalposy, globalposz, globalcursectnum, - tspr->x, tspr->y, tspr->z,tspr->sectnum)) - { cullmodel[tspr->owner] = 0; break; } -/* if (cansee(globalposx, globalposy, globalposz, globalcursectnum, - tspr->x, tspr->y, globalposz,tspr->sectnum)) - { cullmodel[tspr->owner] = 0; break; } */ -/* if (cansee(globalposx, globalposy, sector[globalcursectnum].floorz, globalcursectnum, - tspr->x, tspr->y, tspr->z, tspr->sectnum)) - { cullmodel[tspr->owner] = 0; break; } */ - - if (polymost_checkcoordinates(0, 0, tspr)) - { cullmodel[tspr->owner] = 0; break; } - - i = CULL_OFFSET; - if (polymost_checkcoordinates(-i, 0, tspr)) - { cullmodel[tspr->owner] = 0; break; } - if (polymost_checkcoordinates(-i, -i, tspr)) - { cullmodel[tspr->owner] = 0; break; } - if (polymost_checkcoordinates(0, -i, tspr)) - { cullmodel[tspr->owner] = 0; break; } - - if (polymost_checkcoordinates(i, 0, tspr)) - { cullmodel[tspr->owner] = 0; break; } - if (polymost_checkcoordinates(i, i, tspr)) - { cullmodel[tspr->owner] = 0; break; } - if (polymost_checkcoordinates(0, i, tspr)) - { cullmodel[tspr->owner] = 0; break; } - - if (polymost_checkcoordinates(-i, i, tspr)) - { cullmodel[tspr->owner] = 0; break; } - if (polymost_checkcoordinates(i, -i, tspr)) - { cullmodel[tspr->owner] = 0; break; } - break; + } + while (1); } - while (1); -/* if (totalclock >= lastcullcheck[tspr->owner]) - lastcullcheck[tspr->owner] = totalclock + CULL_DELAY; */ } else cullmodel[tspr->owner] = 0; if (cullmodel[tspr->owner]) break; @@ -5980,10 +5966,10 @@ static int osdcmd_polymostvars(const osdfuncparm_t *parm) } return OSDCMD_OK; } - else if (!Bstrcasecmp(parm->name, "r_cullobstructedmodels")) + else if (!Bstrcasecmp(parm->name, "r_modelocclusionchecking")) { - if (showval) { OSD_Printf("r_cullobstructedmodels is %d\n", r_cullobstructedmodels); } - else r_cullobstructedmodels = max(0,min(val,2)); + if (showval) { OSD_Printf("r_modelocclusionchecking is %d\n", r_modelocclusionchecking); } + else r_modelocclusionchecking = max(0,min(val,2)); return OSDCMD_OK; } else if (!Bstrcasecmp(parm->name, "r_fullbrights")) @@ -6050,7 +6036,7 @@ void polymost_initosdfuncs(void) { #ifdef USE_OPENGL OSD_RegisterFunction("r_animsmoothing","r_animsmoothing: enable/disable model animation smoothing",osdcmd_polymostvars); - OSD_RegisterFunction("r_cullobstructedmodels","r_cullobstructedmodels: enable/disable hack to cull \"obstructed\" models",osdcmd_polymostvars); + OSD_RegisterFunction("r_modelocclusionchecking","r_modelocclusionchecking: enable/disable hack to cull \"obstructed\" models",osdcmd_polymostvars); OSD_RegisterFunction("r_curpeel","r_curpeel: allows to display one depth layer at a time (for development purposes)",osdcmd_polymostvars); OSD_RegisterFunction("r_depthpeeling","r_depthpeeling: enable/disable order-independant transparency",osdcmd_polymostvars); OSD_RegisterFunction("r_detailmapping","r_detailmapping: enable/disable detail mapping",osdcmd_polymostvars); diff --git a/polymer/eduke32/source/config.c b/polymer/eduke32/source/config.c index 3c671621c..b6a2ee729 100644 --- a/polymer/eduke32/source/config.c +++ b/polymer/eduke32/source/config.c @@ -705,7 +705,7 @@ int32 CONFIG_ReadSetup(void) SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLParallaxSkyClamping", &r_parallaxskyclamping); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLParallaxSkyPanning", &r_parallaxskypanning); - SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLCullObstructedModels", &r_cullobstructedmodels); + SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLOcclusionChecking", &r_modelocclusionchecking); SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLTextureQuality", &r_downsize); dummy = usemodels; SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "UseModels",&dummy); @@ -926,7 +926,7 @@ void CONFIG_WriteSetup(void) SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLParallaxSkyClamping",r_parallaxskyclamping,false,false); SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLParallaxSkyPanning",r_parallaxskypanning,false,false); - SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLCullObstructedModels", r_cullobstructedmodels,false,false); + SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLOcclusionChecking", r_modelocclusionchecking,false,false); SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLTextureQuality", r_downsize,false,false); #endif #ifdef RENDERTYPEWIN diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index c539f746a..dd5552cfc 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -2355,13 +2355,13 @@ static void coolgaugetext(int snum) } } -#define AVERAGEFRAMES 16 -static int frameval[AVERAGEFRAMES], framecnt = 0; +#define AVERAGEFRAMES 128 static void tics(void) { int i = totalclock,j; - char b[10]; + static int frameval[AVERAGEFRAMES], framecnt = 0; + char b[4]; if (i != frameval[framecnt]) { @@ -3530,7 +3530,7 @@ void displayrest(int smoothratio) if (ud.screen_size == 4) { i = scale(tilesizy[INVENTORYBOX]+2,ud.statusbarscale,100); - j = scale(scale(5,ud.config.ScreenWidth,320),ud.statusbarscale,100); + j = scale(scale(6,ud.config.ScreenWidth,320),ud.statusbarscale,100); } else if (ud.screen_size > 2) { diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index 8ae103857..aabedba5d 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -2450,7 +2450,7 @@ cheat_for_port_credits: "-", "Use models", "Blend model animations", - "Cull obstructed models", + "Model occlusion checking", NULL }; @@ -2553,37 +2553,37 @@ cheat_for_port_credits: enabled = usehightile; if (enabled && x==io) ud.config.useprecache = !ud.config.useprecache; if (enabled) modval(0,1,(int *)&ud.config.useprecache,1,probey==io); - mgametextpal(d,yy, ud.config.useprecache && enabled ? "On" : "Off", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); + mgametextpal(d,yy, ud.config.useprecache ? "On" : "Off", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); break; case 7: enabled = usehightile; if (enabled && x==io) glusetexcompr = !glusetexcompr; if (enabled) modval(0,1,(int *)&glusetexcompr,1,probey==io); - mgametextpal(d,yy, glusetexcompr && enabled ? "On" : "Off", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); + mgametextpal(d,yy, glusetexcompr ? "On" : "Off", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); break; case 8: enabled = (glusetexcompr && usehightile); if (enabled && x==io) glusetexcache = !glusetexcache; if (enabled) modval(0,1,(int *)&glusetexcache,1,probey==io); - mgametextpal(d,yy, glusetexcache && enabled ? "On" : "Off", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); + mgametextpal(d,yy, glusetexcache ? "On" : "Off", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); break; case 9: enabled = (glusetexcompr && usehightile && glusetexcache); if (enabled && x==io) glusetexcachecompression = !glusetexcachecompression; if (enabled) modval(0,1,(int *)&glusetexcachecompression,1,probey==io); - mgametextpal(d,yy, glusetexcachecompression && enabled ? "On" : "Off", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); + mgametextpal(d,yy, glusetexcachecompression ? "On" : "Off", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); break; case 10: enabled = usehightile; if (enabled && x==io) r_detailmapping = !r_detailmapping; if (enabled) modval(0,1,(int *)&r_detailmapping,1,probey==io); - mgametextpal(d,yy, r_detailmapping && enabled ? "Yes" : "No", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); + mgametextpal(d,yy, r_detailmapping ? "Yes" : "No", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); break; case 11: enabled = usehightile; if (enabled && x==io) r_glowmapping = !r_glowmapping; if (enabled) modval(0,1,(int *)&r_glowmapping,1,probey==io); - mgametextpal(d,yy, r_glowmapping && enabled ? "Yes" : "No", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); + mgametextpal(d,yy, r_glowmapping ? "Yes" : "No", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); break; case 12: if (x==io) usemodels = 1-usemodels; @@ -2594,13 +2594,13 @@ cheat_for_port_credits: enabled = usemodels; if (enabled && x==io) r_animsmoothing = !r_animsmoothing; if (enabled) modval(0,1,(int *)&r_animsmoothing,1,probey==io); - mgametextpal(d,yy, r_animsmoothing && enabled ? "Yes" : "No", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); + mgametextpal(d,yy, r_animsmoothing ? "Yes" : "No", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); break; case 14: enabled = usemodels; - if (enabled && x==io) r_cullobstructedmodels = !r_cullobstructedmodels; - if (enabled) modval(0,1,(int *)&r_cullobstructedmodels,1,probey==io); - mgametextpal(d,yy, r_cullobstructedmodels && enabled ? "Yes" : "No", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); + if (enabled && x==io) r_modelocclusionchecking = !r_modelocclusionchecking; + if (enabled) modval(0,1,(int *)&r_modelocclusionchecking,1,probey==io); + mgametextpal(d,yy, r_modelocclusionchecking ? "Yes" : "No", enabled?MENUHIGHLIGHT(io):DISABLEDMENUSHADE, 0); break; default: break;