From 316918c29b0540d11c32361d11e1ae548d7d92be Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 16 Sep 2018 15:47:59 +0300 Subject: [PATCH] cleanup code in sw_surf --- src/client/refresh/soft/sw_alias.c | 1 + src/client/refresh/soft/sw_surf.c | 154 ++++++++++++++--------------- 2 files changed, 75 insertions(+), 80 deletions(-) diff --git a/src/client/refresh/soft/sw_alias.c b/src/client/refresh/soft/sw_alias.c index 590e5781..2c5f6e40 100644 --- a/src/client/refresh/soft/sw_alias.c +++ b/src/client/refresh/soft/sw_alias.c @@ -330,6 +330,7 @@ R_AliasSetUpTransform(const entity_t *currententity) // TODO: should use a look-up table // TODO: could cache lazily, stored in the entity // + // AngleVectors never change angles, we can convert from const AngleVectors((float *)currententity->angles, s_alias_forward, s_alias_right, s_alias_up ); // TODO: can do this with simple matrix rearrangement diff --git a/src/client/refresh/soft/sw_surf.c b/src/client/refresh/soft/sw_surf.c index f05c559b..cc99a1ee 100644 --- a/src/client/refresh/soft/sw_surf.c +++ b/src/client/refresh/soft/sw_surf.c @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "header/local.h" -static int lightleft, blocksize, sourcetstep; +static int lightleft, sourcetstep; static int lightright, lightleftstep, lightrightstep, blockdivshift; static void *prowdestbase; static unsigned char *pbasesource; @@ -31,8 +31,6 @@ static int r_numhblocks, r_numvblocks; static unsigned char *r_source, *r_sourcemax; static unsigned *r_lightptr; -static void R_DrawSurfaceBlock8_anymip (int level, int surfrowbytes); - void R_BuildLightMap (drawsurf_t *drawsurf); extern unsigned blocklights[1024]; // allow some very large lightmaps @@ -68,82 +66,6 @@ R_TextureAnimation (const entity_t *currententity, mtexinfo_t *tex) } -/* -=============== -R_DrawSurface -=============== -*/ -static void -R_DrawSurface (drawsurf_t *drawsurf) -{ - unsigned char *basetptr; - int smax, tmax, twidth; - int u; - int soffset, basetoffset, texwidth; - unsigned char *pcolumndest; - image_t *mt; - - mt = drawsurf->image; - - r_source = mt->pixels[drawsurf->surfmip]; - - // the fractional light values should range from 0 to (VID_GRADES - 1) << 16 - // from a source range of 0 - 255 - - texwidth = mt->width >> drawsurf->surfmip; - - blocksize = 16 >> drawsurf->surfmip; - blockdivshift = NUM_MIPS - drawsurf->surfmip; - - r_lightwidth = (drawsurf->surf->extents[0]>>4)+1; - - r_numhblocks = drawsurf->surfwidth >> blockdivshift; - r_numvblocks = drawsurf->surfheight >> blockdivshift; - - //============================== - - // TODO: only needs to be set when there is a display settings change - // blocksize = blocksize; - - smax = mt->width >> drawsurf->surfmip; - twidth = texwidth; - tmax = mt->height >> drawsurf->surfmip; - sourcetstep = texwidth; - r_stepback = tmax * twidth; - - r_sourcemax = r_source + (tmax * smax); - - soffset = drawsurf->surf->texturemins[0]; - basetoffset = drawsurf->surf->texturemins[1]; - - // << 16 components are to guarantee positive values for % - soffset = ((soffset >> drawsurf->surfmip) + (smax << SHIFT16XYZ)) % smax; - basetptr = &r_source[((((basetoffset >> drawsurf->surfmip) - + (tmax << SHIFT16XYZ)) % tmax) * twidth)]; - - pcolumndest = drawsurf->surfdat; - - for (u=0 ; usurfmip, drawsurf->rowbytes); - - soffset = soffset + blocksize; - if (soffset >= smax) - soffset = 0; - - pcolumndest += blocksize; - } -} - - -//============================================================================= - /* ================ R_DrawSurfaceBlock8_anymip @@ -195,8 +117,80 @@ R_DrawSurfaceBlock8_anymip (int level, int surfrowbytes) } } -//============================================================================ +/* +=============== +R_DrawSurface +=============== +*/ +static void +R_DrawSurface (drawsurf_t *drawsurf) +{ + unsigned char *basetptr; + int smax, tmax, twidth; + int u; + int soffset, basetoffset, texwidth; + int blocksize; + unsigned char *pcolumndest; + image_t *mt; + + mt = drawsurf->image; + + r_source = mt->pixels[drawsurf->surfmip]; + + // the fractional light values should range from 0 to (VID_GRADES - 1) << 16 + // from a source range of 0 - 255 + + texwidth = mt->width >> drawsurf->surfmip; + + blocksize = 16 >> drawsurf->surfmip; + blockdivshift = NUM_MIPS - drawsurf->surfmip; + + r_lightwidth = (drawsurf->surf->extents[0]>>4)+1; + + r_numhblocks = drawsurf->surfwidth >> blockdivshift; + r_numvblocks = drawsurf->surfheight >> blockdivshift; + + //============================== + + smax = mt->width >> drawsurf->surfmip; + twidth = texwidth; + tmax = mt->height >> drawsurf->surfmip; + sourcetstep = texwidth; + r_stepback = tmax * twidth; + + r_sourcemax = r_source + (tmax * smax); + + soffset = drawsurf->surf->texturemins[0]; + basetoffset = drawsurf->surf->texturemins[1]; + + // << 16 components are to guarantee positive values for % + soffset = ((soffset >> drawsurf->surfmip) + (smax << SHIFT16XYZ)) % smax; + basetptr = &r_source[((((basetoffset >> drawsurf->surfmip) + + (tmax << SHIFT16XYZ)) % tmax) * twidth)]; + + pcolumndest = drawsurf->surfdat; + + for (u=0 ; usurfmip, drawsurf->rowbytes); + + soffset = soffset + blocksize; + if (soffset >= smax) + soffset = 0; + + pcolumndest += blocksize; + } +} + + +//============================================================================= /* ================