From 3a6bcdc10268ee7e3714a9e08bfe36a26e2d7f90 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 26 Dec 2014 17:29:48 +0000 Subject: [PATCH] engine.c: style-cleanup drawvox(). Also clean up ALL of voxmodel.c. No deliberate semantic changes here. git-svn-id: https://svn.eduke32.com/eduke32@4834 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/mdsprite.h | 19 +- polymer/eduke32/build/src/defs.c | 5 +- polymer/eduke32/build/src/engine.c | 218 +++--- polymer/eduke32/build/src/voxmodel.c | 921 +++++++++++++++-------- polymer/eduke32/source/game.c | 1 - 5 files changed, 730 insertions(+), 434 deletions(-) diff --git a/polymer/eduke32/build/include/mdsprite.h b/polymer/eduke32/build/include/mdsprite.h index 9eeb49fa9..1e5054e64 100644 --- a/polymer/eduke32/build/include/mdsprite.h +++ b/polymer/eduke32/build/include/mdsprite.h @@ -162,24 +162,29 @@ typedef struct //MD3 specific md3head_t head; vec3f_t *muladdframes; - uint16_t *indexes; - uint16_t *vindexes; - float *maxdepths; - GLuint* vbos; + + uint16_t *indexes; + uint16_t *vindexes; + + float *maxdepths; + GLuint *vbos; // polymer VBO names after that, allocated per surface - GLuint* indices; - GLuint* texcoords; - GLuint* geometry; + GLuint *indices; + GLuint *texcoords; + GLuint *geometry; } md3model_t; #define VOXBORDWIDTH 1 //use 0 to save memory, but has texture artifacts; 1 looks better... #define VOXUSECHAR 0 + #if (VOXUSECHAR != 0) typedef struct { uint8_t x, y, z, u, v; } vert_t; #else typedef struct { uint16_t x, y, z, u, v; } vert_t; #endif + typedef struct { vert_t v[4]; } voxrect_t; + typedef struct { //WARNING: This top block is a union of md2model,md3model,voxmodel: Make sure it matches! diff --git a/polymer/eduke32/build/src/defs.c b/polymer/eduke32/build/src/defs.c index a2f04120e..65a8c0ee8 100644 --- a/polymer/eduke32/build/src/defs.c +++ b/polymer/eduke32/build/src/defs.c @@ -915,7 +915,8 @@ static int32_t defsparser(scriptfile *script) { char *fn; - if (scriptfile_getstring(script,&fn)) break; //voxel filename + if (EDUKE32_PREDICT_FALSE(scriptfile_getstring(script,&fn))) + break; //voxel filename if (EDUKE32_PREDICT_FALSE(nextvoxid == MAXVOXELS)) { @@ -1428,7 +1429,7 @@ static int32_t defsparser(scriptfile *script) if (scriptfile_getbraces(script,&modelend)) break; while (script->textptr < modelend) { - switch (getatoken(script,voxeltokens,ARRAY_SIZE(voxeltokens))) + switch (getatoken(script, voxeltokens, ARRAY_SIZE(voxeltokens))) { //case T_ERROR: initprintf("Error on line %s:%d in voxel tokens\n", script->filename,linenum); break; case T_TILE: diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index f6ac94f8f..a9b049e2e 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -5245,25 +5245,17 @@ static void drawvox(int32_t dasprx, int32_t daspry, int32_t dasprz, int32_t dasp int32_t daxscale, int32_t dayscale, char daindex, int8_t dashade, char dapal, const int32_t *daumost, const int32_t *dadmost) { - int32_t i, j, k, x, y, syoff, ggxstart, ggystart, nxoff; - int32_t cosang, sinang, sprcosang, sprsinang, backx, backy, gxinc, gyinc; - int32_t daxsiz, daysiz, /*dazsiz,*/ daxpivot, daypivot, dazpivot; - int32_t daxscalerecip, dayscalerecip, cnt, gxstart, gystart, odayscale; - int32_t l1, l2, /*slabxoffs,*/ xyvoxoffs, *longptr; - intptr_t slabxoffs; - int32_t lx, rx, nx, ny, x1=0, y1=0, z1, x2=0, y2=0, z2, yplc, yinc=0; - int32_t yoff, xs=0, ys=0, xe, ye, xi=0, yi=0, cbackx, cbacky, dagxinc, dagyinc; - int16_t *shortptr; - char *voxptr, *voxend, *davoxptr, oand, oand16, oand32; + int32_t i, j, k, x, y; - cosang = sintable[(globalang+512)&2047]; - sinang = sintable[globalang&2047]; - sprcosang = sintable[(dasprang+512)&2047]; - sprsinang = sintable[dasprang&2047]; + int32_t cosang = sintable[(globalang+512)&2047]; + int32_t sinang = sintable[globalang&2047]; + int32_t sprcosang = sintable[(dasprang+512)&2047]; + int32_t sprsinang = sintable[dasprang&2047]; - i = klabs(dmulscale6(dasprx-globalposx,cosang,daspry-globalposy,sinang)); + i = klabs(dmulscale6(dasprx-globalposx, cosang, daspry-globalposy, sinang)); j = getpalookup(mulscale21(globvis,i), dashade)<<8; - setupdrawslab(ylookup[1],FP_OFF(palookup[dapal])+j); + setupdrawslab(ylookup[1], FP_OFF(palookup[dapal])+j); + j = 1310720; j *= min(daxscale,dayscale); j >>= 6; //New hacks (for sized-down voxels) for (k=0; k= MAXVOXMIPS) i = MAXVOXMIPS-1; + if (k >= MAXVOXMIPS) + i = MAXVOXMIPS-1; - if (novoxmips) i = 0; - davoxptr = (char *)voxoff[daindex][i]; + if (novoxmips) + i = 0; + + char *davoxptr = (char *)voxoff[daindex][i]; if (!davoxptr && i > 0) { davoxptr = (char *)voxoff[daindex][0]; i = 0; } - if (!davoxptr) return; + if (!davoxptr) + return; if (voxscale[daindex] == 65536) { daxscale <<= (i+8); dayscale <<= (i+8); } @@ -5286,39 +5282,39 @@ static void drawvox(int32_t dasprx, int32_t daspry, int32_t dasprz, int32_t dasp dayscale = mulscale8(dayscale<>8); - backy = ((dmulscale10(y,sprcosang,x,-sprsinang)+daypivot)>>8); - cbackx = min(max(backx,0),daxsiz-1); - cbacky = min(max(backy,0),daysiz-1); + x = mulscale16(globalposx-dasprx, daxscalerecip); + y = mulscale16(globalposy-daspry, daxscalerecip); + const int32_t backx = (dmulscale10(x,sprcosang, y,sprsinang)+daxpivot)>>8; + const int32_t backy = (dmulscale10(y,sprcosang, x,-sprsinang)+daypivot)>>8; + const int32_t cbackx = min(max(backx,0),daxsiz-1); + const int32_t cbacky = min(max(backy,0),daysiz-1); - sprcosang = mulscale14(daxscale,sprcosang); - sprsinang = mulscale14(daxscale,sprsinang); + sprcosang = mulscale14(daxscale, sprcosang); + sprsinang = mulscale14(daxscale, sprsinang); - x = (dasprx-globalposx) - dmulscale18(daxpivot,sprcosang,daypivot,-sprsinang); - y = (daspry-globalposy) - dmulscale18(daypivot,sprcosang,daxpivot,sprsinang); + x = (dasprx-globalposx) - dmulscale18(daxpivot,sprcosang, daypivot,-sprsinang); + y = (daspry-globalposy) - dmulscale18(daypivot,sprcosang, daxpivot,sprsinang); - cosang = mulscale16(cosang,dayscalerecip); - sinang = mulscale16(sinang,dayscalerecip); + cosang = mulscale16(cosang, dayscalerecip); + sinang = mulscale16(sinang, dayscalerecip); - gxstart = y*cosang - x*sinang; - gystart = x*cosang + y*sinang; - gxinc = dmulscale10(sprsinang,cosang,sprcosang,-sinang); - gyinc = dmulscale10(sprcosang,cosang,sprsinang,sinang); + const int32_t gxstart = y*cosang - x*sinang; + const int32_t gystart = x*cosang + y*sinang; + const int32_t gxinc = dmulscale10(sprsinang,cosang, sprcosang,-sinang); + const int32_t gyinc = dmulscale10(sprcosang,cosang, sprsinang,sinang); x = 0; y = 0; j = max(daxsiz,daysiz); for (i=0; i<=j; i++) @@ -5327,16 +5323,20 @@ static void drawvox(int32_t dasprx, int32_t daspry, int32_t dasprz, int32_t dasp ggyinc[i] = y; y += gyinc; } - if ((klabs(globalposz-dasprz)>>10) >= klabs(odayscale)) return; - syoff = divscale21(globalposz-dasprz,odayscale) + (dazpivot<<7); - yoff = ((klabs(gxinc)+klabs(gyinc))>>1); + if ((klabs(globalposz-dasprz)>>10) >= klabs(odayscale)) + return; + + const int32_t syoff = divscale21(globalposz-dasprz,odayscale) + (dazpivot<<7); + int32_t yoff = (klabs(gxinc)+klabs(gyinc))>>1; longptr = (int32_t *)davoxptr; - xyvoxoffs = ((daxsiz+1)<<2); + int32_t xyvoxoffs = (daxsiz+1)<<2; begindrawing(); //{{{ - for (cnt=0; cnt<8; cnt++) + for (int32_t cnt=0; cnt<8; cnt++) { + int32_t xs=0, ys=0, xi=0, yi=0; + switch (cnt) { case 0: @@ -5356,7 +5356,9 @@ static void drawvox(int32_t dasprx, int32_t daspry, int32_t dasprz, int32_t dasp case 7: xs = cbackx; ys = daysiz-1; xi = 2; yi = -1; break; } - xe = cbackx; ye = cbacky; + + int32_t xe = cbackx, ye = cbacky; + if (cnt < 4) { if ((xi < 0) && (xe >= xs)) continue; @@ -5373,7 +5375,9 @@ static void drawvox(int32_t dasprx, int32_t daspry, int32_t dasprz, int32_t dasp xe += xi; ye += yi; } - i = ksgn(ys-backy)+ksgn(xs-backx)*3+4; + int32_t x1=0, y1=0, z1, x2=0, y2=0, z2; + + i = ksgn(ys-backy) + ksgn(xs-backx)*3 + 4; switch (i) { case 6: @@ -5404,51 +5408,65 @@ static void drawvox(int32_t dasprx, int32_t daspry, int32_t dasprz, int32_t dasp case 3: x2 = gxinc+gyinc; y2 = gyinc-gxinc; break; } - oand = pow2char[(xs 0) { dagxinc = gxinc; dagyinc = mulscale16(gyinc,viewingrangerecip); } else { dagxinc = -gxinc; dagyinc = -mulscale16(gyinc,viewingrangerecip); } //Fix for non 90 degree viewing ranges - nxoff = mulscale16(x2-x1,viewingrangerecip); - x1 = mulscale16(x1,viewingrangerecip); + const int32_t nxoff = mulscale16(x2-x1,viewingrangerecip); + x1 = mulscale16(x1, viewingrangerecip); - ggxstart = gxstart+ggyinc[ys]; - ggystart = gystart-ggxinc[ys]; + const int32_t ggxstart = gxstart + ggyinc[ys]; + const int32_t ggystart = gystart - ggxinc[ys]; for (x=xs; x!=xe; x+=xi) { - slabxoffs = (intptr_t)&davoxptr[B_LITTLE32(longptr[x])]; - shortptr = (int16_t *)&davoxptr[((x*(daysiz+1))<<1)+xyvoxoffs]; + const intptr_t slabxoffs = (intptr_t)&davoxptr[B_LITTLE32(longptr[x])]; + int16_t *const shortptr = (int16_t *)&davoxptr[((x*(daysiz+1))<<1) + xyvoxoffs]; + + int32_t nx = mulscale16(ggxstart+ggxinc[x], viewingrangerecip) + x1; + int32_t ny = ggystart + ggyinc[x]; - nx = mulscale16(ggxstart+ggxinc[x],viewingrangerecip)+x1; - ny = ggystart+ggyinc[x]; for (y=ys; y!=ye; y+=yi,nx+=dagyinc,ny-=dagxinc) { - if ((ny <= nytooclose) || (ny >= nytoofar)) continue; - voxptr = (char *)(B_LITTLE16(shortptr[y])+slabxoffs); - voxend = (char *)(B_LITTLE16(shortptr[y+1])+slabxoffs); - if (voxptr == voxend) continue; + if (ny <= nytooclose || ny >= nytoofar) + continue; + + char *voxptr = (char *)(B_LITTLE16(shortptr[y])+slabxoffs); + char *const voxend = (char *)(B_LITTLE16(shortptr[y+1])+slabxoffs); + if (voxptr == voxend) + continue; // AMCTC V1 MEGABASE: (ny+y1)>>14 == 65547 // (after long corridor with the blinds) - lx = mulscale32(nx>>3,distrecip[(ny+y1)>>14])+halfxdimen; - if (lx < 0) lx = 0; - rx = mulscale32((nx+nxoff)>>3,distrecip[(ny+y2)>>14])+halfxdimen; - if (rx > xdimen) rx = xdimen; - if (rx <= lx) continue; + int32_t lx = mulscale32(nx>>3, distrecip[(ny+y1)>>14]) + halfxdimen; + if (lx < 0) + lx = 0; + + int32_t rx = mulscale32((nx+nxoff)>>3, distrecip[(ny+y2)>>14]) + halfxdimen; + if (rx > xdimen) + rx = xdimen; + + if (rx <= lx) + continue; + rx -= lx; - l1 = distrecip[(ny-yoff)>>14]; + const int32_t l1 = distrecip[(ny-yoff)>>14]; // FIXME! AMCTC RC2/beta shotgun voxel // (e.g. training map right after M16 shooting): - l2 = clamp((ny+yoff)>>14, 0, 65535); - l2 = distrecip[l2]; + const int32_t l2 = distrecip[clamp((ny+yoff)>>14, 0, 65536)]; + for (; voxptr= 1024) yinc = divscale16(voxptr[1],z2-z1); - else if (z2 > z1) yinc = (lowrecip[z2-z1]*voxptr[1]>>8); + if (z2-z1 >= 1024) + yinc = divscale16(voxptr[1], z2-z1); + else if (z2 > z1) + yinc = lowrecip[z2-z1]*voxptr[1]>>8; + if (z1 < daumost[lx]) { yplc = yinc*(daumost[lx]-z1); z1 = daumost[lx]; } else yplc = 0; } - if (z2 > dadmost[lx]) z2 = dadmost[lx]; - z2 -= z1; if (z2 <= 0) continue; - drawslab(rx,yplc,z2,yinc,(intptr_t)&voxptr[3],ylookup[z1]+lx+frameoffset); + if (z2 > dadmost[lx]) + z2 = dadmost[lx]; + z2 -= z1; + if (z2 <= 0) + continue; + + drawslab(rx, yplc, z2, yinc, (intptr_t)&voxptr[3], ylookup[z1]+lx+frameoffset); } } } @@ -12011,26 +12039,30 @@ void copytilepiece(int32_t tilenume1, int32_t sx1, int32_t sy1, int32_t xsiz, in // int32_t qloadkvx(int32_t voxindex, const char *filename) { - int32_t i, fil, dasiz, lengcnt, lengtot; - char *ptr; + const int32_t fil = kopen4load(filename,0); + if (fil == -1) + return -1; - if ((fil = kopen4load(filename,0)) == -1) return -1; + int32_t lengcnt = 0; + const int32_t lengtot = kfilelength(fil); - lengcnt = 0; - lengtot = kfilelength(fil); - - for (i=0; i= lengtot-768) break; + if (lengcnt >= lengtot-768) + break; } + kclose(fil); #ifdef USE_OPENGL @@ -12039,8 +12071,10 @@ int32_t qloadkvx(int32_t voxindex, const char *filename) voxfree(voxmodels[voxindex]); voxmodels[voxindex] = NULL; } + voxmodels[voxindex] = voxload(filename); #endif + return 0; } diff --git a/polymer/eduke32/build/src/voxmodel.c b/polymer/eduke32/build/src/voxmodel.c index 96a54aef4..ef2c5cb3f 100644 --- a/polymer/eduke32/build/src/voxmodel.c +++ b/polymer/eduke32/build/src/voxmodel.c @@ -17,34 +17,36 @@ #include + //For loading/conversion only static vec3_t voxsiz; static int32_t yzsiz, *vbit = 0; //vbit: 1 bit per voxel: 0=air,1=solid static vec3f_t voxpiv; + static int32_t *vcolhashead = 0, vcolhashsizm1; typedef struct { int32_t p, c, n; } voxcol_t; static voxcol_t *vcol = 0; int32_t vnum = 0, vmax = 0; + typedef struct { int16_t x, y; } spoint2d; static spoint2d *shp; static int32_t *shcntmal, *shcnt = 0, shcntp; + static int32_t mytexo5, *zbit, gmaxx, gmaxy, garea, pow2m1[33]; static voxmodel_t *gvox; + //pitch must equal xsiz*4 uint32_t gloadtex(int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, int32_t dapal) { - uint32_t rtexid; - int32_t i; - const char *const cptr = &britable[gammabrightness ? 0 : curbrightness][0]; // Correct for GL's RGB order; also apply gamma here: - const coltype *const pic = (const coltype *) picbuf; - coltype *pic2 = (coltype *) Xmalloc(xsiz*ysiz*sizeof(coltype)); + const coltype *const pic = (const coltype *)picbuf; + coltype *pic2 = (coltype *)Xmalloc(xsiz*ysiz*sizeof(coltype)); if (!is8bit) { - for (i=xsiz*ysiz-1; i>=0; i--) + for (int32_t i=xsiz*ysiz-1; i>=0; i--) { pic2[i].b = cptr[pic[i].r]; pic2[i].g = cptr[pic[i].g]; @@ -57,7 +59,7 @@ uint32_t gloadtex(int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, i if (palookup[dapal] == NULL) dapal = 0; - for (i=xsiz*ysiz-1; i>=0; i--) + for (int32_t i=xsiz*ysiz-1; i>=0; i--) { const int32_t ii = palookup[dapal][pic[i].a] * 3; @@ -68,6 +70,8 @@ uint32_t gloadtex(int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, i } } + uint32_t rtexid; + bglGenTextures(1, (GLuint *) &rtexid); bglBindTexture(GL_TEXTURE_2D, rtexid); bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -82,17 +86,25 @@ uint32_t gloadtex(int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, i static int32_t getvox(int32_t x, int32_t y, int32_t z) { z += x*yzsiz + y*voxsiz.z; + for (x=vcolhashead[(z*214013)&vcolhashsizm1]; x>=0; x=vcol[x].n) - if (vcol[x].p == z) return(vcol[x].c); - return(0x808080); + if (vcol[x].p == z) + return vcol[x].c; + + return 0x808080; } static void putvox(int32_t x, int32_t y, int32_t z, int32_t col) { - if (vnum >= vmax) { vmax = max(vmax<<1, 4096); vcol = (voxcol_t *) Xrealloc(vcol, vmax*sizeof(voxcol_t)); } + if (vnum >= vmax) + { + vmax = max(vmax<<1, 4096); + vcol = (voxcol_t *)Xrealloc(vcol, vmax*sizeof(voxcol_t)); + } z += x*yzsiz + y*voxsiz.z; - vcol[vnum].p = z; z = ((z*214013)&vcolhashsizm1); + + vcol[vnum].p = z; z = (z*214013)&vcolhashsizm1; vcol[vnum].c = col; vcol[vnum].n = vcolhashead[z]; vcolhashead[z] = vnum++; } @@ -101,9 +113,8 @@ static void putvox(int32_t x, int32_t y, int32_t z, int32_t col) #if 0 static void setzrange0(int32_t *lptr, int32_t z0, int32_t z1) { - int32_t z, ze; if (!((z0^z1)&~31)) { lptr[z0>>5] &= ((~(-1<>5); ze = (z1>>5); + int32_t z = (z0>>5), ze = (z1>>5); lptr[z] &=~(-1<>5] |= ((~(-1<>5); ze = (z1>>5); + int32_t z = (z0>>5), ze = (z1>>5); lptr[z] |= (-1<mytexx) for (x=0; x>5]&(1<>5); + dx += x0-1; + const int32_t c = (dx>>5) - (x0>>5); - i = y0*mytexo5 + (x0>>5); dx += x0-1; c = (dx>>5) - (x0>>5); - m = ~pow2m1[x0&31]; m1 = pow2m1[(dx&31)+1]; - if (!c) { for (m&=m1; dy; dy--, i+=mytexo5) if (zbit[i]&m) return(0); } + int32_t m = ~pow2m1[x0&31]; + const int32_t m1 = pow2m1[(dx&31)+1]; + + if (!c) + { + for (m &= m1; dy; dy--, i += mytexo5) + if (zbit[i]&m) + return 0; + } else { - for (; dy; dy--, i+=mytexo5) + for (; dy; dy--, i += mytexo5) { - if (zbit[i]&m) return(0); - for (x=1; xmytexx) for (x=0; x>5] |= (1<>5); + dx += x0-1; + const int32_t c = (dx>>5) - (x0>>5); - i = y0*mytexo5 + (x0>>5); dx += x0-1; c = (dx>>5) - (x0>>5); - m = ~pow2m1[x0&31]; m1 = pow2m1[(dx&31)+1]; - if (!c) { for (m&=m1; dy; dy--, i+=mytexo5) zbit[i] |= m; } + int32_t m = ~pow2m1[x0&31]; + const int32_t m1 = pow2m1[(dx&31)+1]; + + if (!c) + { + for (m &= m1; dy; dy--, i += mytexo5) + zbit[i] |= m; + } else { - for (; dy; dy--, i+=mytexo5) + for (; dy; dy--, i += mytexo5) { zbit[i] |= m; - for (x=1; x gmaxx) gmaxx = x; if (y > gmaxy) gmaxy = y; - garea += (x+(VOXBORDWIDTH<<1))*(y+(VOXBORDWIDTH<<1)); + + garea += (x+(VOXBORDWIDTH<<1)) * (y+(VOXBORDWIDTH<<1)); gvox->qcnt++; } -static void addquad(int32_t x0, int32_t y0, int32_t z0, int32_t x1, int32_t y1, int32_t z1, int32_t x2, int32_t y2, int32_t z2, int32_t face) +static void addquad(int32_t x0, int32_t y0, int32_t z0, int32_t x1, int32_t y1, int32_t z1, + int32_t x2, int32_t y2, int32_t z2, int32_t face) { - int32_t i, j, x, y, z, xx, yy, nx = 0, ny = 0, nz = 0, *lptr; - voxrect_t *qptr; + int32_t i; + int32_t x = labs(x2-x0), y = labs(y2-y0), z = labs(z2-z0); - x = labs(x2-x0); y = labs(y2-y0); z = labs(z2-z0); - if (!x) { x = y; y = z; i = 0; } - else if (!y) { y = z; i = 1; } + if (x == 0) { x = y; y = z; i = 0; } + else if (y == 0) { y = z; i = 1; } else i = 2; + if (x < y) { z = x; x = y; y = z; i += 3; } + z = shcnt[y*shcntp+x]++; - lptr = &gvox->mytex[(shp[z].y+VOXBORDWIDTH)*gvox->mytexx+(shp[z].x+VOXBORDWIDTH)]; + int32_t *lptr = &gvox->mytex[(shp[z].y+VOXBORDWIDTH)*gvox->mytexx + + (shp[z].x+VOXBORDWIDTH)]; + int32_t nx = 0, ny = 0, nz = 0; + switch (face) { case 0: @@ -215,192 +263,273 @@ static void addquad(int32_t x0, int32_t y0, int32_t z0, int32_t x1, int32_t y1, case 5: nx = x0; break; } - for (yy=0; yymytexx) - for (xx=0; xxmytexx) + for (int32_t xx=0; xxmytex[(shp[z].y+yy)*gvox->mytexx+shp[z].x]; - lptr[xx] = lptr[VOXBORDWIDTH]; lptr[xx+x+VOXBORDWIDTH] = lptr[x-1+VOXBORDWIDTH]; + lptr = &gvox->mytex[(shp[z].y+yy)*gvox->mytexx + shp[z].x]; + lptr[xx] = lptr[VOXBORDWIDTH]; + lptr[xx+x+VOXBORDWIDTH] = lptr[x-1+VOXBORDWIDTH]; } + //Extend borders vertically - for (yy=0; yymytex[(shp[z].y+yy)*gvox->mytexx+shp[z].x], - &gvox->mytex[(shp[z].y+VOXBORDWIDTH)*gvox->mytexx+shp[z].x], - (x+(VOXBORDWIDTH<<1))<<2); - Bmemcpy(&gvox->mytex[(shp[z].y+y+yy+VOXBORDWIDTH)*gvox->mytexx+shp[z].x], - &gvox->mytex[(shp[z].y+y-1+VOXBORDWIDTH)*gvox->mytexx+shp[z].x], - (x+(VOXBORDWIDTH<<1))<<2); + Bmemcpy(&gvox->mytex[(shp[z].y+yy)*gvox->mytexx + shp[z].x], + &gvox->mytex[(shp[z].y+VOXBORDWIDTH)*gvox->mytexx + shp[z].x], + (x+(VOXBORDWIDTH<<1))<<2); + Bmemcpy(&gvox->mytex[(shp[z].y+y+yy+VOXBORDWIDTH)*gvox->mytexx + shp[z].x], + &gvox->mytex[(shp[z].y+y-1+VOXBORDWIDTH)*gvox->mytexx + shp[z].x], + (x+(VOXBORDWIDTH<<1))<<2); } - qptr = &gvox->quad[gvox->qcnt]; + voxrect_t *const qptr = &gvox->quad[gvox->qcnt]; + qptr->v[0].x = x0; qptr->v[0].y = y0; qptr->v[0].z = z0; qptr->v[1].x = x1; qptr->v[1].y = y1; qptr->v[1].z = z1; qptr->v[2].x = x2; qptr->v[2].y = y2; qptr->v[2].z = z2; - for (j=0; j<3; j++) { qptr->v[j].u = shp[z].x+VOXBORDWIDTH; qptr->v[j].v = shp[z].y+VOXBORDWIDTH; } - if (i < 3) qptr->v[1].u += x; else qptr->v[1].v += y; - qptr->v[2].u += x; qptr->v[2].v += y; + + for (int32_t j=0; j<3; j++) + { + qptr->v[j].u = shp[z].x+VOXBORDWIDTH; + qptr->v[j].v = shp[z].y+VOXBORDWIDTH; + } + + if (i < 3) + qptr->v[1].u += x; + else + qptr->v[1].v += y; + + qptr->v[2].u += x; + qptr->v[2].v += y; qptr->v[3].u = qptr->v[0].u - qptr->v[1].u + qptr->v[2].u; qptr->v[3].v = qptr->v[0].v - qptr->v[1].v + qptr->v[2].v; qptr->v[3].x = qptr->v[0].x - qptr->v[1].x + qptr->v[2].x; qptr->v[3].y = qptr->v[0].y - qptr->v[1].y + qptr->v[2].y; qptr->v[3].z = qptr->v[0].z - qptr->v[1].z + qptr->v[2].z; - if (gvox->qfacind[face] < 0) gvox->qfacind[face] = gvox->qcnt; - gvox->qcnt++; + if (gvox->qfacind[face] < 0) + gvox->qfacind[face] = gvox->qcnt; + + gvox->qcnt++; } static inline int32_t isolid(int32_t x, int32_t y, int32_t z) { - if ((uint32_t) x >= (uint32_t) voxsiz.x) return(0); - if ((uint32_t) y >= (uint32_t) voxsiz.y) return(0); - if ((uint32_t) z >= (uint32_t) voxsiz.z) return(0); - z += x*yzsiz + y*voxsiz.z; return(vbit[z>>5]&(1<= (uint32_t)voxsiz.x) return 0; + if ((uint32_t)y >= (uint32_t)voxsiz.y) return 0; + if ((uint32_t)z >= (uint32_t)voxsiz.z) return 0; + + z += x*yzsiz + y*voxsiz.z; + + return vbit[z>>5] & (1<>5] & (1<qfacind[i] = -1; - - i = ((max(voxsiz.y, voxsiz.z)+1)<<2); - bx0 = (int32_t *) Xmalloc(i<<1); - by0 = (int32_t *) (((intptr_t) bx0)+i); - - for (cnt=0; cnt<2; cnt++) + if (pow2m1[32] != -1) { - if (!cnt) daquad = cntquad; - else daquad = addquad; + for (i=0; i<32; i++) + pow2m1[i] = (1u<qfacind[i] = -1; + + i = (max(voxsiz.y, voxsiz.z)+1)<<2; + int32_t *const bx0 = (int32_t *)Xmalloc(i<<1); + int32_t *const by0 = (int32_t *)(((intptr_t)bx0)+i); + + int32_t ov, oz=0; + + for (int32_t cnt=0; cnt<2; cnt++) + { + void (*daquad)(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t) = + cnt == 0 ? cntquad : addquad; + gvox->qcnt = 0; - memset(by0, -1, (max(voxsiz.y, voxsiz.z)+1)<<2); v = 0; + memset(by0, -1, (max(voxsiz.y, voxsiz.z)+1)<<2); + int32_t v = 0; for (i=-1; i<=1; i+=2) - for (y=0; y= 0) && ((by0[z] != oz) || (v >= ov))) - { - daquad(bx0[z], y, by0[z], x, y, by0[z], x, y, z, i>=0); by0[z] = -1; - } - if (v > ov) oz = z; else if ((v < ov) && (by0[z] != oz)) { bx0[z] = x; by0[z] = oz; } + ov = v; v = (isolid(x, y, z) && (!isolid(x, y+i, z))); + if ((by0[z] >= 0) && ((by0[z] != oz) || (v >= ov))) + { + daquad(bx0[z], y, by0[z], x, y, by0[z], x, y, z, i>=0); + by0[z] = -1; + } + + if (v > ov) oz = z; + else if ((v < ov) && (by0[z] != oz)) { bx0[z] = x; by0[z] = oz; } } for (i=-1; i<=1; i+=2) - for (z=0; z= 0) && ((by0[y] != oz) || (v >= ov))) - { - daquad(bx0[y], by0[y], z, x, by0[y], z, x, y, z, (i>=0)+2); by0[y] = -1; - } - if (v > ov) oz = y; else if ((v < ov) && (by0[y] != oz)) { bx0[y] = x; by0[y] = oz; } + ov = v; v = (isolid(x, y, z) && (!isolid(x, y, z-i))); + if ((by0[y] >= 0) && ((by0[y] != oz) || (v >= ov))) + { + daquad(bx0[y], by0[y], z, x, by0[y], z, x, y, z, (i>=0)+2); + by0[y] = -1; + } + + if (v > ov) oz = y; + else if ((v < ov) && (by0[y] != oz)) { bx0[y] = x; by0[y] = oz; } } for (i=-1; i<=1; i+=2) - for (x=0; x= 0) && ((by0[z] != oz) || (v >= ov))) - { - daquad(x, bx0[z], by0[z], x, y, by0[z], x, y, z, (i>=0)+4); by0[z] = -1; - } - if (v > ov) oz = z; else if ((v < ov) && (by0[z] != oz)) { bx0[z] = y; by0[z] = oz; } + ov = v; v = (isolid(x, y, z) && (!isolid(x-i, y, z))); + if ((by0[z] >= 0) && ((by0[z] != oz) || (v >= ov))) + { + daquad(x, bx0[z], by0[z], x, y, by0[z], x, y, z, (i>=0)+4); + by0[z] = -1; + } + + if (v > ov) oz = z; + else if ((v < ov) && (by0[z] != oz)) { bx0[z] = y; by0[z] = oz; } } if (!cnt) { - shp = (spoint2d *) Xmalloc(gvox->qcnt*sizeof(spoint2d)); + shp = (spoint2d *)Xmalloc(gvox->qcnt*sizeof(spoint2d)); - sc = 0; - for (y=gmaxy; y; y--) - for (x=gmaxx; x>=y; x--) + int32_t sc = 0; + + for (int32_t y=gmaxy; y; y--) + for (int32_t x=gmaxx; x>=y; x--) { - i = shcnt[y*shcntp+x]; shcnt[y*shcntp+x] = sc; //shcnt changes from counter to head index - for (; i>0; i--) { shp[sc].x = x; shp[sc].y = y; sc++; } + i = shcnt[y*shcntp+x]; shcnt[y*shcntp+x] = sc; //shcnt changes from counter to head index + + for (; i>0; i--) + { + shp[sc].x = x; + shp[sc].y = y; + sc++; + } } - for (gvox->mytexx=32; gvox->mytexx<(gmaxx+(VOXBORDWIDTH<<1)); gvox->mytexx<<=1); - for (gvox->mytexy=32; gvox->mytexy<(gmaxy+(VOXBORDWIDTH<<1)); gvox->mytexy<<=1); + for (gvox->mytexx=32; gvox->mytexx<(gmaxx+(VOXBORDWIDTH<<1)); gvox->mytexx<<=1) + /* do nothing */; + + for (gvox->mytexy=32; gvox->mytexy<(gmaxy+(VOXBORDWIDTH<<1)); gvox->mytexy<<=1) + /* do_nothing */; + while (gvox->mytexx*gvox->mytexy*8 < garea*9) //This should be sufficient to fit most skins... { - skindidntfit: - ; - if (gvox->mytexx <= gvox->mytexy) gvox->mytexx <<= 1; else gvox->mytexy <<= 1; +skindidntfit: + if (gvox->mytexx <= gvox->mytexy) + gvox->mytexx <<= 1; + else + gvox->mytexy <<= 1; } - mytexo5 = (gvox->mytexx>>5); - i = (((gvox->mytexx*gvox->mytexy+31)>>5)<<2); - zbit = (int32_t *) Xmalloc(i); + mytexo5 = gvox->mytexx>>5; + + i = ((gvox->mytexx*gvox->mytexy+31)>>5)<<2; + zbit = (int32_t *)Xmalloc(i); memset(zbit, 0, i); v = gvox->mytexx*gvox->mytexy; - for (z=0; zmytexx, 255)-dx))>>15); - y0 = (((rand()&32767)*(min(gvox->mytexy, 255)-dy))>>15); + x0 = ((rand()&32767)*(min(gvox->mytexx, 255)-dx))>>15; + y0 = ((rand()&32767)*(min(gvox->mytexy, 255)-dy))>>15; #else - x0 = (((rand()&32767)*(gvox->mytexx+1-dx))>>15); - y0 = (((rand()&32767)*(gvox->mytexy+1-dy))>>15); + x0 = ((rand()&32767)*(gvox->mytexx+1-dx))>>15; + y0 = ((rand()&32767)*(gvox->mytexy+1-dy))>>15; #endif i--; if (i < 0) //Time-out! Very slow if this happens... but at least it still works :P @@ -409,111 +538,163 @@ static voxmodel_t *vox2poly() //Re-generate shp[].x/y (box sizes) from shcnt (now head indices) for next pass :/ j = 0; - for (y=gmaxy; y; y--) - for (x=gmaxx; x>=y; x--) + + for (int32_t y=gmaxy; y; y--) + for (int32_t x=gmaxx; x>=y; x--) { - i = shcnt[y*shcntp+x]; - for (; jquad = (voxrect_t *) Xmalloc(gvox->qcnt*sizeof(voxrect_t)); - gvox->mytex = (int32_t *) Xmalloc(gvox->mytexx*gvox->mytexy*sizeof(int32_t)); + gvox->quad = (voxrect_t *)Xmalloc(gvox->qcnt*sizeof(voxrect_t)); + gvox->mytex = (int32_t *)Xmalloc(gvox->mytexx*gvox->mytexy*sizeof(int32_t)); } } + Bfree(shp); Bfree(zbit); Bfree(bx0); + return(gvox); } +static void alloc_vcolhashead(void) +{ + vcolhashead = (int32_t *)Xmalloc((vcolhashsizm1+1)*sizeof(int32_t)); + memset(vcolhashead, -1, (vcolhashsizm1+1)*sizeof(int32_t)); +} + +static void alloc_vbit(void) +{ + yzsiz = voxsiz.y*voxsiz.z; + int32_t i = ((voxsiz.x*yzsiz+31)>>3)+1; + + vbit = (int32_t *)Xmalloc(i); + memset(vbit, 0, i); +} + +static void read_pal(int32_t fil, int32_t pal[256]) +{ + klseek(fil, -768, SEEK_END); + + for (int32_t i=0; i<256; i++) + { + char c[3]; + kread(fil, c, 3); +//#if B_BIG_ENDIAN != 0 + pal[i] = B_LITTLE32((c[0]<<18) + (c[1]<<10) + (c[2]<<2) + (i<<24)); +//#endif + } +} + static int32_t loadvox(const char *filnam) { - int32_t i, j, k, x, y, z, pal[256], fil; - char c[3], *tbuf; + const int32_t fil = kopen4load(filnam, 0); + if (fil < 0) + return -1; - fil = kopen4load(filnam, 0); if (fil < 0) return(-1); kread(fil, &voxsiz, sizeof(vec3_t)); #if B_BIG_ENDIAN != 0 voxsiz.x = B_LITTLE32(voxsiz.x); voxsiz.y = B_LITTLE32(voxsiz.y); voxsiz.z = B_LITTLE32(voxsiz.z); #endif - voxpiv.x = (float) voxsiz.x * .5f; - voxpiv.y = (float) voxsiz.y * .5f; - voxpiv.z = (float) voxsiz.z * .5f; + voxpiv.x = (float)voxsiz.x * .5f; + voxpiv.y = (float)voxsiz.y * .5f; + voxpiv.z = (float)voxsiz.z * .5f; - klseek(fil, -768, SEEK_END); - for (i=0; i<256; i++) - { - kread(fil, c, 3); pal[i] = (((int32_t) c[0])<<18)+(((int32_t) c[1])<<10)+(((int32_t) c[2])<<2)+(i<<24); - } + int32_t pal[256]; + read_pal(fil, pal); pal[255] = -1; vcolhashsizm1 = 8192-1; - vcolhashead = (int32_t *) Xmalloc((vcolhashsizm1+1)*sizeof(int32_t)); - memset(vcolhashead, -1, (vcolhashsizm1+1)*sizeof(int32_t)); + alloc_vcolhashead(); + alloc_vbit(); - yzsiz = voxsiz.y*voxsiz.z; i = ((voxsiz.x*yzsiz+31)>>3)+1; - vbit = (int32_t *) Xmalloc(i); - memset(vbit, 0, i); - - tbuf = (char *) Xmalloc(voxsiz.z*sizeof(uint8_t)); + char *const tbuf = (char *)Xmalloc(voxsiz.z*sizeof(uint8_t)); klseek(fil, 12, SEEK_SET); - for (x=0; x=0; z--) - { - if (tbuf[z] != 255) { i = j+z; vbit[i>>5] |= (1<=0; z--) + if (tbuf[z] != 255) + { + const int32_t i = j+z; + vbit[i>>5] |= (1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<>5]&(1<=0; i--) xyoffs[i] = B_LITTLE16(xyoffs[i]); - klseek(fil, -768, SEEK_END); - for (i=0; i<256; i++) - { - kread(fil, c, 3); -//#if B_BIG_ENDIAN != 0 - pal[i] = B_LITTLE32((((int32_t) c[0])<<18)+(((int32_t) c[1])<<10)+(((int32_t) c[2])<<2)+(i<<24)); -//#endif - } + uint16_t *xyoffs = (uint16_t *)Xmalloc(i); + kread(fil, xyoffs, i); - yzsiz = voxsiz.y*voxsiz.z; i = ((voxsiz.x*yzsiz+31)>>3)+1; - vbit = (int32_t *) Xmalloc(i); - memset(vbit, 0, i); + for (i=i/sizeof(int16_t)-1; i>=0; i--) + xyoffs[i] = B_LITTLE16(xyoffs[i]); + + int32_t pal[256]; + read_pal(fil, pal); + + alloc_vbit(); for (vcolhashsizm1=4096; vcolhashsizm1<(mip1leng>>1); vcolhashsizm1<<=1) { /* do nothing */ } vcolhashsizm1--; //approx to numvoxs! - vcolhashead = (int32_t *) Xmalloc((vcolhashsizm1+1)*sizeof(int32_t)); - memset(vcolhashead, -1, (vcolhashsizm1+1)*sizeof(int32_t)); + alloc_vcolhashead(); klseek(fil, 28+((voxsiz.x+1)<<2)+((ysizp1*voxsiz.x)<<1), SEEK_SET); i = kfilelength(fil)-ktell(fil); - tbuf = (char *) Xmalloc(i); - kread(fil, tbuf, i); kclose(fil); + char *const tbuf = (char *)Xmalloc(i); - cptr = tbuf; - for (x=0; x=0; i--) ylen[i] = B_LITTLE16(ylen[i]); + kread(fil, ylen, voxsiz.x*voxsiz.y*sizeof(int16_t)); + for (i=voxsiz.x*voxsiz.y-1; i>=0; i--) + ylen[i] = B_LITTLE16(ylen[i]); + klseek(fil, 32, SEEK_SET); - yzsiz = voxsiz.y*voxsiz.z; i = ((voxsiz.x*yzsiz+31)>>3)+1; - vbit = (int32_t *) Xmalloc(i); - memset(vbit, 0, i); + alloc_vbit(); for (vcolhashsizm1=4096; vcolhashsizm10; i--) - { - kread(fil, c, 8); //b,g,r,a,z_lo,z_hi,vis,dir - z0 = B_LITTLE16(*(uint16_t *) &c[4]); - if (!(c[6]&16)) setzrange1(vbit, j+z1, j+z0); - vbit[(j+z0)>>5] |= (1<0; i--) + { + char c[8]; + kread(fil, c, 8); //b,g,r,a,z_lo,z_hi,vis,dir + + const int32_t z0 = B_LITTLE16(*(uint16_t *)&c[4]); + + if (!(c[6]&16)) + setzrange1(vbit, j+z1, j+z0); + + vbit[(j+z0)>>5] |= (1<mytex); DO_FREE_AND_NULL(m->quad); DO_FREE_AND_NULL(m->texid); + Bfree(m); } voxmodel_t *voxload(const char *filnam) { - int32_t i, is8bit, ret; - voxmodel_t *vm; + int32_t is8bit, ret; + + const int32_t i = Bstrlen(filnam)-4; + if (i < 0) + return NULL; - i = strlen(filnam)-4; if (i < 0) return NULL; if (!Bstrcasecmp(&filnam[i], ".vox")) { ret = loadvox(filnam); is8bit = 1; } else if (!Bstrcasecmp(&filnam[i], ".kvx")) { ret = loadkvx(filnam); is8bit = 1; } else if (!Bstrcasecmp(&filnam[i], ".kv6")) { ret = loadkv6(filnam); is8bit = 0; } //else if (!Bstrcasecmp(&filnam[i],".vxl")) { ret = loadvxl(filnam); is8bit = 0; } else return NULL; - if (ret >= 0) vm = vox2poly(); else vm = 0; + + voxmodel_t *const vm = (ret >= 0) ? vox2poly() : NULL; + if (vm) { vm->mdnum = 1; //VOXel model id @@ -660,8 +882,9 @@ voxmodel_t *voxload(const char *filnam) vm->piv.x = voxpiv.x; vm->piv.y = voxpiv.y; vm->piv.z = voxpiv.z; vm->is8bit = is8bit; - vm->texid = (uint32_t *) Xcalloc(MAXPALOOKUPS, sizeof(uint32_t)); + vm->texid = (uint32_t *)Xcalloc(MAXPALOOKUPS, sizeof(uint32_t)); } + DO_FREE_AND_NULL(shcntmal); DO_FREE_AND_NULL(vbit); DO_FREE_AND_NULL(vcol); @@ -674,22 +897,19 @@ voxmodel_t *voxload(const char *filnam) //Draw voxel model as perfect cubes int32_t polymost_voxdraw(voxmodel_t *m, const spritetype *tspr) { - vec3f_t m0, a0; - int32_t i, j, fi, xx, yy, zz; - float ru, rv, phack[2]; //, clut[6] = {1.02,1.02,0.94,1.06,0.98,0.98}; - float f, g, k0, mat[16], omat[16], pc[4]; - vert_t *vptr; + // float clut[6] = {1.02,1.02,0.94,1.06,0.98,0.98}; + float f, g, k0; - if ((intptr_t) m == (intptr_t) (-1)) // hackhackhack + if ((intptr_t)m == (intptr_t)(-1)) // hackhackhack + return 0; + + if ((tspr->cstat&48)==32) return 0; - if ((tspr->cstat&48)==32) return 0; //updateanimation((md2model *)m,tspr); - m0.x = m->scale; - m0.y = m->scale; - m0.z = m->scale; - a0.x = a0.y = 0; a0.z = ((globalorientation&8) ? -m->zadd : m->zadd)*m->scale; + vec3f_t m0 = { m->scale, m->scale, m->scale }; + vec3f_t a0 = { 0, 0, ((globalorientation&8) ? -m->zadd : m->zadd)*m->scale }; //if (globalorientation&8) //y-flipping //{ @@ -712,88 +932,124 @@ int32_t polymost_voxdraw(voxmodel_t *m, const spritetype *tspr) k0 = (float) tspr->z; if (globalorientation&128) k0 += (float) ((tilesiz[tspr->picnum].y*tspr->yrepeat)<<1); - f = (65536.f*512.f)/((float) xdimen*viewingrange); - g = 32.f/((float) xdimen*gxyaspect); - m0.y *= f; a0.y = (((float) (tspr->x-globalposx))* (1.f/1024.f) + a0.y)*f; - m0.x *=-f; a0.x = (((float) (tspr->y-globalposy))* -(1.f/1024.f) + a0.x)*-f; - m0.z *= g; a0.z = (((float) (k0 -globalposz))* -(1.f/16384.f) + a0.z)*g; + f = (65536.f*512.f) / ((float)xdimen*viewingrange); + g = 32.f / ((float)xdimen*gxyaspect); + m0.y *= f; a0.y = (((float)(tspr->x-globalposx)) * (1.f/1024.f) + a0.y) * f; + m0.x *=-f; a0.x = (((float)(tspr->y-globalposy)) * -(1.f/1024.f) + a0.x) * -f; + m0.z *= g; a0.z = (((float)(k0 -globalposz)) * -(1.f/16384.f) + a0.z) * g; + + float mat[16]; md3_vox_calcmat_common(tspr, &a0, f, mat); //Mirrors - if (grhalfxdown10x < 0) { mat[0] = -mat[0]; mat[4] = -mat[4]; mat[8] = -mat[8]; mat[12] = -mat[12]; } + if (grhalfxdown10x < 0) + { + mat[0] = -mat[0]; + mat[4] = -mat[4]; + mat[8] = -mat[8]; + mat[12] = -mat[12]; + } if (tspr->cstat&CSTAT_SPRITE_MDHACK) { bglDepthFunc(GL_LESS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS bglDepthRange(0.0, 0.9999); } + bglPushAttrib(GL_POLYGON_BIT); - if ((grhalfxdown10x >= 0) /*^ ((globalorientation&8) != 0) ^ ((globalorientation&4) != 0)*/) bglFrontFace(GL_CW); else bglFrontFace(GL_CCW); + if ((grhalfxdown10x >= 0) /*^ ((globalorientation&8) != 0) ^ ((globalorientation&4) != 0)*/) + bglFrontFace(GL_CW); + else + bglFrontFace(GL_CCW); + bglEnable(GL_CULL_FACE); bglCullFace(GL_BACK); bglEnable(GL_TEXTURE_2D); - pc[0] = pc[1] = pc[2] = ((float) (numshades-min(max((globalshade * shadescale)+m->shadeoff, 0), numshades)))/((float) numshades); + float pc[4]; + + pc[0] = pc[1] = pc[2] = + (float)(numshades-min(max((globalshade * shadescale)+m->shadeoff, 0), numshades)) / (float)numshades; hictinting_apply(pc, globalpal); - if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66f; else pc[3] = 0.33f; } - else pc[3] = 1.0f; + if (tspr->cstat&2) + pc[3] = !(tspr->cstat&512) ? 0.66f : 0.33f; + else + pc[3] = 1.0f; + pc[3] *= 1.0f - spriteext[tspr->owner].alpha; - if ((tspr->cstat&2) || spriteext[tspr->owner].alpha > 0.f || pc[3] < 1.0f) bglEnable(GL_BLEND); //else bglDisable(GL_BLEND); + + if ((tspr->cstat&2) || spriteext[tspr->owner].alpha > 0.f || pc[3] < 1.0f) + bglEnable(GL_BLEND); //else bglDisable(GL_BLEND); //------------ //transform to Build coords + float omat[16]; Bmemcpy(omat, mat, sizeof(omat)); + f = 1.f/64.f; g = m0.x*f; mat[0] *= g; mat[1] *= g; mat[2] *= g; g = m0.y*f; mat[4] = omat[8]*g; mat[5] = omat[9]*g; mat[6] = omat[10]*g; g =-m0.z*f; mat[8] = omat[4]*g; mat[9] = omat[5]*g; mat[10] = omat[6]*g; + // mat[12] -= (m->piv.x*mat[0] + m->piv.y*mat[4] + (m->piv.z+m->siz.z*.5f)*mat[8]); mat[13] -= (m->piv.x*mat[1] + m->piv.y*mat[5] + (m->piv.z+m->siz.z*.5f)*mat[9]); mat[14] -= (m->piv.x*mat[2] + m->piv.y*mat[6] + (m->piv.z+m->siz.z*.5f)*mat[10]); + // bglMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; bglLoadMatrixf(mat); - ru = 1.f/((float) m->mytexx); - rv = 1.f/((float) m->mytexy); + const float ru = 1.f/((float)m->mytexx); + const float rv = 1.f/((float)m->mytexy); #if (VOXBORDWIDTH == 0) uhack[0] = ru*.125; uhack[1] = -uhack[0]; vhack[0] = rv*.125; vhack[1] = -vhack[0]; #endif - phack[0] = 0; phack[1] = 1.f/256.f; + const float phack[2] = { 0, 1.f/256.f }; - if (!m->texid[globalpal]) m->texid[globalpal] = gloadtex(m->mytex, m->mytexx, m->mytexy, m->is8bit, globalpal); - else bglBindTexture(GL_TEXTURE_2D, m->texid[globalpal]); - bglBegin(GL_QUADS); - for (i=0, fi=0; iqcnt; i++) + if (!m->texid[globalpal]) + m->texid[globalpal] = gloadtex(m->mytex, m->mytexx, m->mytexy, m->is8bit, globalpal); + else + bglBindTexture(GL_TEXTURE_2D, m->texid[globalpal]); + + bglBegin(GL_QUADS); // {{{ + + for (int32_t i=0, fi=0; iqcnt; i++) { - if (i == m->qfacind[fi]) { f = 1 /*clut[fi++]*/; bglColor4f(pc[0]*f, pc[1]*f, pc[2]*f, pc[3]*f); } - vptr = &m->quad[i].v[0]; + if (i == m->qfacind[fi]) + { + f = 1 /*clut[fi++]*/; + bglColor4f(pc[0]*f, pc[1]*f, pc[2]*f, pc[3]*f); + } - xx = vptr[0].x+vptr[2].x; - yy = vptr[0].y+vptr[2].y; - zz = vptr[0].z+vptr[2].z; + const vert_t *const vptr = &m->quad[i].v[0]; - for (j=0; j<4; j++) + const int32_t xx = vptr[0].x + vptr[2].x; + const int32_t yy = vptr[0].y + vptr[2].y; + const int32_t zz = vptr[0].z + vptr[2].z; + + for (int32_t j=0; j<4; j++) { vec3f_t fp; #if (VOXBORDWIDTH == 0) - bglTexCoord2f(((float) vptr[j].u)*ru+uhack[vptr[j].u!=vptr[0].u], - ((float) vptr[j].v)*rv+vhack[vptr[j].v!=vptr[0].v]); + bglTexCoord2f(((float)vptr[j].u)*ru + uhack[vptr[j].u!=vptr[0].u], + ((float)vptr[j].v)*rv + vhack[vptr[j].v!=vptr[0].v]); #else - bglTexCoord2f(((float) vptr[j].u)*ru, ((float) vptr[j].v)*rv); + bglTexCoord2f(((float)vptr[j].u)*ru, ((float)vptr[j].v)*rv); #endif - fp.x = ((float) vptr[j].x) - phack[xx>vptr[j].x*2] + phack[xxvptr[j].y*2] + phack[yyvptr[j].z*2] + phack[zzvptr[j].x*2] + phack[xxvptr[j].y*2] + phack[yyvptr[j].z*2] + phack[zzgm & (MODE_MENU|MODE_DEMO))) && totalclock >= ototalclock+TICSPERFRAME); - } G_DoCheats();