diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 083e8a462..97a4febe2 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -664,7 +664,6 @@ set (PCH_SOURCES #thirdparty/imgui/imgui_widgets.cpp # Todo: Split out the license-safe code from this. - build/src/a-c.cpp build/src/animvpx.cpp build/src/clip.cpp build/src/common.cpp diff --git a/source/blood/src/screen.cpp b/source/blood/src/screen.cpp index 8f81d2b75..b088fe641 100644 --- a/source/blood/src/screen.cpp +++ b/source/blood/src/screen.cpp @@ -23,7 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "ns.h" // Must come before everything else! #include -#include "a.h" #include "build.h" #include "common_game.h" diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index cabe1c3a2..c1a524e20 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include "compat.h" -#include "a.h" #include "build.h" #include "pragmas.h" #include "mmulti.h" diff --git a/source/build/include/baselayer.h b/source/build/include/baselayer.h index 5c354ff6e..3226fed25 100644 --- a/source/build/include/baselayer.h +++ b/source/build/include/baselayer.h @@ -30,8 +30,6 @@ extern int32_t xres, yres, bpp, bytesperline, refreshfreq; extern intptr_t frameplace; extern char offscreenrendering; -void calc_ylookup(int32_t bpl, int32_t lastyidx); - int32_t videoCheckMode(int32_t *x, int32_t *y, int32_t c, int32_t fs, int32_t forced); int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs); void videoGetModes(void); diff --git a/source/build/include/build.h b/source/build/include/build.h index 866ac306c..ef9aed751 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -29,6 +29,8 @@ static_assert('\xff' == 255, "Char must be unsigned!"); #include "textures.h" #include "c_cvars.h" +typedef int64_t coord_t; + enum rendmode_t { REND_CLASSIC, REND_POLYMOST = 3, @@ -494,7 +496,6 @@ EXTERN tspriteptr_t tspriteptr[MAXSPRITESONSCREEN + 1]; EXTERN int32_t wx1, wy1, wx2, wy2; EXTERN int32_t xdim, ydim, numpages, upscalefactor; EXTERN int32_t yxaspect, viewingrange; -EXTERN TArray ylookup; EXTERN int32_t rotatesprite_y_offset; EXTERN int32_t rotatesprite_yxaspect; diff --git a/source/build/include/palette.h b/source/build/include/palette.h index d8f7aea16..1ed4ab448 100644 --- a/source/build/include/palette.h +++ b/source/build/include/palette.h @@ -90,7 +90,6 @@ extern uint32_t g_lastpalettesum; extern palette_t paletteGetColor(int32_t col); extern void paletteLoadFromDisk(void); extern void palettePostLoadTables(void); -extern void setup_blend(int32_t blend, int32_t doreverse); extern uint8_t basepalreset; extern int32_t curbrightness; diff --git a/source/build/src/a-c.cpp b/source/build/src/a-c.cpp index 887ddcab8..f37ea3ec4 100644 --- a/source/build/src/a-c.cpp +++ b/source/build/src/a-c.cpp @@ -10,7 +10,6 @@ // by Jonathon Fowler (jf@jonof.id.au) // by the EDuke32 team (development@voidpoint.com) -#include "a.h" #include "pragmas.h" #ifdef ENGINE_USING_A_C diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index 476681286..4c2072f04 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -6,7 +6,6 @@ // by Jonathon Fowler (jf@jonof.id.au) // by the EDuke32 team (development@voidpoint.com) -#include "a.h" #include "build.h" #include "baselayer.h" #include "clip.h" diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 8e52c4069..1646af218 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -9,7 +9,6 @@ #define engine_c_ #include "gl_load.h" -#include "a.h" #include "baselayer.h" #include "build.h" @@ -54,27 +53,6 @@ #endif #define MULTI_COLUMN_VLINE -//#define DEBUG_TILESIZY_512 -//#define DEBUG_TILEOFFSETS -////////// - -#ifdef LUNATIC -# if !defined DEBUG_MAIN_ARRAYS -LUNATIC_EXTERN const int32_t engine_main_arrays_are_static = 0; // for Lunatic -# else -LUNATIC_EXTERN const int32_t engine_main_arrays_are_static = 1; -# endif - -#if MAXSECTORS==MAXSECTORSV8 -LUNATIC_EXTERN const int32_t engine_v8 = 1; -#else -LUNATIC_EXTERN const int32_t engine_v8 = 0; -#endif -#endif - -#ifdef DEBUGGINGAIDS -float debug1, debug2; -#endif int32_t mapversion=7; // JBF 20040211: default mapversion to 7 int32_t g_loadedMapVersion = -1; // -1: none (e.g. started new) @@ -173,7 +151,6 @@ intptr_t bufplce[4]; int32_t globaltilesizy; int32_t globalx1, globaly2, globalx3, globaly3; -int32_t sloptable[SLOPTABLESIZ]; #define SLOPALOOKUPSIZ 16384 static intptr_t slopalookup[SLOPALOOKUPSIZ]; // was 2048 @@ -194,8 +171,6 @@ int32_t showfirstwall=0; int32_t showheightindicators=1; int32_t circlewall=-1; -static void classicScanSector(int16_t startsectnum); - int16_t editstatus = 0; static fix16_t global100horiz; // (-100..300)-scale horiz (the one passed to drawrooms) @@ -642,12 +617,9 @@ static void yax_scanbunches(int32_t bbeg, int32_t numhere, const uint8_t *lastgo if (checkthisec) { numscans = numbunches = 0; - if (videoGetRenderMode() == REND_CLASSIC) - classicScanSector(k); -#ifdef USE_OPENGL - else - polymost_scansector(k); -#endif + + polymost_scansector(k); + if (numbunches > 0) { bestsec = k; @@ -1489,189 +1461,6 @@ static int get_screen_coords(const vec2_t &p1, const vec2_t &p2, } -// -// scansector (internal) -// -static void classicScanSector(int16_t startsectnum) -{ - if (startsectnum < 0) - return; - - if (automapping) - show2dsector.Set(startsectnum); - - sectorborder[0] = startsectnum; - int32_t sectorbordercnt = 1; - - do - { - const int32_t sectnum = sectorborder[--sectorbordercnt]; - -#ifdef YAX_ENABLE - if (scansector_collectsprites) -#endif - for (bssize_t i=headspritesect[sectnum]; i>=0; i=nextspritesect[i]) - { - auto const spr = (uspriteptr_t)&sprite[i]; - - if (((spr->cstat & 0x8000) && !showinvisibility) || spr->xrepeat == 0 || spr->yrepeat == 0) - continue; - - vec2_t const s = { spr->x-globalposx, spr->y-globalposy }; - - if ((spr->cstat&48) || ((coord_t)s.x*cosglobalang+(coord_t)s.y*singlobalang > 0)) - if ((spr->cstat&(64+48))!=(64+16) || dmulscale6(sintable[(spr->ang+512)&2047],-s.x, sintable[spr->ang&2047],-s.y) > 0) - if (renderAddTsprite(i, sectnum)) - break; - } - - gotsector[sectnum>>3] |= pow2char[sectnum&7]; - - const int32_t onumbunches = numbunches; - const int32_t onumscans = numscans; - - const int32_t startwall = sector[sectnum].wallptr; - const int32_t endwall = startwall + sector[sectnum].wallnum; - int32_t scanfirst = numscans; - - vec2_t p1, p2 = { 0, 0 }; - - for (bssize_t w=startwall; wnextsector; - auto const wal2 = (uwallptr_t)&wall[wal->point2]; - - const int32_t x1 = wal->x-globalposx, y1 = wal->y-globalposy; - const int32_t x2 = wal2->x-globalposx, y2 = wal2->y-globalposy; - - // The following block checks for a potential collection of a - // sector that is "thin" in screen space. This is necessary because - // not all sectors that are needed to be drawn may be collected via - // drawalls() -> scansector() (although those are the majority). - // Example: standing at exactly the intersection of a large sector - // into four quadrant sub-sectors. -#if 1 - if (nextsectnum >= 0 && (wal->cstat&32) == 0 && sectorbordercnt < ARRAY_SSIZE(sectorborder)) -#ifdef YAX_ENABLE - if (yax_nomaskpass==0 || !yax_isislandwall(w, !yax_globalcf) || (yax_nomaskdidit=1, 0)) -#endif - if ((gotsector[nextsectnum>>3]&pow2char[nextsectnum&7]) == 0) - { - // OV: E2L10 - coord_t temp = (coord_t)x1*y2-(coord_t)x2*y1; - int32_t tempint = temp; - if (((uint64_t)tempint+262144) < 524288) // BXY_MAX? - if (mulscale5(tempint,tempint) <= (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) - { - sectorborder[sectorbordercnt++] = nextsectnum; - gotsector[nextsectnum>>3] |= pow2char[nextsectnum&7]; - } - } -#endif - p1 = (w == startwall || wall[w - 1].point2 != w) ? get_rel_coords(x1, y1) : p2; - p2 = get_rel_coords(x2, y2); - - if (p1.y < 256 && p2.y < 256) - goto skipitaddwall; - - // If wall's NOT facing you - if (dmulscale32(p1.x, p2.y, -p2.x, p1.y) >= 0) - goto skipitaddwall; - - if (numscans >= MAXWALLSB-1) - { - OSD_Printf("!!numscans\n"); - return; - } - - if (get_screen_coords(p1, p2, &xb1[numscans], &yb1[numscans], &xb2[numscans], &yb2[numscans])) - { - // Made it all the way! - thesector[numscans] = sectnum; thewall[numscans] = w; - rx1[numscans] = p1.x; ry1[numscans] = p1.y; - rx2[numscans] = p2.x; ry2[numscans] = p2.y; - bunchp2[numscans] = numscans+1; - numscans++; - } - -skipitaddwall: - if (wall[w].point2 < w && scanfirst < numscans) - bunchp2[numscans-1] = scanfirst, scanfirst = numscans; - } - - for (bssize_t s=onumscans; s= xb1[bunchp2[s]]) - { - bunchfirst[numbunches++] = bunchp2[s], bunchp2[s] = -1; -#ifdef YAX_ENABLE - if (scansector_retfast) - return; -#endif - } - - for (bssize_t bn=onumbunches; bn=0; s=bunchp2[s]) - /* do nothing */; - bunchlast[bn] = s; - } - } - while (sectorbordercnt > 0); -} - -#if DEBUGGINGAIDS >= 2 -// Printing functions for collected scans (called "wall proxies" by -// http://fabiensanglard.net/duke3d/build_engine_internals.php) and -// bunches. For use from within the debugger. - -void printscans(void) -{ - static uint8_t didscan[(MAXWALLSB+7)>>3]; - - Bmemset(didscan, 0, sizeof(didscan)); - - for (bssize_t s=0; s= 0 && (didscan[s>>3] & pow2char[s&7])==0) - { - printf("scan "); - - int z = s; - do - { - const int cond = (wall[thewall[z]].point2 != thewall[bunchp2[z]] || - xb2[z] >= xb1[bunchp2[z]]); - - printf("%s%d(%d) ", cond ? "!" : "", z, thewall[z]); - - if (didscan[z>>3] & pow2char[z&7]) - { - printf("*"); - break; - } - - didscan[z>>3] |= pow2char[z&7]; - z = bunchp2[z]; - } while (z >= 0); - - printf("\n"); - } - } -} - -void printbunches(void) -{ - for (bssize_t bn=0; bn=0; s=bunchp2[s]) - printf("%d(%d) ", s, thewall[s]); - printf("\n"); - } -} -#endif ////////// *WALLSCAN HELPERS ////////// @@ -1690,198 +1479,9 @@ static WSHELPER_DECL void tweak_tsizes(vec2_16_t *tsiz) tsiz->y = -tsiz->y; } -static WSHELPER_DECL void calc_bufplc(intptr_t *bufplc, int32_t lw, vec2_16_t tsiz) -{ - // CAUTION: lw can be negative! - int32_t i = lw + globalxpanning; - -// if (i >= tsizx) - { - if (tsiz.x < 0) - i = (uint32_t)i % -tsiz.x; - else - i &= tsiz.x; - } - - if (tsiz.y < 0) - i *= -tsiz.y; - else - i <<= tsiz.y; - -// Bassert(i >= 0 && i < tilesiz[globalpicnum].x*tilesiz[globalpicnum].y); - - // Address is at the first row of tile storage (which is column-major). - *bufplc = (intptr_t)tilePtr(globalpicnum) + i; -} - -static WSHELPER_DECL void calc_vplcinc_wall(uint32_t *vplc, int32_t *vinc, inthi_t sw, int32_t y1v) -{ - *vinc = sw*globalyscale; - *vplc = globalzd + (uint32_t)(*vinc)*(y1v-globalhoriz+1); -} - -#ifdef HIGH_PRECISION_SPRITE -static WSHELPER_DECL void calc_vplcinc_sprite(uint32_t *vplc, int32_t *vinc, int32_t x, int32_t y1v) -{ - inthi_t const tmpvinc = inthi_rintf(swallf[x]); - inthi_t const tmpvplc = globalzd + tmpvinc*(y1v-globalhoriz+1); - - *vinc = tmpvinc; - // Clamp the vertical texture coordinate! - *vplc = min(max(0, tmpvplc), UINT32_MAX); -} -#endif static int32_t drawing_sprite = 0; -static WSHELPER_DECL void calc_vplcinc(uint32_t *vplc, int32_t *vinc, const int32_t *swal, int32_t x, int32_t y1v) -{ -#if !defined HIGH_PRECISION_SPRITE - (void)drawing_sprite; -#else - if (drawing_sprite) - calc_vplcinc_sprite(vplc, vinc, x, y1v); - else -#endif - calc_vplcinc_wall(vplc, vinc, swal[x], y1v); -} - -#undef NONPOW2_YSIZE_ASM - - -// -// maskwallscan (internal) -// -static void maskwallscan(int32_t x1, int32_t x2, int32_t saturatevplc) -{ - if (globalshiftval < 0) return; - if ((uwall[x1] > ydimen) && (uwall[x2] > ydimen)) return; - if ((dwall[x1] < 0) && (dwall[x2] < 0)) return; - - auto tsiz = tilesiz[globalpicnum]; - if ((tsiz.x <= 0) || (tsiz.y <= 0)) return; - - setgotpic(globalpicnum); - - tileLoad(globalpicnum); - - tweak_tsizes(&tsiz); - - if (EDUKE32_PREDICT_FALSE(palookup[globalpal] == NULL)) - globalpal = 0; - - intptr_t const fpalookup = FP_OFF(palookup[globalpal]); - - setupmvlineasm(globalshiftval, saturatevplc); - - int32_t x = x1; - while ((x <= x2) && (startumost[x+windowxy1.x] > startdmost[x+windowxy1.x])) - x++; - - intptr_t p = x+frameoffset; - - int32_t y1ve[4], y2ve[4]; - -#ifdef NONPOW2_YSIZE_ASM - if (globalshiftval==0) - goto do_mvlineasm1; -#endif - -#ifdef MULTI_COLUMN_VLINE - for (; (x<=x2)&&(p&3); x++,p++) - { - y1ve[0] = max(uwall[x],startumost[x+windowxy1.x]-windowxy1.y); - y2ve[0] = min(dwall[x],startdmost[x+windowxy1.x]-windowxy1.y); - if (y2ve[0] <= y1ve[0]) continue; - - palookupoffse[0] = fpalookup + getpalookupsh(mulscale16(swall[x],globvis)); - - calc_bufplc(&bufplce[0], lwall[x], tsiz); - calc_vplcinc(&vplce[0], &vince[0], swall.Data(), x, y1ve[0]); - - mvlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0],p+ylookup[y1ve[0]]); - } - for (; x<=x2-3; x+=4,p+=4) - { - char bad = 0; - - for (bssize_t z=3,dax=x+3; z>=0; z--,dax--) - { - y1ve[z] = max(uwall[dax],startumost[dax+windowxy1.x]-windowxy1.y); - y2ve[z] = min(dwall[dax],startdmost[dax+windowxy1.x]-windowxy1.y)-1; - if (y2ve[z] < y1ve[z]) { bad += pow2char[z]; continue; } - - calc_bufplc(&bufplce[z], lwall[dax], tsiz); - calc_vplcinc(&vplce[z], &vince[z], swall.Data(), dax, y1ve[z]); - } - if (bad == 15) continue; - - palookupoffse[0] = fpalookup + getpalookupsh(mulscale16(swall[x],globvis)); - palookupoffse[3] = fpalookup + getpalookupsh(mulscale16(swall[x+3],globvis)); - - if ((palookupoffse[0] == palookupoffse[3]) && ((bad&0x9) == 0)) - { - palookupoffse[1] = palookupoffse[0]; - palookupoffse[2] = palookupoffse[0]; - } - else - { - palookupoffse[1] = fpalookup + getpalookupsh(mulscale16(swall[x+1],globvis)); - palookupoffse[2] = fpalookup + getpalookupsh(mulscale16(swall[x+2],globvis)); - } - - int32_t const u4 = max(max(y1ve[0],y1ve[1]),max(y1ve[2],y1ve[3])); - int32_t const d4 = min(min(y2ve[0],y2ve[1]),min(y2ve[2],y2ve[3])); - - if ((bad > 0) || (u4 >= d4)) - { - if (!(bad&1)) mvlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0],vplce[0],bufplce[0],ylookup[y1ve[0]]+p+0); - if (!(bad&2)) mvlineasm1(vince[1],palookupoffse[1],y2ve[1]-y1ve[1],vplce[1],bufplce[1],ylookup[y1ve[1]]+p+1); - if (!(bad&4)) mvlineasm1(vince[2],palookupoffse[2],y2ve[2]-y1ve[2],vplce[2],bufplce[2],ylookup[y1ve[2]]+p+2); - if (!(bad&8)) mvlineasm1(vince[3],palookupoffse[3],y2ve[3]-y1ve[3],vplce[3],bufplce[3],ylookup[y1ve[3]]+p+3); - continue; - } - - if (u4 > y1ve[0]) vplce[0] = mvlineasm1(vince[0],palookupoffse[0],u4-y1ve[0]-1,vplce[0],bufplce[0],ylookup[y1ve[0]]+p+0); - if (u4 > y1ve[1]) vplce[1] = mvlineasm1(vince[1],palookupoffse[1],u4-y1ve[1]-1,vplce[1],bufplce[1],ylookup[y1ve[1]]+p+1); - if (u4 > y1ve[2]) vplce[2] = mvlineasm1(vince[2],palookupoffse[2],u4-y1ve[2]-1,vplce[2],bufplce[2],ylookup[y1ve[2]]+p+2); - if (u4 > y1ve[3]) vplce[3] = mvlineasm1(vince[3],palookupoffse[3],u4-y1ve[3]-1,vplce[3],bufplce[3],ylookup[y1ve[3]]+p+3); - - if (d4 >= u4) mvlineasm4(d4-u4+1, (char *)(ylookup[u4]+p)); - - intptr_t const pp = p+ylookup[d4+1]; - - if (y2ve[0] > d4) mvlineasm1(vince[0],palookupoffse[0],y2ve[0]-d4-1,vplce[0],bufplce[0],pp+0); - if (y2ve[1] > d4) mvlineasm1(vince[1],palookupoffse[1],y2ve[1]-d4-1,vplce[1],bufplce[1],pp+1); - if (y2ve[2] > d4) mvlineasm1(vince[2],palookupoffse[2],y2ve[2]-d4-1,vplce[2],bufplce[2],pp+2); - if (y2ve[3] > d4) mvlineasm1(vince[3],palookupoffse[3],y2ve[3]-d4-1,vplce[3],bufplce[3],pp+3); - } -#endif - -#ifdef NONPOW2_YSIZE_ASM -do_mvlineasm1: -#endif - for (; x<=x2; x++,p++) - { - y1ve[0] = max(uwall[x],startumost[x+windowxy1.x]-windowxy1.y); - y2ve[0] = min(dwall[x],startdmost[x+windowxy1.x]-windowxy1.y); - if (y2ve[0] <= y1ve[0]) continue; - - palookupoffse[0] = fpalookup + getpalookupsh(mulscale16(swall[x],globvis)); - - calc_bufplc(&bufplce[0], lwall[x], tsiz); - calc_vplcinc(&vplce[0], &vince[0], swall.Data(), x, y1ve[0]); - -#ifdef NONPOW2_YSIZE_ASM - if (globalshiftval==0) - mvlineasm1nonpow2(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0],p+ylookup[y1ve[0]]); - else -#endif - mvlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0],p+ylookup[y1ve[0]]); - } - - faketimerhandler(); -} // @@ -1930,58 +1530,6 @@ static inline int32_t spritewallfront(tspritetype const * const s, int32_t w) return dmulscale32(wal2->x - v.x, s->y - v.y, -(s->x - v.x), wal2->y - v.y) >= 0; } -// -// spritebehindwall(internal) -// -#if 0 -static int32_t spriteobstructswall(spritetype *s, int32_t w) -{ - walltype *wal; - int32_t x, y; - int32_t x1, y1; - int32_t x2, y2; - double a1, b1, c1; - double a2, b2, c2; - double d1, d2; - - // wall line equation - wal = &wall[w]; x1 = wal->x - globalposx; y1 = wal->y - globalposy; - wal = &wall[wal->point2]; x2 = wal->x - globalposx; y2 = wal->y - globalposy; - if ((x2 - x1) != 0) - a1 = (float)(y2 - y1)/(x2 - x1); - else - a1 = 1e+37; // not infinite, but almost ;) - b1 = -1; - c1 = (y1 - (a1 * x1)); - - // player to sprite line equation - if ((s->x - globalposx) != 0) - a2 = (float)(s->y - globalposy)/(s->x - globalposx); - else - a2 = 1e+37; - b2 = -1; - c2 = 0; - - // intersection point - d1 = (float)(1) / (a1*b2 - a2*b1); - x = ((b1*c2 - b2*c1) * d1); - y = ((a2*c1 - a1*c2) * d1); - - // distance between the sprite and the player - a1 = s->x - globalposx; - b1 = s->y - globalposy; - d1 = (a1 * a1 + b1 * b1); - - // distance between the intersection point and the player - d2 = (x * x + y * y); - - // check if the sprite obstructs the wall - if ((d1 < d2) && (min(x1, x2) <= x) && (x <= max(x1, x2)) && (min(y1, y2) <= y) && (y <= max(y1, y2))) - return 1; - else - return 0; -} -#endif // // bunchfront (internal) // @@ -2012,45 +1560,6 @@ static inline int32_t bunchfront(int32_t b1, int32_t b2) } -// -// hline (internal) -// -static inline void hline(int32_t xr, int32_t yp) -{ - int32_t const xl = lastx[yp]; - if (xl > xr) return; - int32_t const r = horizlookup2[yp-globalhoriz+horizycent]; - asm1 = (inthi_t)mulscale6(globalx1, r); - asm2 = (inthi_t)mulscale6(globaly2, r); - int32_t const s = getpalookupsh(mulscale22(r,globvis)); - - hlineasm4(xr-xl,0,s,(uint32_t)mulscale6(globalx2,r)+globalypanning,(uint32_t)mulscale6(globaly1,r)+globalxpanning, - ylookup[yp]+xr+frameoffset); -} - - -// -// slowhline (internal) -// -static inline void slowhline(int32_t xr, int32_t yp) -{ - int32_t const xl = lastx[yp]; if (xl > xr) return; - int32_t const r = horizlookup2[yp-globalhoriz+horizycent]; - asm1 = (inthi_t)mulscale6(globalx1, r); - asm2 = (inthi_t)mulscale6(globaly2, r); - - asm3 = (intptr_t)globalpalwritten + getpalookupsh(mulscale22(r,globvis)); - if (!(globalorientation&256)) - { - mhline(globalbufplc,(uint32_t)mulscale6(globaly1,r)+globalxpanning-asm1*(xr-xl),(xr-xl)<<16,0L, - (uint32_t)mulscale6(globalx2,r)+globalypanning-asm2*(xr-xl),ylookup[yp]+xl+frameoffset); - return; - } - thline(globalbufplc,(uint32_t)mulscale6(globaly1,r)+globalxpanning-asm1*(xr-xl),(xr-xl)<<16,0L, - (uint32_t)mulscale6(globalx2,r)+globalypanning-asm2*(xr-xl),ylookup[yp]+xl+frameoffset); -} - - // // prepwall (internal) // @@ -2183,13 +1692,6 @@ static inline void wallmosts_finish(int16_t *mostbuf, int32_t z1, int32_t z2, { const int32_t y = scale(z1, xdimenscale, iy1)<<4; -#if 0 - // enable for paranoia: - ix1 = clamp(ix1, 0, xdim-1); - ix2 = clamp(ix2, 0, xdim-1); - if (ix2-ix1 < 0) - swaplong(&ix1, &ix2); -#endif // PK 20110423: a bit consistency checking is a good thing: int32_t const tmp = (ix2 - ix1 >= 0) ? (ix2 - ix1 + 1) : 1; int32_t const yinc = tabledivide32((scale(z2, xdimenscale, iy2) << 4) - y, tmp); @@ -2225,233 +1727,6 @@ typedef int32_t zint_t; # define dmulscale24z dmulscale24 #endif -// -// owallmost (internal) -// -static int32_t owallmost(int16_t *mostbuf, int32_t w, zint_t z) -{ - z <<= 7; - const zint_t s1 = mulscale20z(globaluclip,yb1[w]), s2 = mulscale20z(globaluclip,yb2[w]); - const zint_t s3 = mulscale20z(globaldclip,yb1[w]), s4 = mulscale20z(globaldclip,yb2[w]); - const int32_t bad = (zs3)<<2)+((z>s4)<<3); - - int32_t ix1 = xb1[w], iy1 = yb1[w]; - int32_t ix2 = xb2[w], iy2 = yb2[w]; - - if ((bad&3) == 3) - { - for (bssize_t i=ix1; i<=ix2; i++) - mostbuf[i] = 0; - return bad; - } - - if ((bad&12) == 12) - { - for (bssize_t i=ix1; i<=ix2; i++) - mostbuf[i] = ydimen; - return bad; - } - - if (bad&3) - { - int32_t t = divscale30(z-s1,s2-s1); - int32_t inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t); - int32_t xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty); - - if ((bad&3) == 2) - { - if (xb1[w] <= xcross) { iy2 = inty; ix2 = xcross; } - for (bssize_t i=xcross+1; i<=xb2[w]; i++) - mostbuf[i] = 0; - } - else - { - if (xcross <= xb2[w]) { iy1 = inty; ix1 = xcross; } - for (bssize_t i=xb1[w]; i<=xcross; i++) - mostbuf[i] = 0; - } - } - - if (bad&12) - { - int32_t t = divscale30(z-s3,s4-s3); - int32_t inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t); - int32_t xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty); - - if ((bad&12) == 8) - { - if (xb1[w] <= xcross) { iy2 = inty; ix2 = xcross; } - for (bssize_t i=xcross+1; i<=xb2[w]; i++) - mostbuf[i] = ydimen; - } - else - { - if (xcross <= xb2[w]) { iy1 = inty; ix1 = xcross; } - for (bssize_t i=xb1[w]; i<=xcross; i++) - mostbuf[i] = ydimen; - } - } - - wallmosts_finish(mostbuf, z, z, ix1, iy1, ix2, iy2); - - return bad; -} - -static inline zint_t wallmost_getz(int32_t fw, int32_t t, zint_t z, - int32_t x1, int32_t y1, int32_t x2, int32_t y2, - int32_t xv, int32_t yv, int32_t dx, int32_t dy) -{ - // XXX: OVERFLOW with huge sectors and sloped ceilngs/floors! - int32_t i = xv*(y1-globalposy) - yv*(x1-globalposx); - const int32_t j = yv*x2 - xv*y2; - - if (klabs(j) > klabs(i>>3)) - i = divscale28(i,j); - - return dmulscale24z(dx*t, mulscale20z(y2,i)+((y1-wall[fw].y)<<8), - -dy*t, mulscale20z(x2,i)+((x1-wall[fw].x)<<8)) + ((z-globalposz)<<7); -} - -// -// wallmost (internal) -// -static int32_t wallmost(int16_t *mostbuf, int32_t w, int32_t sectnum, char dastat) -{ - int32_t t, z; - int32_t xv, yv; - - if (dastat == 0) - { - z = sector[sectnum].ceilingz-globalposz; - if ((sector[sectnum].ceilingstat&2) == 0) - return owallmost(mostbuf,w,z); - } - else - { - z = sector[sectnum].floorz-globalposz; - if ((sector[sectnum].floorstat&2) == 0) - return owallmost(mostbuf,w,z); - } - - const int wi = thewall[w]; - if (wi == sector[sectnum].wallptr) - return owallmost(mostbuf,w,z); - - auto const wal = (uwallptr_t)&wall[wi]; - const int32_t x1 = wal->x, x2 = wall[wal->point2].x-x1; - const int32_t y1 = wal->y, y2 = wall[wal->point2].y-y1; - - const int w1 = sector[sectnum].wallptr, w2 = wall[w1].point2; - const int32_t dx = wall[w2].x-wall[w1].x, dy = wall[w2].y-wall[w1].y; - const int32_t dasqr = krecipasm(nsqrtasm(uhypsq(dx,dy))); - - if (dastat == 0) - { - t = mulscale15(sector[sectnum].ceilingheinum, dasqr); - z = sector[sectnum].ceilingz; - } - else - { - t = mulscale15(sector[sectnum].floorheinum,dasqr); - z = sector[sectnum].floorz; - } - - - if (xb1[w] == 0) - { xv = cosglobalang+sinviewingrangeglobalang; yv = singlobalang-cosviewingrangeglobalang; } - else - { xv = x1-globalposx; yv = y1-globalposy; } - zint_t z1 = wallmost_getz(w1, t, z, x1, y1, x2, y2, xv, yv, dx, dy); - - - if (xb2[w] == xdimen-1) - { xv = cosglobalang-sinviewingrangeglobalang; yv = singlobalang+cosviewingrangeglobalang; } - else - { xv = (x2+x1)-globalposx; yv = (y2+y1)-globalposy; } - zint_t z2 = wallmost_getz(w1, t, z, x1, y1, x2, y2, xv, yv, dx, dy); - - - const zint_t s1 = mulscale20(globaluclip,yb1[w]), s2 = mulscale20(globaluclip,yb2[w]); - const zint_t s3 = mulscale20(globaldclip,yb1[w]), s4 = mulscale20(globaldclip,yb2[w]); - const int32_t bad = (z1s3)<<2)+((z2>s4)<<3); - - int32_t ix1 = xb1[w], ix2 = xb2[w]; - int32_t iy1 = yb1[w], iy2 = yb2[w]; - - if ((bad&3) == 3) - { - for (bssize_t i=ix1; i<=ix2; i++) - mostbuf[i] = 0; - return bad; - } - - if ((bad&12) == 12) - { - for (bssize_t i=ix1; i<=ix2; i++) - mostbuf[i] = ydimen; - return bad; - } - - const int32_t oz1 = z1, oz2 = z2; - - if (bad&3) - { - //inty = intz / (globaluclip>>16) - t = divscale30(oz1-s1,s2-s1+oz1-oz2); - int32_t inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t); - int32_t intz = oz1 + mulscale30(oz2-oz1,t); - int32_t xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty); - - //t = divscale30((x1<<4)-xcross*yb1[w],xcross*(yb2[w]-yb1[w])-((x2-x1)<<4)); - //inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t); - //intz = z1 + mulscale30(z2-z1,t); - - if ((bad&3) == 2) - { - if (xb1[w] <= xcross) { z2 = intz; iy2 = inty; ix2 = xcross; } - for (bssize_t i=xcross+1; i<=xb2[w]; i++) - mostbuf[i] = 0; - } - else - { - if (xcross <= xb2[w]) { z1 = intz; iy1 = inty; ix1 = xcross; } - for (bssize_t i=xb1[w]; i<=xcross; i++) - mostbuf[i] = 0; - } - } - - if (bad&12) - { - //inty = intz / (globaldclip>>16) - t = divscale30(oz1-s3,s4-s3+oz1-oz2); - int32_t inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t); - int32_t intz = oz1 + mulscale30(oz2-oz1,t); - int32_t xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty); - - //t = divscale30((x1<<4)-xcross*yb1[w],xcross*(yb2[w]-yb1[w])-((x2-x1)<<4)); - //inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t); - //intz = z1 + mulscale30(z2-z1,t); - - if ((bad&12) == 8) - { - if (xb1[w] <= xcross) { z2 = intz; iy2 = inty; ix2 = xcross; } - for (bssize_t i=xcross+1; i<=xb2[w]; i++) - mostbuf[i] = ydimen; - } - else - { - if (xcross <= xb2[w]) { z1 = intz; iy1 = inty; ix1 = xcross; } - for (bssize_t i=xb1[w]; i<=xcross; i++) - mostbuf[i] = ydimen; - } - } - - wallmosts_finish(mostbuf, z1, z2, ix1, iy1, ix2, iy2); - - return bad; -} - - // globalpicnum --> globalxshift, globalyshift static void calc_globalshifts(void) { @@ -2464,3584 +1739,9 @@ static void calc_globalshifts(void) if (globalyshift > 31) globalyshift=0; } -static int32_t setup_globals_cf1(usectorptr_t sec, int32_t pal, int32_t zd, - int32_t picnum, int32_t shade, int32_t stat, - int32_t xpanning, int32_t ypanning, int32_t x1) -{ - int32_t i; - - if (palookup[pal] != globalpalwritten) - { - globalpalwritten = palookup[pal]; - if (!globalpalwritten) globalpalwritten = palookup[globalpal]; // JBF: fixes null-pointer crash - setpalookupaddress(globalpalwritten); - } - - globalzd = zd; - if (globalzd > 0) return 1; - - globalpicnum = picnum; - if ((unsigned)globalpicnum >= MAXTILES) globalpicnum = 0; - tileUpdatePicnum(&globalpicnum, 0); - setgotpic(globalpicnum); - if ((tilesiz[globalpicnum].x <= 0) || (tilesiz[globalpicnum].y <= 0)) return 1; - tileLoad(globalpicnum); - - - globalbufplc = (intptr_t)tilePtr(globalpicnum); - - globalshade = shade; - globvis = globalcisibility; - if (sec->visibility != 0) globvis = mulscale4(globvis, (uint8_t)(sec->visibility+16)); - globalorientation = stat; - - if ((globalorientation&64) == 0) - { - globalx1 = singlobalang; globalx2 = singlobalang; - globaly1 = cosglobalang; globaly2 = cosglobalang; - globalxpanning = ((inthi_t)globalposx<<20); - globalypanning = -((inthi_t)globalposy<<20); - } - else - { - vec2_t const xy = { wall[wall[sec->wallptr].point2].x - wall[sec->wallptr].x, - wall[wall[sec->wallptr].point2].y - wall[sec->wallptr].y }; - i = nsqrtasm(uhypsq(xy.x,xy.y)); if (i == 0) i = 1024; else i = tabledivide32(1048576, i); - int const wcos = mulscale6(xy.x, i), wsin = mulscale6(xy.y, i); - globalx1 = dmulscale14(wcos,singlobalang,-wsin,cosglobalang); - globaly1 = dmulscale14(wcos,cosglobalang,wsin,singlobalang); - globalx2 = -globalx1; - globaly2 = -globaly1; - - globalxpanning = (coord_t)((globalposx - wall[sec->wallptr].x)<<6) * wcos + (coord_t)((globalposy - wall[sec->wallptr].y)<<6) * wsin; - globalypanning = (coord_t)((globalposy - wall[sec->wallptr].y)<<6) * wcos - (coord_t)((globalposx - wall[sec->wallptr].x)<<6) * wsin; - } - globalx2 = mulscale16(globalx2,viewingrangerecip); - globaly1 = mulscale16(globaly1,viewingrangerecip); - - calc_globalshifts(); - - if ((globalorientation&0x4) > 0) - { - i = globalxpanning; globalxpanning = globalypanning; globalypanning = i; - i = globalx2; globalx2 = -globaly1; globaly1 = -i; - i = globalx1; globalx1 = globaly2; globaly2 = i; - } - if ((globalorientation&0x10) > 0) globalx1 = -globalx1, globaly1 = -globaly1, globalxpanning = -(inthi_t)globalxpanning; - if ((globalorientation&0x20) > 0) globalx2 = -globalx2, globaly2 = -globaly2, globalypanning = -(inthi_t)globalypanning; - globalx1 <<= globalxshift; globaly1 <<= globalxshift; - globalx2 <<= globalyshift; globaly2 <<= globalyshift; - globalxpanning <<= globalxshift; globalypanning <<= globalyshift; - globalxpanning = (uint32_t)globalxpanning + (xpanning<<24); - globalypanning = (uint32_t)globalypanning + (ypanning<<24); - globaly1 = (-globalx1-globaly1)*halfxdimen; - globalx2 = (globalx2-globaly2)*halfxdimen; - - sethlinesizes(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4,globalbufplc); - - globalx2 += globaly2*(x1-1); - globaly1 += globalx1*(x1-1); - globalx1 = mulscale16(globalx1,globalzd); - globalx2 = mulscale16(globalx2,globalzd); - globaly1 = mulscale16(globaly1,globalzd); - globaly2 = mulscale16(globaly2,globalzd); - globvis = klabs(mulscale10(globvis,globalzd)); - - return 0; -} - -// -// ceilscan (internal) -// -static void ceilscan(int32_t x1, int32_t x2, int32_t sectnum) -{ - int32_t x, y1, y2; - auto const sec = (usectorptr_t)§or[sectnum]; - - if (setup_globals_cf1(sec, sec->ceilingpal, sec->ceilingz-globalposz, - sec->ceilingpicnum, sec->ceilingshade, sec->ceilingstat, - sec->ceilingxpanning, sec->ceilingypanning, x1)) - return; - - if (!(globalorientation&0x180)) - { - y1 = umost[x1]; y2 = y1; - for (x=x1; x<=x2; x++) - { - const int32_t twall = umost[x]-1; - const int32_t bwall = min(uplc[x],dmost[x]); - - if (twall < bwall-1) - { - if (twall >= y2) - { - while (y1 < y2-1) hline(x-1,++y1); - y1 = twall; - } - else - { - while (y1 < twall) hline(x-1,++y1); - while (y1 > twall) lastx[y1--] = x; - } - while (y2 > bwall) hline(x-1,--y2); - while (y2 < bwall) lastx[y2++] = x; - } - else - { - while (y1 < y2-1) hline(x-1,++y1); - if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } - y1 = umost[x+1]; y2 = y1; - } - globalx2 += globaly2; globaly1 += globalx1; - } - while (y1 < y2-1) hline(x2,++y1); - faketimerhandler(); - return; - } - - switch (globalorientation&0x180) - { - case 128: - msethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; - case 256: - setup_blend(0, 0); - tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; - case 384: - setup_blend(0, 1); - tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; - } - - y1 = umost[x1]; y2 = y1; - for (x=x1; x<=x2; x++) - { - const int32_t twall = umost[x]-1; - const int32_t bwall = min(uplc[x],dmost[x]); - - if (twall < bwall-1) - { - if (twall >= y2) - { - while (y1 < y2-1) slowhline(x-1,++y1); - y1 = twall; - } - else - { - while (y1 < twall) slowhline(x-1,++y1); - while (y1 > twall) lastx[y1--] = x; - } - while (y2 > bwall) slowhline(x-1,--y2); - while (y2 < bwall) lastx[y2++] = x; - } - else - { - while (y1 < y2-1) slowhline(x-1,++y1); - if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } - y1 = umost[x+1]; y2 = y1; - } - globalx2 += globaly2; globaly1 += globalx1; - } - while (y1 < y2-1) slowhline(x2,++y1); - faketimerhandler(); -} - - -// -// florscan (internal) -// -static void florscan(int32_t x1, int32_t x2, int32_t sectnum) -{ - int32_t x, y1, y2; - auto const sec = (usectorptr_t)§or[sectnum]; - - if (setup_globals_cf1(sec, sec->floorpal, globalposz-sec->floorz, - sec->floorpicnum, sec->floorshade, sec->floorstat, - sec->floorxpanning, sec->floorypanning, x1)) - return; - - if (!(globalorientation&0x180)) - { - y1 = max(dplc[x1],umost[x1]); y2 = y1; - for (x=x1; x<=x2; x++) - { - const int32_t twall = max(dplc[x],umost[x])-1; - const int32_t bwall = dmost[x]; - - if (twall < bwall-1) - { - if (twall >= y2) - { - while (y1 < y2-1) hline(x-1,++y1); - y1 = twall; - } - else - { - while (y1 < twall) hline(x-1,++y1); - while (y1 > twall) lastx[y1--] = x; - } - while (y2 > bwall) hline(x-1,--y2); - while (y2 < bwall) lastx[y2++] = x; - } - else - { - while (y1 < y2-1) hline(x-1,++y1); - if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } - y1 = max(dplc[x+1],umost[x+1]); y2 = y1; - } - globalx2 += globaly2; globaly1 += globalx1; - } - while (y1 < y2-1) hline(x2,++y1); - faketimerhandler(); - return; - } - - switch (globalorientation&0x180) - { - case 128: - msethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; - case 256: - setup_blend(0, 0); - tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; - case 384: - setup_blend(0, 1); - tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4); - break; - } - - y1 = max(dplc[x1],umost[x1]); y2 = y1; - for (x=x1; x<=x2; x++) - { - const int32_t twall = max(dplc[x],umost[x])-1; - const int32_t bwall = dmost[x]; - - if (twall < bwall-1) - { - if (twall >= y2) - { - while (y1 < y2-1) slowhline(x-1,++y1); - y1 = twall; - } - else - { - while (y1 < twall) slowhline(x-1,++y1); - while (y1 > twall) lastx[y1--] = x; - } - while (y2 > bwall) slowhline(x-1,--y2); - while (y2 < bwall) lastx[y2++] = x; - } - else - { - while (y1 < y2-1) slowhline(x-1,++y1); - if (x == x2) { globalx2 += globaly2; globaly1 += globalx1; break; } - y1 = max(dplc[x+1],umost[x+1]); y2 = y1; - } - globalx2 += globaly2; globaly1 += globalx1; - } - while (y1 < y2-1) slowhline(x2,++y1); - faketimerhandler(); -} - - -// -// wallscan (internal) -// -static void wallscan(int32_t x1, int32_t x2, - const int16_t *uwal, const int16_t *dwal, - const int32_t *swal, const int32_t *lwal) -{ - int32_t x; - intptr_t fpalookup; - int32_t y1ve[4], y2ve[4]; - vec2_16_t tsiz; -#ifdef MULTI_COLUMN_VLINE - char bad; - int32_t u4, d4, z; - uintptr_t p; -#endif - -#ifdef YAX_ENABLE - if (g_nodraw) - return; -#endif - setgotpic(globalpicnum); - if (globalshiftval < 0) - return; - - if (x2 >= xdim) - x2 = xdim-1; - assert((unsigned)x1 < (unsigned)xdim); - - tsiz = tilesiz[globalpicnum]; - - if ((tsiz.x <= 0) || (tsiz.y <= 0)) return; - if ((uwal[x1] > ydimen) && (uwal[x2] > ydimen)) return; - if ((dwal[x1] < 0) && (dwal[x2] < 0)) return; - - tileLoad(globalpicnum); - - - tweak_tsizes(&tsiz); - - fpalookup = FP_OFF(palookup[globalpal]); - - setupvlineasm(globalshiftval); - - - x = x1; - while ((x <= x2) && (umost[x] > dmost[x])) - x++; - -#ifdef NONPOW2_YSIZE_ASM - if (globalshiftval==0) - goto do_vlineasm1; -#endif - -#ifdef MULTI_COLUMN_VLINE - for (; (x<=x2)&&((x+frameoffset)&3); x++) - { - y1ve[0] = max(uwal[x],umost[x]); - y2ve[0] = min(dwal[x],dmost[x]); - if (y2ve[0] <= y1ve[0]) continue; - - palookupoffse[0] = fpalookup + getpalookupsh(mulscale16(swal[x],globvis)); - - calc_bufplc(&bufplce[0], lwal[x], tsiz); - calc_vplcinc(&vplce[0], &vince[0], swal, x, y1ve[0]); - - vlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0],x+frameoffset+ylookup[y1ve[0]]); - } - for (; x<=x2-3; x+=4) - { - bad = 0; - for (z=3; z>=0; z--) - { - y1ve[z] = max(uwal[x+z],umost[x+z]); - y2ve[z] = min(dwal[x+z],dmost[x+z])-1; - if (y2ve[z] < y1ve[z]) { bad += pow2char[z]; continue; } - - calc_bufplc(&bufplce[z], lwal[x+z], tsiz); - calc_vplcinc(&vplce[z], &vince[z], swal, x+z, y1ve[z]); - } - if (bad == 15) continue; - - palookupoffse[0] = fpalookup + getpalookupsh(mulscale16(swal[x],globvis)); - palookupoffse[3] = fpalookup + getpalookupsh(mulscale16(swal[x+3],globvis)); - - if ((palookupoffse[0] == palookupoffse[3]) && ((bad&0x9) == 0)) - { - palookupoffse[1] = palookupoffse[0]; - palookupoffse[2] = palookupoffse[0]; - } - else - { - palookupoffse[1] = fpalookup + getpalookupsh(mulscale16(swal[x+1],globvis)); - palookupoffse[2] = fpalookup + getpalookupsh(mulscale16(swal[x+2],globvis)); - } - - u4 = max(max(y1ve[0],y1ve[1]),max(y1ve[2],y1ve[3])); - d4 = min(min(y2ve[0],y2ve[1]),min(y2ve[2],y2ve[3])); - - if ((bad != 0) || (u4 >= d4)) - { - if (!(bad&1)) prevlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0],vplce[0],bufplce[0],ylookup[y1ve[0]]+x+frameoffset+0); - if (!(bad&2)) prevlineasm1(vince[1],palookupoffse[1],y2ve[1]-y1ve[1],vplce[1],bufplce[1],ylookup[y1ve[1]]+x+frameoffset+1); - if (!(bad&4)) prevlineasm1(vince[2],palookupoffse[2],y2ve[2]-y1ve[2],vplce[2],bufplce[2],ylookup[y1ve[2]]+x+frameoffset+2); - if (!(bad&8)) prevlineasm1(vince[3],palookupoffse[3],y2ve[3]-y1ve[3],vplce[3],bufplce[3],ylookup[y1ve[3]]+x+frameoffset+3); - continue; - } - - if (u4 > y1ve[0]) vplce[0] = prevlineasm1(vince[0],palookupoffse[0],u4-y1ve[0]-1,vplce[0],bufplce[0],ylookup[y1ve[0]]+x+frameoffset+0); - if (u4 > y1ve[1]) vplce[1] = prevlineasm1(vince[1],palookupoffse[1],u4-y1ve[1]-1,vplce[1],bufplce[1],ylookup[y1ve[1]]+x+frameoffset+1); - if (u4 > y1ve[2]) vplce[2] = prevlineasm1(vince[2],palookupoffse[2],u4-y1ve[2]-1,vplce[2],bufplce[2],ylookup[y1ve[2]]+x+frameoffset+2); - if (u4 > y1ve[3]) vplce[3] = prevlineasm1(vince[3],palookupoffse[3],u4-y1ve[3]-1,vplce[3],bufplce[3],ylookup[y1ve[3]]+x+frameoffset+3); - - if (d4 >= u4) vlineasm4(d4-u4+1, (char *)(ylookup[u4]+x+frameoffset)); - - p = x+frameoffset+ylookup[d4+1]; - if (y2ve[0] > d4) prevlineasm1(vince[0],palookupoffse[0],y2ve[0]-d4-1,vplce[0],bufplce[0],p+0); - if (y2ve[1] > d4) prevlineasm1(vince[1],palookupoffse[1],y2ve[1]-d4-1,vplce[1],bufplce[1],p+1); - if (y2ve[2] > d4) prevlineasm1(vince[2],palookupoffse[2],y2ve[2]-d4-1,vplce[2],bufplce[2],p+2); - if (y2ve[3] > d4) prevlineasm1(vince[3],palookupoffse[3],y2ve[3]-d4-1,vplce[3],bufplce[3],p+3); - } -#endif - -#ifdef NONPOW2_YSIZE_ASM -do_vlineasm1: -#endif - for (; x<=x2; x++) - { - y1ve[0] = max(uwal[x],umost[x]); - y2ve[0] = min(dwal[x],dmost[x]); - if (y2ve[0] <= y1ve[0]) continue; - - palookupoffse[0] = fpalookup + getpalookupsh(mulscale16(swal[x],globvis)); - - calc_bufplc(&bufplce[0], lwal[x], tsiz); - calc_vplcinc(&vplce[0], &vince[0], swal, x, y1ve[0]); - -#ifdef NONPOW2_YSIZE_ASM - if (globalshiftval==0) - vlineasm1nonpow2(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0],x+frameoffset+ylookup[y1ve[0]]); - else -#endif - vlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0],x+frameoffset+ylookup[y1ve[0]]); - } - - faketimerhandler(); -} - -// -// transmaskvline (internal) -// -static void transmaskvline(int32_t x) -{ - if ((unsigned)x >= (unsigned)xdimen) return; - - int32_t const y1v = max(uwall[x],startumost[x+windowxy1.x]-windowxy1.y); - int32_t const y2v = min(dwall[x],startdmost[x+windowxy1.x]-windowxy1.y) - 1; - - if (y2v < y1v) return; - - intptr_t palookupoffs = FP_OFF(palookup[globalpal]) + getpalookupsh(mulscale16(swall[x],globvis)); - - vec2_16_t const ntsiz = { (int16_t)-tilesiz[globalpicnum].x, (int16_t)-tilesiz[globalpicnum].y }; - intptr_t bufplc; - calc_bufplc(&bufplc, lwall[x], ntsiz); - uint32_t vplc; - int32_t vinc; - calc_vplcinc(&vplc, &vinc, swall.Data(), x, y1v); - - intptr_t p = ylookup[y1v]+x+frameoffset; - -#ifdef NONPOW2_YSIZE_ASM - if (globalshiftval==0) - tvlineasm1nonpow2(vinc,palookupoffs,y2v-y1v,vplc,bufplc,p); - else -#endif - tvlineasm1(vinc,palookupoffs,y2v-y1v,vplc,bufplc,p); -} - - -// -// transmaskvline2 (internal) -// -#ifdef MULTI_COLUMN_VLINE -static void transmaskvline2(int32_t x) -{ - if ((unsigned)x >= (unsigned)xdimen) return; - if (x == xdimen-1) { transmaskvline(x); return; } - - int32_t y1ve[2], y2ve[2]; - int32_t x2 = x+1; - - y1ve[0] = max(uwall[x],startumost[x+windowxy1.x]-windowxy1.y); - y2ve[0] = min(dwall[x],startdmost[x+windowxy1.x]-windowxy1.y)-1; - if (y2ve[0] < y1ve[0]) { transmaskvline(x2); return; } - y1ve[1] = max(uwall[x2],startumost[x2+windowxy1.x]-windowxy1.y); - y2ve[1] = min(dwall[x2],startdmost[x2+windowxy1.x]-windowxy1.y)-1; - if (y2ve[1] < y1ve[1]) { transmaskvline(x); return; } - - palookupoffse[0] = FP_OFF(palookup[globalpal]) + getpalookupsh(mulscale16(swall[x],globvis)); - palookupoffse[1] = FP_OFF(palookup[globalpal]) + getpalookupsh(mulscale16(swall[x2],globvis)); - - setuptvlineasm2(globalshiftval,palookupoffse[0],palookupoffse[1]); - - vec2_16_t const ntsiz = { (int16_t)-tilesiz[globalpicnum].x, (int16_t)-tilesiz[globalpicnum].y }; - - calc_bufplc(&bufplce[0], lwall[x], ntsiz); - calc_bufplc(&bufplce[1], lwall[x2], ntsiz); - calc_vplcinc(&vplce[0], &vince[0], swall.Data(), x, y1ve[0]); - calc_vplcinc(&vplce[1], &vince[1], swall.Data(), x2, y1ve[1]); - - int32_t const y1 = max(y1ve[0],y1ve[1]); - int32_t const y2 = min(y2ve[0],y2ve[1]); - - uintptr_t p = x+frameoffset; - - if (y1ve[0] != y1ve[1]) - { - if (y1ve[0] < y1) - vplce[0] = tvlineasm1(vince[0],palookupoffse[0],y1-y1ve[0]-1,vplce[0],bufplce[0],ylookup[y1ve[0]]+p); - else - vplce[1] = tvlineasm1(vince[1],palookupoffse[1],y1-y1ve[1]-1,vplce[1],bufplce[1],ylookup[y1ve[1]]+p+1); - } - - if (y2 > y1) - { - asm1 = vince[1]; - asm2 = ylookup[y2]+p+1; - tvlineasm2(vplce[1],vince[0],bufplce[0],bufplce[1],vplce[0],ylookup[y1]+p); - } - else - { - asm1 = vplce[0]; - asm2 = vplce[1]; - } - - if (y2ve[0] > y2ve[1]) - tvlineasm1(vince[0],palookupoffse[0],y2ve[0]-y2-1,asm1,bufplce[0],ylookup[y2+1]+p); - else if (y2ve[0] < y2ve[1]) - tvlineasm1(vince[1],palookupoffse[1],y2ve[1]-y2-1,asm2,bufplce[1],ylookup[y2+1]+p+1); - - faketimerhandler(); -} -#endif - -// -// transmaskwallscan (internal) -// -static void transmaskwallscan(int32_t x1, int32_t x2, int32_t saturatevplc) -{ - setgotpic(globalpicnum); - - Bassert(globalshiftval>=0 || ((tilesiz[globalpicnum].x <= 0) || (tilesiz[globalpicnum].y <= 0))); - // globalshiftval<0 implies following condition - if ((tilesiz[globalpicnum].x <= 0) || (tilesiz[globalpicnum].y <= 0)) - return; - - tileLoad(globalpicnum); - - - setuptvlineasm(globalshiftval, saturatevplc); - - int32_t x = x1; - while ((x <= x2) && (startumost[x+windowxy1.x] > startdmost[x+windowxy1.x])) - ++x; - - { -#ifdef MULTI_COLUMN_VLINE - if ((x <= x2) && (x&1)) transmaskvline(x++); - while (x < x2) transmaskvline2(x), x += 2; -#endif - while (x <= x2) transmaskvline(x++); - } - - faketimerhandler(); -} - - -////////// NON-power-of-two replacements for mhline/thline, adapted from a.c ////////// -#if defined(__GNUC__) && defined(__i386__) && !defined(NOASM) -// from pragmas.h -# define ourdivscale32(d,b) \ - ({ int32_t __d=(d), __b=(b), __r; \ - __asm__ __volatile__ ("xorl %%eax, %%eax; divl %%ebx" \ - : "=a" (__r), "=d" (__d) : "d" (__d), "b" (__b) : "cc"); \ - __r; }) -#else -# define ourdivscale32(d,b) divscale32(d,b) -#endif - -// cntup16>>16 iterations - -static void nonpow2_mhline(intptr_t bufplc, uint32_t bx, int32_t cntup16, uint32_t by, char *p) -{ - char ch; - - const char *const A_C_RESTRICT buf = (char *)bufplc; - const char *const A_C_RESTRICT pal = (char *)asm3; - - const uint32_t xmul = globalxspan; - const uint32_t ymul = globalyspan; - const uint32_t yspan = globalyspan; - const int32_t xinc = asm1, yinc = asm2; - - for (cntup16>>=16; cntup16>0; cntup16--) - { - ch = buf[mulscale31(bx>>1, xmul)*yspan + mulscale31(by>>1, ymul)]; - - if (ch != 255) *p = pal[ch]; - bx += xinc; - by += yinc; - p++; - } -} - -// cntup16>>16 iterations -static void nonpow2_thline(intptr_t bufplc, uint32_t bx, int32_t cntup16, uint32_t by, char *p) -{ - char ch; - - const char *const A_C_RESTRICT buf = (char *)bufplc; - const char *const A_C_RESTRICT pal = (char *)asm3; - const char *const A_C_RESTRICT trans = paletteGetBlendTable(globalblend); - - const uint32_t xmul = globalxspan; - const uint32_t ymul = globalyspan; - const uint32_t yspan = globalyspan; - const int32_t xinc = asm1, yinc = asm2; - - if (globalorientation&512) - { - for (cntup16>>=16; cntup16>0; cntup16--) - { - ch = buf[mulscale31(bx>>1, xmul)*yspan + mulscale31(by>>1, ymul)]; - if (ch != 255) *p = trans[(*p)|(pal[ch]<<8)]; - bx += xinc; - by += yinc; - p++; - } - } - else - { - for (cntup16>>=16; cntup16>0; cntup16--) - { - ch = buf[mulscale31(bx>>1, xmul)*yspan + mulscale31(by>>1, ymul)]; - if (ch != 255) *p = trans[((*p)<<8)|pal[ch]]; - bx += xinc; - by += yinc; - p++; - } - } -} -////////// END non-power-of-two replacements ////////// - -// -// ceilspritehline (internal) -// -static void ceilspritehline(int32_t x2, int32_t y) -{ - int32_t x1, v, bx, by; - - //x = x1 + (x2-x1)t + (y1-y2)u ~ x = 160v - //y = y1 + (y2-y1)t + (x2-x1)u ~ y = (scrx-160)v - //z = z1 = z2 ~ z = posz + (scry-horiz)v - - x1 = lastx[y]; if (x2 < x1) return; - - v = mulscale20(globalzd,horizlookup[y-globalhoriz+horizycent]); - bx = (uint32_t)mulscale14(globalx2*x1+globalx1,v) + globalxpanning; - by = (uint32_t)mulscale14(globaly2*x1+globaly1,v) + globalypanning; - asm1 = mulscale14(globalx2,v); - asm2 = mulscale14(globaly2,v); - - asm3 = FP_OFF(palookup[globalpal]) + getpalookupsh(mulscale28(klabs(v),globvis)); - - if (globalispow2) - { - if ((globalorientation&2) == 0) - mhline(globalbufplc,bx,(x2-x1)<<16,0L,by,ylookup[y]+x1+frameoffset); - else - thline(globalbufplc,bx,(x2-x1)<<16,0L,by,ylookup[y]+x1+frameoffset); - } - else - { - if ((globalorientation&2) == 0) - nonpow2_mhline(globalbufplc,bx,(x2-x1)<<16,by,(char *)(ylookup[y]+x1+frameoffset)); - else - nonpow2_thline(globalbufplc,bx,(x2-x1)<<16,by,(char *)(ylookup[y]+x1+frameoffset)); - } -} - - -// -// ceilspritescan (internal) -// -static void ceilspritescan(int32_t x1, int32_t x2) -{ - int32_t y1 = uwall[x1]; - int32_t y2 = y1; - - for (bssize_t x=x1; x<=x2; ++x) - { - const int32_t twall = uwall[x]-1; - const int32_t bwall = dwall[x]; - - if (twall < bwall-1) - { - if (twall >= y2) - { - while (y1 < y2-1) ceilspritehline(x-1,++y1); - y1 = twall; - } - else - { - while (y1 < twall) ceilspritehline(x-1,++y1); - while (y1 > twall) lastx[y1--] = x; - } - while (y2 > bwall) ceilspritehline(x-1,--y2); - while (y2 < bwall) lastx[y2++] = x; - } - else - { - while (y1 < y2-1) ceilspritehline(x-1,++y1); - if (x == x2) break; - y1 = uwall[x+1]; y2 = y1; - } - } - while (y1 < y2-1) ceilspritehline(x2,++y1); - faketimerhandler(); -} - -////////// translucent slope vline, based on a-c.c's slopevlin ////////// -static int32_t gglogx, gglogy, ggpinc; -static char *ggbuf, *ggpal; - -#ifdef ENGINE_USING_A_C -extern int32_t gpinc; -#endif - -static inline void setupslopevlin_alsotrans(int32_t logylogx, intptr_t bufplc, int32_t pinc) -{ - sethlinesizes(logylogx&255, logylogx>>8, bufplc); - gpinc = pinc; - gglogx = (logylogx&255); gglogy = (logylogx>>8); - ggbuf = (char *)bufplc; ggpinc = pinc; - ggpal = palookup[globalpal] + getpalookupsh(0); -} - -// cnt iterations -static void tslopevlin(uint8_t *p, const intptr_t *slopalptr, bssize_t cnt, int32_t bx, int32_t by) -{ - const char *const A_C_RESTRICT buf = ggbuf; - const char *const A_C_RESTRICT trans = paletteGetBlendTable(0); - const int32_t bzinc = (asm1>>3), pinc = ggpinc; - - const int32_t transmode = (globalorientation&128); - const uint32_t xtou = globalx3, ytov = globaly3; - const int32_t logx = gglogx, logy = gglogy; - - int32_t bz = asm3; - - do - { - int const i = (sloptable[(bz>>6)+HALFSLOPTABLESIZ]); bz += bzinc; - uint32_t u = bx + xtou*i; - uint32_t v = by + ytov*i; - uint8_t ch = buf[((u>>(32-logx))<>(32-logy))]; - if (ch != 255) - { - ch = *(uint8_t *)(slopalptr[0] + ch); - *p = trans[transmode ? *p|(ch<<8) : (*p<<8)|ch]; - } - - slopalptr--; - p += pinc; - } - while (--cnt); -} - -// cnt iterations -static void mslopevlin(uint8_t *p, const intptr_t *slopalptr, bssize_t cnt, int32_t bx, int32_t by) -{ - const char *const A_C_RESTRICT buf = ggbuf; - const int32_t bzinc = (asm1>>3), pinc = ggpinc; - - const uint32_t xtou = globalx3, ytov = globaly3; - const int32_t logx = gglogx, logy = gglogy; - - int32_t bz = asm3; - - do - { - int const i = (sloptable[(bz>>6)+HALFSLOPTABLESIZ]); bz += bzinc; - uint32_t u = bx + xtou*i; - uint32_t v = by + ytov*i; - uint8_t ch = buf[((u>>(32-logx))<>(32-logy))]; - if (ch != 255) - *p = *(uint8_t *)(slopalptr[0] + ch); - - slopalptr--; - p += pinc; - } - while (--cnt); -} - -// -// grouscan (internal) -// -#define BITSOFPRECISION 3 //Don't forget to change this in A.ASM also! -static void fgrouscan(int32_t dax1, int32_t dax2, int32_t sectnum, char dastat) -{ - int32_t i, j, l, globalx1, globaly1, y1, y2, daslope, daz, wxi, wyi; - float fi, wx, wy, dasqr; - float globalx, globaly, globalx2, globaly2, globalx3, globaly3, globalz, globalzd, globalzx; - int32_t shoffs, m1, m2, shy1, shy2; - intptr_t *mptr1, *mptr2; - - const usectortype *const sec = (usectortype *)§or[sectnum]; - const uwalltype *wal; - - if (dastat == 0) - { - if (globalposz <= getceilzofslope(sectnum,globalposx,globalposy)) - return; //Back-face culling - globalorientation = sec->ceilingstat; - globalpicnum = sec->ceilingpicnum; - globalshade = sec->ceilingshade; - globalpal = sec->ceilingpal; - daslope = sec->ceilingheinum; - daz = sec->ceilingz; - } - else - { - if (globalposz >= getflorzofslope(sectnum,globalposx,globalposy)) - return; //Back-face culling - globalorientation = sec->floorstat; - globalpicnum = sec->floorpicnum; - globalshade = sec->floorshade; - globalpal = sec->floorpal; - daslope = sec->floorheinum; - daz = sec->floorz; - } - - tileUpdatePicnum(&globalpicnum, sectnum); - setgotpic(globalpicnum); - if ((tilesiz[globalpicnum].x <= 0) || (tilesiz[globalpicnum].y <= 0)) return; - tileLoad(globalpicnum); - - - wal = (uwalltype *)&wall[sec->wallptr]; - wxi = wall[wal->point2].x - wal->x; - wyi = wall[wal->point2].y - wal->y; - dasqr = 1073741824.f/nsqrtasm(uhypsq(wxi,wyi)); - fi = daslope*dasqr*(1.f/2097152.f); - wx = wxi*fi; wy = wyi*fi; - - globalx = -float(singlobalang)*float(xdimenrecip)*(1.f/524288.f); - globaly = float(cosglobalang)*float(xdimenrecip)*(1.f/524288.f); - globalx1 = globalposx<<8; - globaly1 = -globalposy<<8; - fi = (dax1-halfxdimen)*xdimenrecip; - globalx2 = float(cosglobalang)*float(viewingrangerecip)*(1.f/4096.f) - float(singlobalang)*fi*(1.f/134217728.f); - globaly2 = float(singlobalang)*float(viewingrangerecip)*(1.f/4096.f) + float(cosglobalang)*fi*(1.f/134217728.f); - globalzd = xdimscale*512.f; - globalzx = -(wx*globaly2-wy*globalx2)*(1.f/131072.f) + (1-globalhoriz)*globalzd*(1.f/1024.f); - globalz = -(wx*globaly-wy*globalx)*(1.f/33554432.f); - - if (globalorientation&64) //Relative alignment - { - float dx, dy, x, y; - dx = (wall[wal->point2].x-wal->x)*dasqr*(1.f/16384.f); - dy = (wall[wal->point2].y-wal->y)*dasqr*(1.f/16384.f); - - fi = float(nsqrtasm(daslope*daslope+16777216)); - - x = globalx; y = globaly; - globalx = (x*dx+y*dy)*(1.f/65536.f); - globaly = (-y*dx+x*dy)*fi*(1.f/268435456.f); - - x = (wal->x-globalposx)*256.f; y = (wal->y-globalposy)*256.f; - globalx1 = Blrintf((-x*dx-y*dy)*(1.f/65536.f)); - globaly1 = Blrintf((-y*dx+x*dy)*fi*(1.f/268435456.f)); - - x = globalx2; y = globaly2; - globalx2 = (x*dx+y*dy)*(1.f/65536.f); - globaly2 = (-y*dx+x*dy)*fi*(1.f/268435456.f); - } - if (globalorientation&0x4) - { - fi = globalx; globalx = -globaly; globaly = -fi; - i = globalx1; globalx1 = globaly1; globaly1 = i; - fi = globalx2; globalx2 = -globaly2; globaly2 = -fi; - } - if (globalorientation&0x10) { globalx1 = -globalx1, globalx2 = -globalx2, globalx = -globalx; } - if (globalorientation&0x20) { globaly1 = -globaly1, globaly2 = -globaly2, globaly = -globaly; } - - float fdaz = (wx*(globalposy-wal->y)-wy*(globalposx-wal->x))*(1.f/512.f) + (daz-globalposz)*256.f; - globalx2 = (globalx2*fdaz)*(1.f/1048576.f); globalx = (globalx*fdaz)*(1.f/268435456.f); - globaly2 = (globaly2*-fdaz)*(1.f/1048576.f); globaly = (globaly*-fdaz)*(1.f/268435456.f); - - i = 8-(picsiz[globalpicnum]&15); j = 8-(picsiz[globalpicnum]>>4); - if (globalorientation&8) { i++; j++; } - globalx1 <<= (i+12); globalx2 *= 1<ceilingxpanning<<24; - globaly1 += (uint32_t)sec->ceilingypanning<<24; - } - else - { - globalx1 += (uint32_t)sec->floorxpanning<<24; - globaly1 += (uint32_t)sec->floorypanning<<24; - } - - globalx1 >>= 16; - globaly1 >>= 16; - - //asm1 = -(globalzd>>(16-BITSOFPRECISION)); - float bzinc = -globalzd*(1.f/65536.f); - - { - int32_t vis = globalvisibility; - int64_t lvis; - - if (sec->visibility != 0) vis = mulscale4(vis, (uint8_t)(sec->visibility+16)); - lvis = ((uint64_t)(vis*fdaz)) >> 13; // NOTE: lvis can be negative now! - lvis = (lvis * xdimscale) >> 16; - globvis = lvis; - } - - intptr_t fj = FP_OFF(palookup[globalpal]); - - setupslopevlin_alsotrans((picsiz[globalpicnum]&15) + ((picsiz[globalpicnum]>>4)<<8), - (intptr_t)tilePtr(globalpicnum),-ylookup[1]); - - l = Blrintf((globalzd)*(1.f/65536.f)); - - int32_t const shinc = Blrintf(globalz*xdimenscale*(1.f/65536.f)); - - shoffs = (shinc > 0) ? (4 << 15) : ((16380 - ydimen) << 15); // JBF: was 2044 - y1 = (dastat == 0) ? umost[dax1] : max(umost[dax1], dplc[dax1]); - - m1 = Blrintf((y1*globalzd)*(1.f/65536.f) + globalzx*(1.f/64.f)); - //Avoid visibility overflow by crossing horizon - m1 += klabs(l); - m2 = m1+l; - shy1 = y1+(shoffs>>15); - if ((unsigned)shy1 >= SLOPALOOKUPSIZ-1) - { - OSD_Printf("%s:%d: slopalookup[%" PRId32 "] overflow drawing sector %d!\n", EDUKE32_FUNCTION, __LINE__, shy1, sectnum); - return; - } - - mptr1 = &slopalookup[shy1]; mptr2 = mptr1+1; - - for (int x=dax1; x<=dax2; x++) - { - if (dastat == 0) { y1 = umost[x]; y2 = min(dmost[x],uplc[x])-1; } - else { y1 = max(umost[x],dplc[x]); y2 = dmost[x]-1; } - if (y1 <= y2) - { - shy1 = y1+(shoffs>>15); - shy2 = y2+(shoffs>>15); - - // Ridiculously steep gradient? - if ((unsigned)shy1 >= SLOPALOOKUPSIZ) - { - OSD_Printf("%s:%d: slopalookup[%" PRId32 "] overflow drawing sector %d!\n", EDUKE32_FUNCTION, __LINE__, shy1, sectnum); - goto next_most; - } - if ((unsigned)shy2 >= SLOPALOOKUPSIZ) - { - OSD_Printf("%s:%d: slopalookup[%" PRId32 "] overflow drawing sector %d!\n", EDUKE32_FUNCTION, __LINE__, shy2, sectnum); - goto next_most; - } - - intptr_t *nptr1 = &slopalookup[shy1]; - intptr_t *nptr2 = &slopalookup[shy2]; - - while (nptr1 <= mptr1) - { - *mptr1-- = fj + getpalookupsh(mulscale24(krecipasm(m1),globvis)); - m1 -= l; - } - while (nptr2 >= mptr2) - { - *mptr2++ = fj + getpalookupsh(mulscale24(krecipasm(m2),globvis)); - m2 += l; - } - - globalx3 = globalx2*(1.f/1024.f); - globaly3 = globaly2*(1.f/1024.f); - float bz = (y2*globalzd)*(1.f/65536.f) + globalzx*(1.f/64.f); - uint8_t *p = (uint8_t*)(ylookup[y2]+x+frameoffset); - intptr_t* A_C_RESTRICT slopalptr = (intptr_t*)nptr2; - const char* const A_C_RESTRICT trans = paletteGetBlendTable(0); - uint32_t u, v; - int cnt = y2-y1+1; -#define LINTERPSIZ 4 - int u0 = Blrintf(1048576.f*globalx3/bz); - int v0 = Blrintf(1048576.f*globaly3/bz); - switch (globalorientation&0x180) - { - case 0: - while (cnt > 0) - { - bz += bzinc*(1<>LINTERPSIZ; - v1 = (v1-v0)>>LINTERPSIZ; - int cnt2 = min(cnt, 1<0; cnt2--) - { - u = (globalx1+u0)&0xffff; - v = (globaly1+v0)&0xffff; - *p = *(uint8_t *)(((intptr_t)slopalptr[0])+ggbuf[((u>>(16-gglogx))<>(16-gglogy))]); - slopalptr--; - p += ggpinc; - u0 += u1; - v0 += v1; - } - cnt -= 1< 0) - { - bz += bzinc*(1<>LINTERPSIZ; - v1 = (v1-v0)>>LINTERPSIZ; - int cnt2 = min(cnt, 1<0; cnt2--) - { - u = (globalx1+u0)&0xffff; - v = (globaly1+v0)&0xffff; - uint8_t ch = ggbuf[((u>>(16-gglogx))<>(16-gglogy))]; - if (ch != 255) - *p = *(uint8_t *)(((intptr_t)slopalptr[0])+ch); - slopalptr--; - p += ggpinc; - u0 += u1; - v0 += v1; - } - cnt -= 1< 0) - { - bz += bzinc*(1<>LINTERPSIZ; - v1 = (v1-v0)>>LINTERPSIZ; - int cnt2 = min(cnt, 1<0; cnt2--) - { - u = (globalx1+u0)&0xffff; - v = (globaly1+v0)&0xffff; - uint8_t ch = ggbuf[((u>>(16-gglogx))<>(16-gglogy))]; - if (ch != 255) - { - ch = *(uint8_t *)(((intptr_t)slopalptr[0])+ch); - *p = trans[(*p<<8)|ch]; - } - slopalptr--; - p += ggpinc; - u0 += u1; - v0 += v1; - } - cnt -= 1< 0) - { - bz += bzinc*(1<>LINTERPSIZ; - v1 = (v1-v0)>>LINTERPSIZ; - int cnt2 = min(cnt, 1<0; cnt2--) - { - u = (globalx1+u0)&0xffff; - v = (globaly1+v0)&0xffff; - uint8_t ch = ggbuf[((u>>(16-gglogx))<>(16-gglogy))]; - if (ch != 255) - { - ch = *(uint8_t *)(((intptr_t)slopalptr[0])+ch); - *p = trans[ch<<8|*p]; - } - slopalptr--; - p += ggpinc; - u0 += u1; - v0 += v1; - } - cnt -= 1<ceilingstat; - globalpicnum = sec->ceilingpicnum; - globalshade = sec->ceilingshade; - globalpal = sec->ceilingpal; - daslope = sec->ceilingheinum; - daz = sec->ceilingz; - } - else - { - if (globalposz >= getflorzofslope(sectnum,globalposx,globalposy)) - return; //Back-face culling - globalorientation = sec->floorstat; - globalpicnum = sec->floorpicnum; - globalshade = sec->floorshade; - globalpal = sec->floorpal; - daslope = sec->floorheinum; - daz = sec->floorz; - } - - tileUpdatePicnum(&globalpicnum, sectnum); - setgotpic(globalpicnum); - if ((tilesiz[globalpicnum].x <= 0) || (tilesiz[globalpicnum].y <= 0)) return; - tileLoad(globalpicnum); - - - wal = (uwallptr_t)&wall[sec->wallptr]; - wx = wall[wal->point2].x - wal->x; - wy = wall[wal->point2].y - wal->y; - dasqr = krecipasm(nsqrtasm(uhypsq(wx,wy))); - i = mulscale21(daslope,dasqr); - wx *= i; wy *= i; - - globalx = -mulscale19(singlobalang,xdimenrecip); - globaly = mulscale19(cosglobalang,xdimenrecip); - globalx1 = (globalposx<<8); - globaly1 = -(globalposy<<8); - i = (dax1-halfxdimen)*xdimenrecip; - globalx2 = mulscale16(cosglobalang<<4,viewingrangerecip) - mulscale27(singlobalang,i); - globaly2 = mulscale16(singlobalang<<4,viewingrangerecip) + mulscale27(cosglobalang,i); - globalzd = decltype(globalzd)(xdimscale)<<9; - globalzx = -dmulscale17(wx,globaly2,-wy,globalx2) + mulscale10(1-globalhoriz,globalzd); - globalz = -dmulscale25(wx,globaly,-wy,globalx); - - if (globalorientation&64) //Relative alignment - { - dx = mulscale14(wall[wal->point2].x-wal->x,dasqr); - dy = mulscale14(wall[wal->point2].y-wal->y,dasqr); - - i = nsqrtasm(daslope*daslope+16777216); - - x = globalx; y = globaly; - globalx = dmulscale16(x,dx,y,dy); - globaly = mulscale12(dmulscale16(-y,dx,x,dy),i); - - x = ((wal->x-globalposx)<<8); y = ((wal->y-globalposy)<<8); - globalx1 = dmulscale16(-x,dx,-y,dy); - globaly1 = mulscale12(dmulscale16(-y,dx,x,dy),i); - - x = globalx2; y = globaly2; - globalx2 = dmulscale16(x,dx,y,dy); - globaly2 = mulscale12(dmulscale16(-y,dx,x,dy),i); - } - if (globalorientation&0x4) - { - i = globalx; globalx = -globaly; globaly = -i; - i = globalx1; globalx1 = globaly1; globaly1 = i; - i = globalx2; globalx2 = -globaly2; globaly2 = -i; - } - if (globalorientation&0x10) { globalx1 = -globalx1, globalx2 = -globalx2, globalx = -globalx; } - if (globalorientation&0x20) { globaly1 = -globaly1, globaly2 = -globaly2, globaly = -globaly; } - - daz = dmulscale9(wx,globalposy-wal->y,-wy,globalposx-wal->x) + ((daz-globalposz)<<8); - globalx2 = mulscale20(globalx2,daz); globalx = mulscale28(globalx,daz); - globaly2 = mulscale20(globaly2,-daz); globaly = mulscale28(globaly,-daz); - - i = 8-(picsiz[globalpicnum]&15); j = 8-(picsiz[globalpicnum]>>4); - if (globalorientation&8) { i++; j++; } - globalx1 <<= (i+12); globalx2 <<= i; globalx <<= i; - globaly1 <<= (j+12); globaly2 <<= j; globaly <<= j; - - if (dastat == 0) - { - globalx1 += (uint32_t)sec->ceilingxpanning<<24; - globaly1 += (uint32_t)sec->ceilingypanning<<24; - } - else - { - globalx1 += (uint32_t)sec->floorxpanning<<24; - globaly1 += (uint32_t)sec->floorypanning<<24; - } - - asm1 = -(globalzd>>(16-BITSOFPRECISION)); - - { - int32_t vis = globalvisibility; - int64_t lvis; - - if (sec->visibility != 0) vis = mulscale4(vis, (uint8_t)(sec->visibility+16)); - lvis = ((uint64_t)vis*daz) >> 13; // NOTE: lvis can be negative now! - lvis = (lvis * xdimscale) >> 16; - globvis = lvis; - } - - j = FP_OFF(palookup[globalpal]); - - setupslopevlin_alsotrans((picsiz[globalpicnum]&15) + ((picsiz[globalpicnum]>>4)<<8), - (intptr_t)tilePtr(globalpicnum),-ylookup[1]); - - l = (globalzd>>16); - - int32_t const shinc = mulscale16(globalz,xdimenscale); - - shoffs = (shinc > 0) ? (4 << 15) : ((16380 - ydimen) << 15); // JBF: was 2044 - y1 = (dastat == 0) ? umost[dax1] : max(umost[dax1], dplc[dax1]); - - m1 = mulscale16(y1,globalzd) + (globalzx>>6); - //Avoid visibility overflow by crossing horizon - m1 += klabs((int32_t) (globalzd>>16)); - m2 = m1+l; - shy1 = y1+(shoffs>>15); - if ((unsigned)shy1 >= SLOPALOOKUPSIZ - 1) - { - OSD_Printf("%s:%d: slopalookup[%" PRId32 "] overflow drawing sector %d!\n", EDUKE32_FUNCTION, __LINE__, shy1, sectnum); - return; - } - - mptr1 = &slopalookup[shy1]; mptr2 = mptr1+1; - - for (x=dax1; x<=dax2; x++) - { - if (dastat == 0) { y1 = umost[x]; y2 = min(dmost[x],uplc[x])-1; } - else { y1 = max(umost[x],dplc[x]); y2 = dmost[x]-1; } - if (y1 <= y2) - { - shy1 = y1+(shoffs>>15); - shy2 = y2+(shoffs>>15); - - // Ridiculously steep gradient? - if ((unsigned)shy1 >= SLOPALOOKUPSIZ) - { - OSD_Printf("%s:%d: slopalookup[%" PRId32 "] overflow drawing sector %d!\n", EDUKE32_FUNCTION, __LINE__, shy1, sectnum); - goto next_most; - } - if ((unsigned)shy2 >= SLOPALOOKUPSIZ) - { - OSD_Printf("%s:%d: slopalookup[%" PRId32 "] overflow drawing sector %d!\n", EDUKE32_FUNCTION, __LINE__, shy2, sectnum); - goto next_most; - } - - intptr_t *nptr1 = &slopalookup[shy1]; - intptr_t *nptr2 = &slopalookup[shy2]; - - while (nptr1 <= mptr1) - { - *mptr1-- = j + getpalookupsh(mulscale24(krecipasm(m1),globvis)); - m1 -= l; - } - while (nptr2 >= mptr2) - { - *mptr2++ = j + getpalookupsh(mulscale24(krecipasm(m2),globvis)); - m2 += l; - } - - globalx3 = (globalx2>>10); - globaly3 = (globaly2>>10); - asm3 = mulscale16(y2,globalzd) + (globalzx>>6); - switch (globalorientation&0x180) - { - case 0: - slopevlin(ylookup[y2]+x+frameoffset,krecipasm(asm3>>3),(intptr_t)nptr2,y2-y1+1,globalx1,globaly1); - break; - case 128: - mslopevlin((uint8_t *)(ylookup[y2]+x+frameoffset),nptr2,y2-y1+1,globalx1,globaly1); - break; - case 256: - case 384: - tslopevlin((uint8_t *)(ylookup[y2]+x+frameoffset),nptr2,y2-y1+1,globalx1,globaly1); - break; - } - - if ((x&15) == 0) faketimerhandler(); - } -next_most: - globalx2 += globalx; - globaly2 += globaly; - globalzx += globalz; - shoffs += shinc; - } -} - - -// -// parascan (internal) -// -static void parascan(char dastat, int32_t bunch) -{ - int32_t j, k, l, m, n, x, z, wallnum, nextsectnum, globalhorizbak; - int16_t *topptr, *botptr; - - int32_t logtilesizy, tsizy; - - int32_t sectnum = thesector[bunchfirst[bunch]]; - auto const sec = (usectorptr_t)§or[sectnum]; - - globalhorizbak = globalhoriz; - globvis = globalpisibility; - //globalorientation = 0L; - if (sec->visibility != 0) - globvis = mulscale4(globvis, (uint8_t)(sec->visibility+16)); - - if (dastat == 0) - { - globalpal = sec->ceilingpal; - globalpicnum = sec->ceilingpicnum; - globalshade = (int32_t)sec->ceilingshade; - globalxpanning = (int32_t)sec->ceilingxpanning; - globalypanning = (int32_t)sec->ceilingypanning; - topptr = umost.Data(); - botptr = uplc.Data(); - } - else - { - globalpal = sec->floorpal; - globalpicnum = sec->floorpicnum; - globalshade = (int32_t)sec->floorshade; - globalxpanning = (int32_t)sec->floorxpanning; - globalypanning = (int32_t)sec->floorypanning; - topptr = dplc.Data(); - botptr = dmost.Data(); - } - - if ((unsigned)globalpicnum >= MAXTILES) globalpicnum = 0; - tileUpdatePicnum(&globalpicnum, sectnum); - setgotpic(globalpicnum); - - logtilesizy = (picsiz[globalpicnum]>>4); - tsizy = tilesiz[globalpicnum].y; - - if (tsizy==0) - return; - - - int32_t dapyscale, dapskybits, dapyoffs, daptileyscale; - int8_t const * const dapskyoff = getpsky(globalpicnum, &dapyscale, &dapskybits, &dapyoffs, &daptileyscale); - - globalshiftval = logtilesizy; - - // before proper non-power-of-two tilesizy drawing - if (oldnonpow2() && pow2long[logtilesizy] != tsizy) - globalshiftval++; -#ifdef CLASSIC_NONPOW2_YSIZE_WALLS - // non power-of-two y size textures! - if ((!oldnonpow2() && pow2long[logtilesizy] != tsizy) || tsizy >= 512) - { - globaltilesizy = tsizy; - globalyscale = 65536 / tsizy; - globalshiftval = 0; - globalzd = divscale32(((tsizy>>1)+dapyoffs), tsizy) + ((uint32_t)globalypanning<<24); - } - else -#endif - { - globalshiftval = 32-globalshiftval; - globalyscale = (8<<(globalshiftval-19)); - globalzd = (decltype(globalzd)((tsizy >> 1) + dapyoffs) << globalshiftval) + (decltype(globalzd)(globalypanning) << 24); - } - globalyscale = divscale16(globalyscale,daptileyscale); - - //if (globalorientation&256) globalyscale = -globalyscale, globalzd = -globalzd; - - if (dapyscale != 65536) - globalhoriz = mulscale16(globalhoriz-(ydimen>>1),dapyscale) + (ydimen>>1); - - k = 27 - (picsiz[globalpicnum]&15) - dapskybits; - - // WGR2 SVN: select new episode after playing wgmicky1 with Polymer - // (maybe switched to classic earlier). - // --> rendmode==0, glrendermode == REND_POLYMER, we end up with globalpicnum==266, - // picsiz...==9 and dapskybits==3 - // FIXME ? - if (k < 0) - k = 0; - - x = -1; - - for (z=bunchfirst[bunch]; z>=0; z=bunchp2[z]) - { - wallnum = thewall[z]; nextsectnum = wall[wallnum].nextsector; - - if (nextsectnum >= 0) //else negative array access - { - if (dastat == 0) j = sector[nextsectnum].ceilingstat; - else j = sector[nextsectnum].floorstat; - } - - if ((nextsectnum < 0) || (wall[wallnum].cstat&32) || ((j&1) == 0)) - { - if (x == -1) x = xb1[z]; - - if (parallaxtype == 0 || no_radarang2) - { - n = mulscale16(xdimenrecip,viewingrange); - for (j=xb1[z]; j<=xb2[z]; j++) - lplc[j] = ((mulscale7(j-halfxdimen,n)+qglobalang)&0x7FFFFFF)>>k; - } - else - { - for (j=xb1[z]; j<=xb2[z]; j++) - lplc[j] = ((radarang2[j]+qglobalang)&0x7FFFFFF)>>k; - } - - if (parallaxtype == 2 && !no_radarang2) - { - n = mulscale16(xdimscale,viewingrange); - for (j=xb1[z]; j<=xb2[z]; j++) - swplc[j] = mulscale14(sintable[((radarang2[j]>>16)+512)&2047],n); - } - else - clearbuf(&swplc[xb1[z]],xb2[z]-xb1[z]+1,mulscale16(xdimscale,viewingrange)); - } - else if (x >= 0) - { - l = globalpicnum; m = (picsiz[globalpicnum]&15); - globalpicnum = l + dapskyoff[lplc[x]>>m]; - - if (((lplc[x]^lplc[xb1[z]-1])>>m) == 0) - wallscan(x,xb1[z]-1,topptr,botptr,swplc.Data(),lplc.Data()); - else - { - j = x; - while (x < xb1[z]) - { - n = l + dapskyoff[lplc[x]>>m]; - if (n != globalpicnum) - { - wallscan(j,x-1,topptr,botptr,swplc.Data(),lplc.Data()); - j = x; - globalpicnum = n; - } - x++; - } - if (j < x) - wallscan(j,x-1,topptr,botptr,swplc.Data(),lplc.Data()); - } - - globalpicnum = l; - x = -1; - } - } - - if (x >= 0) - { - l = globalpicnum; m = (picsiz[globalpicnum]&15); - globalpicnum = l + dapskyoff[lplc[x]>>m]; - - if (((lplc[x]^lplc[xb2[bunchlast[bunch]]])>>m) == 0) - wallscan(x,xb2[bunchlast[bunch]],topptr,botptr,swplc.Data(),lplc.Data()); - else - { - j = x; - while (x <= xb2[bunchlast[bunch]]) - { - n = l + dapskyoff[lplc[x]>>m]; - if (n != globalpicnum) - { - wallscan(j,x-1,topptr,botptr,swplc.Data(),lplc.Data()); - j = x; - globalpicnum = n; - } - x++; - } - if (j <= x) - wallscan(j,x-1,topptr,botptr,swplc.Data(),lplc.Data()); - } - globalpicnum = l; - } - globalhoriz = globalhorizbak; -} - - -// set orientation, panning, shade, pal; picnum -static void setup_globals_wall1(uwallptr_t wal, int32_t dapicnum) -{ - globalorientation = wal->cstat; - - globalpicnum = dapicnum; - if ((unsigned)globalpicnum >= MAXTILES) globalpicnum = 0; - tileUpdatePicnum(&globalpicnum, 16384); - - globalxpanning = wal->xpanning; - globalypanning = wal->ypanning; - - globalshade = wal->shade; - globalpal = wal->pal; - if (palookup[globalpal] == NULL) globalpal = 0; // JBF: fixes crash -} - -static void setup_globals_wall2(uwallptr_t wal, uint8_t secvisibility, int32_t topzref, int32_t botzref) -{ - const int32_t logtilesizy = (picsiz[globalpicnum]>>4); - const int32_t tsizy = tilesiz[globalpicnum].y; - - if (tsizy==0) - { - globalshiftval = -1; - return; - } - - globvis = globalvisibility; - if (secvisibility != 0) - globvis = mulscale4(globvis, (uint8_t)(secvisibility+16)); - - globalshiftval = logtilesizy; - - // before proper non-power-of-two tilesizy drawing - if (oldnonpow2() && pow2long[logtilesizy] != tsizy) - globalshiftval++; -#ifdef CLASSIC_NONPOW2_YSIZE_WALLS - // non power-of-two y size textures! - if ((!oldnonpow2() && pow2long[logtilesizy] != tsizy) || tsizy >= 512) - { - globaltilesizy = tsizy; - globalyscale = divscale13(wal->yrepeat, tsizy); - globalshiftval = 0; - } - else -#endif - { - // globalshiftval==13 --> globalshiftval==19 - // ==> upper texture y size limit *here* = 8192 - globalshiftval = 32-globalshiftval; - globalyscale = wal->yrepeat<<(globalshiftval-19); - } - - if ((globalorientation&4) == 0) - globalzd = (((int64_t)(globalposz-topzref)*globalyscale)<<8); - else // bottom-aligned - globalzd = (((int64_t)(globalposz-botzref)*globalyscale)<<8); - - globalzd += decltype(globalzd)(globalypanning) << 24; - - if (globalorientation&256) // y-flipped - globalyscale = -globalyscale, globalzd = -(inthi_t)globalzd; -} - - -/* _______________ - * X umost ####### - * ###### ________ - * ______/ - * X dwall - * - * ________ - * X uwall \______ - * /////////////// - * _______________ - * X dmost - */ - -#ifdef YAX_ENABLE -// returns: should dmost be raised when drawing a "ceiling wall"? -static int32_t should_clip_cwall(int32_t x1, int32_t x2) -{ - int32_t x; - - if (yax_globallev <= YAX_MAXDRAWS) - return 1; - - for (x=x1; x<=x2; x++) - if (dwall[x] < dmost[x] || uplc[x] < dmost[x]) - return 1; - - return 0; -} - -// returns: should umost be lowered when drawing a "floor wall"? -static int32_t should_clip_fwall(int32_t x1, int32_t x2) -{ - int32_t x; - - if (yax_globallev >= YAX_MAXDRAWS) - return 1; - - for (x=x1; x<=x2; x++) - if (uwall[x] > umost[x] || dplc[x] > umost[x]) - return 1; - - return 0; -} -#endif - -// -// drawalls (internal) -// -static void classicDrawBunches(int32_t bunch) -{ - int32_t i, x; - - int32_t z = bunchfirst[bunch]; - - const int32_t sectnum = thesector[z]; - auto const sec = (usectorptr_t)§or[sectnum]; - - uint8_t andwstat1 = 0xff, andwstat2 = 0xff; - - for (; z>=0; z=bunchp2[z]) //uplc/dplc calculation - { - andwstat1 &= wallmost(uplc.Data(),z,sectnum,(uint8_t)0); - andwstat2 &= wallmost(dplc.Data(),z,sectnum,(uint8_t)1); - } - -#ifdef YAX_ENABLE - if (g_nodraw) - { - int32_t baselevp, checkcf; - int16_t bn[2]; -# if 0 - int32_t obunchchk = (1 && yax_globalbunch>=0 && - haveymost[yax_globalbunch>>3]&pow2char[yax_globalbunch&7]); - - // if (obunchchk) - const int32_t x2 = yax_globalbunch*xdimen; -# endif - baselevp = (yax_globallev == YAX_MAXDRAWS); - - yax_getbunches(sectnum, &bn[0], &bn[1]); - checkcf = (bn[0]>=0) + ((bn[1]>=0)<<1); - if (!baselevp) - checkcf &= (1<>3]&pow2char[bn[i]&7])==0) - { - // init yax *most arrays for that bunch - haveymost[bn[i]>>3] |= pow2char[bn[i]&7]; - for (x=xdimen*bn[i]; xceilingstat&256)==0 || - yax_nomaskpass==1 || !(yax_gotsector[sectnum>>3]&pow2char[sectnum&7])) -#endif - { - if ((sec->ceilingstat&3) == 2) - grouscan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum,0); - else if ((sec->ceilingstat&1) == 0) - ceilscan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum); - else - parascan(0,bunch); - } - - if ((andwstat2&12) != 12) //draw floors -#ifdef YAX_ENABLE - // this is to prevent double-drawing of translucent masked floors - if (r_tror_nomaskpass==0 || yax_globallev==YAX_MAXDRAWS || (sec->floorstat&256)==0 || - yax_nomaskpass==1 || !(yax_gotsector[sectnum>>3]&pow2char[sectnum&7])) -#endif - { - if ((sec->floorstat&3) == 2) - grouscan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum,1); - else if ((sec->floorstat&1) == 0) - florscan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum); - else - parascan(1,bunch); - } - } - - - //DRAW WALLS SECTION! - for (z=bunchfirst[bunch]; z>=0; z=bunchp2[z]) - { - const int32_t x1 = xb1[z], x2 = xb2[z]; - - if (umost[x2] >= dmost[x2]) - { - for (x=x1; x= x2) - { - smostwall[smostwallcnt] = z; - smostwalltype[smostwallcnt] = 0; - smostwallcnt++; - continue; - } - } - - const int32_t wallnum = thewall[z]; - auto const wal = (uwallptr_t)&wall[wallnum]; - - const int32_t nextsectnum = wal->nextsector; - auto const nextsec = nextsectnum>=0 ? (usectorptr_t)§or[nextsectnum] : NULL; - - int32_t gotswall = 0; - - const int32_t startsmostwallcnt = smostwallcnt; - const int32_t startsmostcnt = smostcnt; - - if (searchit == 2 && (searchx >= x1 && searchx <= x2)) - { - if (searchy <= uplc[searchx] -#ifdef YAX_ENABLE - && umost[searchx] <= searchy && getceilzofslope(sectnum, globalposx, globalposy) <= globalposz - && (yax_getbunch(sectnum, YAX_CEILING) < 0 || showinvisibility || (sec->ceilingstat&(256+128)) || klabs(yax_globallev-YAX_MAXDRAWS)==YAX_MAXDRAWS) -#endif - ) //ceiling - { - searchsector = sectnum; searchwall = wallnum; - searchstat = 1; searchit = 1; - } - else if (dplc[searchx] <= searchy -#ifdef YAX_ENABLE - && searchy < dmost[searchx] && getflorzofslope(sectnum, globalposx, globalposy) >= globalposz - && (yax_getbunch(sectnum, YAX_FLOOR) < 0 || showinvisibility || (sec->floorstat&(256+128)) || klabs(yax_globallev-YAX_MAXDRAWS)==YAX_MAXDRAWS) -#endif - ) //floor - { - searchsector = sectnum; searchwall = wallnum; - searchstat = 2; searchit = 1; - } - } - -#ifdef YAX_ENABLE - if (yax_nomaskpass==0 || !yax_isislandwall(wallnum, !yax_globalcf) || (yax_nomaskdidit=1, 0)) -#endif - if (nextsectnum >= 0) - { - // 2 <--- 3 - // x------------------x - // 0 ---> 1 - // - // 4 (our pos, z wrt the nextsector!) - - int32_t cz[5], fz[5]; - - getzsofslope((int16_t)sectnum,wal->x,wal->y,&cz[0],&fz[0]); - getzsofslope((int16_t)sectnum,wall[wal->point2].x,wall[wal->point2].y,&cz[1],&fz[1]); - getzsofslope((int16_t)nextsectnum,wal->x,wal->y,&cz[2],&fz[2]); - getzsofslope((int16_t)nextsectnum,wall[wal->point2].x,wall[wal->point2].y,&cz[3],&fz[3]); - getzsofslope((int16_t)nextsectnum,globalposx,globalposy,&cz[4],&fz[4]); - - if ((wal->cstat&48) == 16) - maskwall[maskwallcnt++] = z; - - if (((sec->ceilingstat&1) == 0) || ((nextsec->ceilingstat&1) == 0)) - { - if ((cz[2] <= cz[0]) && (cz[3] <= cz[1])) - { -// if (globparaceilclip) - if (getceilzofslope(sectnum, globalposx, globalposy) <= globalposz) - for (x=x1; x<=x2; x++) - if (uplc[x] > umost[x]) - if (umost[x] <= dmost[x]) - { - umost[x] = uplc[x]; - if (umost[x] > dmost[x]) numhits--; - } - } - else - { - wallmost(dwall.Data(),z,nextsectnum,(uint8_t)0); - - if ((cz[2] > fz[0]) || (cz[3] > fz[1])) - for (i=x1; i<=x2; i++) if (dwall[i] > dplc[i]) dwall[i] = dplc[i]; - - if (searchit == 2 && (searchx >= x1 && searchx <= x2)) -#ifdef YAX_ENABLE - if (uplc[searchx] <= searchy) -#endif - if (searchy <= dwall[searchx]) //wall - { - searchsector = sectnum; searchbottomwall = searchwall = wallnum; - searchisbottom = 0; - searchstat = 0; searchit = 1; - } - - setup_globals_wall1(wal, wal->picnum); - setup_globals_wall2(wal, sec->visibility, nextsec->ceilingz, sec->ceilingz); - - gotswall = 1; - prepwall(z,wal); - wallscan(x1,x2,uplc.Data(),dwall.Data(),swall.Data(),lwall.Data()); - - if ((cz[2] >= cz[0]) && (cz[3] >= cz[1])) - { -#ifdef YAX_ENABLE - if (should_clip_cwall(x1, x2)) -#endif - for (x=x1; x<=x2; x++) - if (dwall[x] > umost[x]) - if (umost[x] <= dmost[x]) - { - umost[x] = dwall[x]; - if (umost[x] > dmost[x]) numhits--; - } - } - else - { -#ifdef YAX_ENABLE - if (should_clip_cwall(x1, x2)) -#endif - for (x=x1; x<=x2; x++) - if (umost[x] <= dmost[x]) - { - i = max(uplc[x],dwall[x]); - if (i > umost[x]) - { - umost[x] = i; - if (umost[x] > dmost[x]) numhits--; - } - } - } - } - - if ((cz[2] < cz[0]) || (cz[3] < cz[1]) || (globalposz < cz[4])) - { - i = x2-x1+1; - if (smostcnt+i < ysavecnt) - { - smoststart[smostwallcnt] = smostcnt; - smostwall[smostwallcnt] = z; - smostwalltype[smostwallcnt] = 1; //1 for umost - smostwallcnt++; - copybufbyte(&umost[x1],&smost[smostcnt],i*sizeof(smost[0])); - smostcnt += i; - } - } - } - - if (((sec->floorstat&1) == 0) || ((nextsec->floorstat&1) == 0)) - { - if ((fz[2] >= fz[0]) && (fz[3] >= fz[1])) - { -// if (globparaflorclip) - if (getflorzofslope(sectnum, globalposx, globalposy) >= globalposz) - for (x=x1; x<=x2; x++) - if (dplc[x] < dmost[x]) - if (umost[x] <= dmost[x]) - { - dmost[x] = dplc[x]; - if (umost[x] > dmost[x]) numhits--; - } - } - else - { - wallmost(uwall.Data(),z,nextsectnum,(uint8_t)1); - - if ((fz[2] < cz[0]) || (fz[3] < cz[1])) - for (i=x1; i<=x2; i++) if (uwall[i] < uplc[i]) uwall[i] = uplc[i]; - - if (searchit == 2 && (searchx >= x1 && searchx <= x2)) -#ifdef YAX_ENABLE - if (dplc[searchx] >= searchy) -#endif - if (searchy >= uwall[searchx]) //wall - { - searchsector = sectnum; searchbottomwall = searchwall = wallnum; - if ((wal->cstat&2) > 0) searchbottomwall = wal->nextwall; - searchisbottom = 1; - searchstat = 0; searchit = 1; - } - - auto const twal = (wal->cstat&2) ? (uwallptr_t)&wall[wal->nextwall] : wal; - setup_globals_wall1(twal, twal->picnum); - - setup_globals_wall2(wal, sec->visibility, nextsec->floorz, sec->ceilingz); - - if (gotswall == 0) { gotswall = 1; prepwall(z,wal); } - wallscan(x1,x2,uwall.Data(),dplc.Data(),swall.Data(),lwall.Data()); - - if ((fz[2] <= fz[0]) && (fz[3] <= fz[1])) - { -#ifdef YAX_ENABLE - if (should_clip_fwall(x1, x2)) -#endif - for (x=x1; x<=x2; x++) - if (uwall[x] < dmost[x] && umost[x] <= dmost[x]) - { - dmost[x] = uwall[x]; - if (umost[x] > dmost[x]) numhits--; - } - } - else - { -#ifdef YAX_ENABLE - if (should_clip_fwall(x1, x2)) -#endif - for (x=x1; x<=x2; x++) - if (umost[x] <= dmost[x]) - { - i = min(dplc[x],uwall[x]); - if (i < dmost[x]) - { - dmost[x] = i; - if (umost[x] > dmost[x]) numhits--; - } - } - } - } - - if ((fz[2] > fz[0]) || (fz[3] > fz[1]) || (globalposz > fz[4])) - { - i = x2-x1+1; - if (smostcnt+i < ysavecnt) - { - smoststart[smostwallcnt] = smostcnt; - smostwall[smostwallcnt] = z; - smostwalltype[smostwallcnt] = 2; //2 for dmost - smostwallcnt++; - copybufbyte(&dmost[x1],&smost[smostcnt],i*sizeof(smost[0])); - smostcnt += i; - } - } - } - - if (numhits < 0) - return; - - if (!(wal->cstat&32) && (gotsector[nextsectnum>>3]&pow2char[nextsectnum&7]) == 0) - { - if (umost[x2] < dmost[x2]) - classicScanSector(nextsectnum); - else - { - for (x=x1; xcstat&32)) //White/1-way wall - { - setup_globals_wall1(wal, (nextsectnum < 0) ? wal->picnum : wal->overpicnum); - setup_globals_wall2(wal, sec->visibility, - (nextsectnum >= 0) ? nextsec->ceilingz : sec->ceilingz, - (nextsectnum >= 0) ? sec->ceilingz : sec->floorz); - - if (gotswall == 0) { gotswall = 1; prepwall(z,wal); } - wallscan(x1,x2,uplc.Data(),dplc.Data(),swall.Data(),lwall.Data()); - -#ifdef YAX_ENABLE - // TODO: slopes? - - if (globalposz > sec->floorz && yax_isislandwall(wallnum, YAX_FLOOR)) - { - for (x=x1; x<=x2; x++) - if (dplc[x] > umost[x] && umost[x] <= dmost[x]) - { - umost[x] = dplc[x]; - if (umost[x] > dmost[x]) numhits--; - } - } - else if (globalposz < sec->ceilingz && yax_isislandwall(wallnum, YAX_CEILING)) - { - for (x=x1; x<=x2; x++) - if (uplc[x] < dmost[x] && umost[x] <= dmost[x]) - { - dmost[x] = uplc[x]; - if (umost[x] > dmost[x]) numhits--; - } - } - else -#endif - for (x=x1; x<=x2; x++) - if (umost[x] <= dmost[x]) - { umost[x] = 1; dmost[x] = 0; numhits--; } - smostwall[smostwallcnt] = z; - smostwalltype[smostwallcnt] = 0; - smostwallcnt++; - - if (searchit == 2 && (x1 <= searchx && searchx <= x2)) -#ifdef YAX_ENABLE - if (uplc[searchx] <= searchy && searchy < dplc[searchx]) -#endif - { - searchit = 1; searchsector = sectnum; - searchbottomwall = searchwall = wallnum; - searchstat = (nextsectnum < 0) ? 0 : 4; - } - } - } -} - -// High-precision integer type for view-relative x and y in drawvox(). -typedef zint_t voxint_t; - -// -// drawvox -// -static void classicDrawVoxel(int32_t dasprx, int32_t daspry, int32_t dasprz, int32_t dasprang, - int32_t daxscale, int32_t dayscale, int32_t daindex, - int8_t dashade, char dapal, const int32_t *daumost, const int32_t *dadmost, - const int8_t cstat, const int32_t clipcf, int32_t floorz, int32_t ceilingz) -{ - int32_t i, j, k, x, y, mip; - - int32_t cosang = cosglobalang; - int32_t sinang = singlobalang; - int32_t sprcosang = sintable[(dasprang+512)&2047]; - int32_t sprsinang = sintable[dasprang&2047]; - - i = klabs(dmulscale6(dasprx-globalposx, cosang, daspry-globalposy, sinang)); - j = getpalookup(mulscale21(globvis,i), dashade)<<8; - 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; - - mip = 0; - - if (novoxmips) - { - mip = i; - i = 0; - } - - char *davoxptr = (char *)voxoff[daindex][i]; - if (!davoxptr && i > 0) { davoxptr = (char *)voxoff[daindex][0]; mip = i; i = 0;} - if (!davoxptr) - return; - - if (voxscale[daindex] == 65536) - { daxscale <<= (i+8); dayscale <<= (i+8); } - else - { - daxscale = mulscale8(daxscale<>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); - - x = (dasprx-globalposx) - dmulscale18(daxpivot,sprcosang, daypivot,-sprsinang); - y = (daspry-globalposy) - dmulscale18(daypivot,sprcosang, daxpivot,sprsinang); - - cosang <<= 2; - sinang <<= 2; - - cosang >>= mip; - sinang >>= mip; - - const voxint_t gxstart = (voxint_t)y*cosang - (voxint_t)x*sinang; - const voxint_t gystart = (voxint_t)x*cosang + (voxint_t)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++) - { - ggxinc[i] = x; x += gxinc; - ggyinc[i] = y; y += gyinc; - } - - if ((klabs(globalposz-dasprz)>>10) >= klabs(odayscale)) - return; - - int32_t zoff = dazsiz<<14; - if (!(cstat & 128)) - zoff += dazpivot<<7; - else if ((cstat&48) != 48) - { - zoff += dazpivot<<7; - zoff -= dazsiz<<14; - } - - const int32_t syoff = divscale21(globalposz-dasprz,odayscale)+zoff; - floorz = min(floorz, dasprz+mulscale21(-zoff+(dazsiz<<15),odayscale)); - ceilingz = max(ceilingz, dasprz+mulscale21(-zoff, odayscale)); - const int32_t flooroff = divscale21(floorz-globalposz,odayscale); - const int32_t ceilingoff = divscale21(ceilingz-globalposz,odayscale); - int32_t yoff = (klabs(gxinc)+klabs(gyinc))>>1; - longptr = (int32_t *)davoxptr; - int32_t xyvoxoffs = (daxsiz+1)<<2; - - videoBeginDrawing(); //{{{ - - for (bssize_t cnt=0; cnt<8; cnt++) - { - int32_t xs=0, ys=0, xi=0, yi=0; - - switch (cnt) - { - case 0: - xs = 0; ys = 0; xi = 1; yi = 1; break; - case 1: - xs = daxsiz-1; ys = 0; xi = -1; yi = 1; break; - case 2: - xs = 0; ys = daysiz-1; xi = 1; yi = -1; break; - case 3: - xs = daxsiz-1; ys = daysiz-1; xi = -1; yi = -1; break; - case 4: - xs = 0; ys = cbacky; xi = 1; yi = 2; break; - case 5: - xs = daxsiz-1; ys = cbacky; xi = -1; yi = 2; break; - case 6: - xs = cbackx; ys = 0; xi = 2; yi = 1; break; - case 7: - xs = cbackx; ys = daysiz-1; xi = 2; yi = -1; break; - } - - int32_t xe = cbackx, ye = cbacky; - - if (cnt < 4) - { - if ((xi < 0) && (xe >= xs)) continue; - if ((xi > 0) && (xe <= xs)) continue; - if ((yi < 0) && (ye >= ys)) continue; - if ((yi > 0) && (ye <= ys)) continue; - } - else - { - if ((xi < 0) && (xe > xs)) continue; - if ((xi > 0) && (xe < xs)) continue; - if ((yi < 0) && (ye > ys)) continue; - if ((yi > 0) && (ye < ys)) continue; - xe += xi; ye += yi; - } - - 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: - case 7: - x1 = 0; y1 = 0; break; - case 8: - case 5: - x1 = gxinc; y1 = gyinc; break; - case 0: - case 3: - x1 = gyinc; y1 = -gxinc; break; - case 2: - case 1: - x1 = gxinc+gyinc; y1 = gyinc-gxinc; break; - } - switch (i) - { - case 2: - case 5: - x2 = 0; y2 = 0; break; - case 0: - case 1: - x2 = gxinc; y2 = gyinc; break; - case 8: - case 7: - x2 = gyinc; y2 = -gxinc; break; - case 6: - case 3: - x2 = gxinc+gyinc; y2 = gyinc-gxinc; break; - } - - char oand = pow2char[(xs 0) { dagxinc = gxinc; dagyinc = mulscale16(gyinc,viewingrangerecip); } - else { dagxinc = -gxinc; dagyinc = -mulscale16(gyinc,viewingrangerecip); } - - //Fix for non 90 degree viewing ranges - const int32_t nxoff = mulscale16(x2-x1,viewingrangerecip); - x1 = mulscale16(x1, viewingrangerecip); - - const voxint_t ggxstart = gxstart + ggyinc[ys]; - const voxint_t ggystart = gystart - ggxinc[ys]; - - for (x=xs; x!=xe; x+=xi) - { - const int32_t xf = (cstat & 4) ? daxsiz-1-x : x; - const intptr_t slabxoffs = (intptr_t)&davoxptr[B_LITTLE32(longptr[xf])]; - int16_t *const shortptr = (int16_t *)&davoxptr[((xf*(daysiz+1))<<1) + xyvoxoffs]; - - voxint_t nx = mulscale16z(ggxstart+ggxinc[x], viewingrangerecip) + x1; - voxint_t ny = ggystart + ggyinc[x]; - - for (y=ys; y!=ye; y+=yi,nx+=dagyinc,ny-=dagxinc) - { - 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) - // - // Also, OOB (<0?) in my amcvoxels_crash.map. - const int32_t il = clamp((ny+y1)>>14, 1, DISTRECIPSIZ-1); - int32_t lx = mulscale32(nx>>3, distrecip[il]) + halfxdimen; - if (lx < 0) - lx = 0; - - const int32_t ir = clamp((ny+y2)>>14, 1, DISTRECIPSIZ-1); - int32_t rx = mulscale32((nx+nxoff)>>3, distrecip[ir]) + halfxdimen; - if (rx > xdimen) - rx = xdimen; - - if (rx <= lx) - continue; - - rx -= lx; - - const int32_t l1 = mulscale(distrecip[clamp((ny-yoff)>>14, 1, DISTRECIPSIZ-1)], dayscale, 12+mip); - // FIXME! AMCTC RC2/beta shotgun voxel - // (e.g. training map right after M16 shooting): - const int32_t l2 = mulscale(distrecip[clamp((ny+yoff)>>14, 1, DISTRECIPSIZ-1)], dayscale, 12+mip); - int32_t cz1 = 0, cz2 = INT32_MAX; - - if (clipcf) - { - cz1 = mulscale32((ceilingoff < 0) ? l1 : l2, ceilingoff) + globalhoriz; - cz2 = mulscale32((flooroff < 0) ? l2 : l1, flooroff) + globalhoriz; - } - - for (; voxptr= 1024) - yinc = divscale16(voxptr[1], z2-z1); - else if (z2 > z1) - yinc = lowrecip[z2-z1]*voxptr[1]>>8; - - if (z1 < um) { yplc = yinc*(um-z1); z1 = um; } - else yplc = 0; - - if (cstat & 8) - yinc = -yinc; - if (cstat & 8) - yplc = ((voxptr[1])<<16) - yplc + yinc; - } - - if (z2 > dm) - z2 = dm; - z2 -= z1; - if (z2 <= 0) - continue; - - drawslab(rx, yplc, z2, yinc, (intptr_t)&voxptr[3], ylookup[z1]+lx+frameoffset); - } - } - } - } - - - videoEndDrawing(); //}}} -} - - -static void setup_globals_sprite1(tspriteptr_t tspr, usectorptr_t sec, - int32_t yspan, int32_t yoff, int32_t tilenum, - int32_t cstat, int32_t *z1ptr, int32_t *z2ptr) -{ - int32_t logtilesizy, tsizy; - int32_t z1, z2 = tspr->z - ((yoff*tspr->yrepeat)<<2); - - if (cstat&128) - { - z2 += ((yspan*tspr->yrepeat)<<1); - if (yspan&1) z2 += (tspr->yrepeat<<1); //Odd yspans - } - z1 = z2 - ((yspan*tspr->yrepeat)<<2); - - globalorientation = 0; - globalpicnum = tilenum; - if ((unsigned)globalpicnum >= MAXTILES) globalpicnum = 0; - // sprite panning - globalxpanning = (((256-spriteext[tspr->owner].xpanning)&255) * tilesiz[globalpicnum].x)>>8; - globalypanning = 0; - - globvis = globalvisibility; - if (sec->visibility != 0) globvis = mulscale4(globvis, (uint8_t)(sec->visibility+16)); - - logtilesizy = (picsiz[globalpicnum]>>4); - tsizy = tilesiz[globalpicnum].y; - - globalshiftval = logtilesizy; -#if !defined CLASSIC_NONPOW2_YSIZE_SPRITES - // before proper non-power-of-two tilesizy drawing - if (pow2long[logtilesizy] != tsizy) - globalshiftval++; -#else - // non power-of-two y size textures! - if (pow2long[logtilesizy] != tsizy || tsizy >= 512) - { - globaltilesizy = tsizy; - globalyscale = (1<<22)/(tsizy*tspr->yrepeat); - globalshiftval = 0; - } - else -#endif - { - globalshiftval = 32-globalshiftval; - globalyscale = divscale(512,tspr->yrepeat,globalshiftval-19); - } - - globalzd = ((int64_t)(globalposz-z1)*globalyscale)<<8; - if ((cstat&8) > 0) - { - globalyscale = -globalyscale; - globalzd = ((int64_t)(globalposz-z2)*globalyscale)<<8; - } - - *z1ptr = z1; - *z2ptr = z2; -} - -// -// drawsprite (internal) -// - -static size_t falpha_to_blend(float alpha, int32_t *cstatptr, uint8_t *blendptr, int32_t transbit1, int32_t transbit2) -{ - int32_t cstat = *cstatptr | transbit1; - - int32_t const twonumalphatabs = 2*numalphatabs + (numalphatabs&1); - int32_t blendidx = Blrintf(alpha * twonumalphatabs); - if (blendidx > numalphatabs) - { - blendidx = twonumalphatabs - blendidx; - cstat |= transbit2; - } - else - { - cstat &= ~transbit2; - } - - if (blendidx < 1) - return cstat&transbit2; - - // blendidx now in [1 .. numalphatabs] - - *cstatptr = cstat; - *blendptr = blendidx; - return 0; -} - -static FORCE_INLINE int32_t mulscale_triple30(int32_t a, int32_t b, int32_t c) -{ - return ((int64_t)a * b * c)>>30; -} - -static void classicDrawSprite(int32_t snum) -{ - auto const tspr = tspriteptr[snum]; - const int32_t sectnum = tspr->sectnum; - - if (sectnum < 0 || bad_tspr(tspr)) - return; - - int32_t x1, y1, x2, y2, i, j, k, x; - int32_t z, zz, z1, z2, xp1, yp1, xp2, yp2; - int32_t dax, day, dax1, dax2, y; - int32_t vtilenum = 0; - - - uint8_t blendidx = tspr->blend; - const int32_t xb = spritesxyz[snum].x; - const int32_t yp = spritesxyz[snum].y; - - const int32_t spritenum = tspr->owner; - const float alpha = spriteext[spritenum].alpha; - - auto const sec = (usectorptr_t)§or[sectnum]; - - int32_t cstat=tspr->cstat, tilenum; - - if ((cstat&48) != 48) - tileUpdatePicnum(&tspr->picnum, spritenum+32768); - - if (!(cstat&2) && alpha > 0.0f) - { - if (alpha >= 1.0f) - return; - - if (numalphatabs != 0) - { - if (falpha_to_blend(alpha, &cstat, &blendidx, 2, 512)) - return; - } - else if (alpha >= 1.f/3.f) - { - cstat |= 2; - - if (alpha >= 2.f/3.f) - cstat |= 512; - else - cstat &= ~512; - - // Blood's transparency table is inverted - if (playing_blood) - cstat ^= 512; - } - - tspr->cstat = cstat; - } - - tilenum = tspr->picnum; - - if ((cstat&48)==48) - vtilenum = tilenum; // if the game wants voxels, it gets voxels - else if ((cstat & 48) != 32 && r_voxels && tiletovox[tilenum] != -1 && spritenum != -1 && !(spriteext[spritenum].flags&SPREXT_NOTMD)) - { - vtilenum = tiletovox[tilenum]; - cstat |= 48; - } - - if ((cstat&48) != 48) - { - if (spritenum < 0 || tilesiz[tilenum].x <= 0 || tilesiz[tilenum].y <= 0) - return; - } - - if (!tspr->xrepeat || !tspr->yrepeat) - return; - - globalpal = tspr->pal; - if (palookup[globalpal] == NULL) globalpal = 0; // JBF: fixes null-pointer crash - globalshade = tspr->shade; - - if (cstat&2) - setup_blend(blendidx, cstat&512); - - vec2_t off = { picanm[tilenum].xofs + tspr->xoffset, picanm[tilenum].yofs + tspr->yoffset }; - - if ((cstat&48) == 0) - { - int32_t startum, startdm; - int32_t linum, linuminc; - -draw_as_face_sprite: - if (yp <= (4<<8)) return; - - int const isiz = divscale19(xdimenscale,yp); - int const xv = mulscale16(((int32_t)tspr->xrepeat)<<16,xyaspect); - vec2_16_t const span = tilesiz[tilenum]; - vec2_t const siz = { mulscale30(isiz, xv * span.x), mulscale14(isiz, tspr->yrepeat * span.y) }; - - if (EDUKE32_PREDICT_FALSE((span.x>>11) >= siz.x || span.y >= (siz.y>>1))) - return; //Watch out for divscale overflow - - x1 = xb-(siz.x>>1); - if (span.x&1) x1 += mulscale31(isiz,xv); //Odd xspans - i = mulscale30(isiz,xv*off.x); - if ((cstat&4) == 0) x1 -= i; else x1 += i; - - y1 = mulscale16(tspr->z-globalposz,isiz); - y1 -= mulscale14(isiz,tspr->yrepeat*off.y); - y1 += (globalhoriz<<8)-siz.y; - if (cstat&128) - { - y1 += (siz.y>>1); - if (span.y&1) y1 += mulscale15(isiz,tspr->yrepeat); //Odd yspans - } - - x2 = x1+siz.x-1; - y2 = y1+siz.y-1; - if ((y1|255) >= (y2|255)) return; - - int32_t lx = (x1>>8)+1; if (lx < 0) lx = 0; - int32_t rx = (x2>>8); if (rx >= xdimen) rx = xdimen-1; - if (lx > rx) return; - - startum = ((sec->ceilingstat&3) == 0) ? globalhoriz+mulscale24(isiz,sec->ceilingz-globalposz)-1 : 0; - startdm = ((sec->floorstat&3) == 0) ? globalhoriz+mulscale24(isiz,sec->floorz-globalposz)+1 : INT32_MAX; - - if ((y1>>8) > startum) startum = (y1>>8); - if ((y2>>8) < startdm) startdm = (y2>>8); - - if (startum < -32768) startum = -32768; - if (startdm > 32767) startdm = 32767; - if (startum >= startdm) return; - - if ((cstat&4) == 0) - { - linuminc = divscale24(span.x,siz.x); - linum = mulscale8((lx<<8)-x1,linuminc); - } - else - { - linuminc = -divscale24(span.x,siz.x); - linum = mulscale8((lx<<8)-x2,linuminc); - } - - if ((cstat&8) > 0) - swaplong(&y1, &y2); - - x = lx; -#ifdef CLASSIC_SLICE_BY_4 - for (; x<=rx-4; x+=4) - { - uwall[x] = max(startumost[windowxy1.x+x]-windowxy1.y, startum); - uwall[x+1] = max(startumost[windowxy1.x+x+1]-windowxy1.y, startum); - uwall[x+2] = max(startumost[windowxy1.x+x+2]-windowxy1.y, startum); - uwall[x+3] = max(startumost[windowxy1.x+x+3]-windowxy1.y, startum); - - dwall[x] = min(startdmost[windowxy1.x+x]-windowxy1.y, startdm); - dwall[x+1] = min(startdmost[windowxy1.x+x+1]-windowxy1.y, startdm); - dwall[x+2] = min(startdmost[windowxy1.x+x+2]-windowxy1.y, startdm); - dwall[x+3] = min(startdmost[windowxy1.x+x+3]-windowxy1.y, startdm); - } -#endif - for (; x<=rx; x++) - { - uwall[x] = max(startumost[windowxy1.x+x]-windowxy1.y,startum); - dwall[x] = min(startdmost[windowxy1.x+x]-windowxy1.y,startdm); - } - - int32_t daclip = 0; - for (i=smostwallcnt-1; i>=0; i--) - { - if (smostwalltype[i]&daclip) continue; - j = smostwall[i]; - if ((xb1[j] > rx) || (xb2[j] < lx)) continue; - if ((yp <= yb1[j]) && (yp <= yb2[j])) continue; - if (spritewallfront(tspr,(int32_t)thewall[j]) && ((yp <= yb1[j]) || (yp <= yb2[j]))) continue; - - const int32_t dalx2 = max(xb1[j],lx); - const int32_t darx2 = min(xb2[j],rx); - - switch (smostwalltype[i]) - { - case 0: - if (dalx2 <= darx2) - { - if ((dalx2 == lx) && (darx2 == rx)) return; - //clearbufbyte(&dwall[dalx2],(darx2-dalx2+1)*sizeof(dwall[0]),0L); - for (k=dalx2; k<=darx2; k++) dwall[k] = 0; - } - break; - case 1: - k = smoststart[i] - xb1[j]; - x = dalx2; -#ifdef CLASSIC_SLICE_BY_4 // ok, this one is really by 2 ;) - for (; x<=darx2-2; x+=2) - { - if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; - if (smost[k+x+1] > uwall[x+1]) uwall[x+1] = smost[k+x+1]; - } -#endif - for (; x<=darx2; x++) - if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; - if ((dalx2 == lx) && (darx2 == rx)) daclip |= 1; - break; - case 2: - k = smoststart[i] - xb1[j]; - x = dalx2; -#ifdef CLASSIC_SLICE_BY_4 - for (; x<=darx2-4; x+=4) - { - if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; - if (smost[k+x+1] < dwall[x+1]) dwall[x+1] = smost[k+x+1]; - if (smost[k+x+2] < dwall[x+2]) dwall[x+2] = smost[k+x+2]; - if (smost[k+x+3] < dwall[x+3]) dwall[x+3] = smost[k+x+3]; - } -#endif - for (; x<=darx2; x++) - if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; - if ((dalx2 == lx) && (darx2 == rx)) daclip |= 2; - break; - } - } - - if (uwall[rx] >= dwall[rx]) - { - for (x=lx; x= 1 && (searchx >= lx && searchx <= rx)) - if (searchy >= uwall[searchx] && searchy < dwall[searchx]) - { - searchsector = sectnum; searchwall = spritenum; - searchstat = 3; searchit = 1; - } - - setup_globals_sprite1(tspr, sec, span.y, off.y, tilenum, cstat, &z1, &z2); - - qinterpolatedown16((intptr_t)&lwall[lx],rx-lx+1,linum,linuminc); - clearbuf(&swall[lx],rx-lx+1,mulscale19(yp,xdimscale)); - - { -#ifdef HIGH_PRECISION_SPRITE - union { float f; int32_t i; } sw = { - // initialize the float of the union - ((cstat&8) ? -1 : 1) - * (float)yp * xdimscale - * (1<<(22-19)) / (span.y*tspr->yrepeat) - }; - - clearbuf(&swallf[lx], rx-lx+1, sw.i); -#endif - } - - drawing_sprite = 1; - - if ((cstat&2) == 0) - maskwallscan(lx,rx, (cstat&8)==0); - else - transmaskwallscan(lx,rx, (cstat&8)==0); - - drawing_sprite = 0; - } - else if ((cstat&48) == 16) - { - const int32_t xspan = tilesiz[tilenum].x; - const int32_t yspan = tilesiz[tilenum].y; - const int32_t xv = tspr->xrepeat*sintable[(tspr->ang+2560+1536)&2047]; - const int32_t yv = tspr->xrepeat*sintable[(tspr->ang+2048+1536)&2047]; - - if ((cstat&4) > 0) off.x = -off.x; - if ((cstat&8) > 0) off.y = -off.y; - - i = (xspan>>1) + off.x; - x1 = tspr->x-globalposx-mulscale16(xv,i); x2 = x1+mulscale16(xv,xspan); - y1 = tspr->y-globalposy-mulscale16(yv,i); y2 = y1+mulscale16(yv,xspan); - - vec2_t p1 = get_rel_coords(x1, y1); - vec2_t p2 = get_rel_coords(x2, y2); - - if (p1.y <= 0 && p2.y <= 0) - return; - - x1 += globalposx; y1 += globalposy; - x2 += globalposx; y2 += globalposy; - - int32_t swapped = 0; - if (dmulscale32(p1.x, p2.y, -p2.x, p1.y) >= 0) // If wall's NOT facing you - { - if ((cstat&64) != 0) - return; - - const vec2_t pt = p2; - p2 = p1; - p1 = pt; - i = x1, x1 = x2, x2 = i; - i = y1, y1 = y2, y2 = i; - swapped = 1; - } - - int32_t sx1, sx2, sy1, sy2; - if (!get_screen_coords(p1, p2, &sx1, &sy1, &sx2, &sy2)) - return; - - const int32_t topinc = -mulscale10(p1.y,xspan); - int32_t top = ((mulscale10(p1.x,xdimen) - mulscale9(sx1-halfxdimen,p1.y))*xspan)>>3; - const int32_t botinc = (p2.y-p1.y)>>8; - int32_t bot = mulscale11(p1.x-p2.x,xdimen) + mulscale2(sx1-halfxdimen,botinc); - - j = sx2+3; - z = mulscale20(top,krecipasm(bot)); - lwall[sx1] = (z>>8); - for (x=sx1+4; x<=j; x+=4) - { - top += topinc; bot += botinc; - zz = z; z = mulscale20(top,krecipasm(bot)); - i = ((z+zz)>>1); - lwall[x-3] = ((i+zz)>>9); - lwall[x-2] = (i>>8); - lwall[x-1] = ((i+z)>>9); - lwall[x] = (z>>8); - } - - if (lwall[sx1] < 0) lwall[sx1] = 0; - if (lwall[sx2] >= xspan) lwall[sx2] = xspan-1; - - if ((swapped^((cstat&4)>0)) > 0) - { - j = xspan-1; - for (x=sx1; x<=sx2; x++) - lwall[x] = j-lwall[x]; - } - - // XXX: UNUSED? - rx1[MAXWALLSB-1] = p1.x; ry1[MAXWALLSB-1] = p1.y; - rx2[MAXWALLSB-1] = p2.x; ry2[MAXWALLSB-1] = p2.y; - - setup_globals_sprite1(tspr, sec, yspan, off.y, tilenum, cstat, &z1, &z2); - - if ((sec->ceilingstat&1) == 0 && z1 < sec->ceilingz) - z1 = sec->ceilingz; - if ((sec->floorstat&1) == 0 && z2 > sec->floorz) - z2 = sec->floorz; - - xb1[MAXWALLSB-1] = sx1; - xb2[MAXWALLSB-1] = sx2; - yb1[MAXWALLSB-1] = sy1; - yb2[MAXWALLSB-1] = sy2; - owallmost(uwall.Data(), MAXWALLSB-1, z1-globalposz); - owallmost(dwall.Data(), MAXWALLSB-1, z2-globalposz); - - int32_t hplc = divscale19(xdimenscale,sy1); - const int32_t hplc2 = divscale19(xdimenscale,sy2); - const int32_t idiv = sx2-sx1; - int32_t hinc[4] = { idiv ? tabledivide32(hplc2-hplc, idiv) : 0 }; - -#ifdef HIGH_PRECISION_SPRITE - float const cc = ((1<<19) * fxdimen * (float)yxaspect) * (1.f/320.f); - float const loopcc = ((cstat&8) ? -1.f : 1.f) * (float(1<<30) * float(1<<24)) / float(yspan * tspr->yrepeat); - - float hplcf = cc / sy1; - float hincf[4] = { idiv ? (cc / sy2 - hplcf) / idiv : 0 }; - -#ifdef CLASSIC_SLICE_BY_4 - hincf[1] = hincf[0] * 2.f; - hincf[2] = hincf[0] * 3.f; - hincf[3] = hincf[0] * 4.f; -#endif // CLASSIC_SLICE_BY_4 -#endif // HIGH_PRECISION_SPRITE -#ifdef CLASSIC_SLICE_BY_4 - hinc[1] = hinc[0]<<1; - hinc[2] = hinc[0]*3; - hinc[3] = hinc[0]<<2; -#endif - i = sx1; - -#ifdef CLASSIC_SLICE_BY_4 - for (; i<=sx2-4; i+=4) - { - swall[i] = (krecipasm(hplc)<<2); - swall[i+1] = (krecipasm(hplc+hinc[0])<<2); - swall[i+2] = (krecipasm(hplc+hinc[1])<<2); - swall[i+3] = (krecipasm(hplc+hinc[2])<<2); - hplc += hinc[3]; -#ifdef HIGH_PRECISION_SPRITE - swallf[i] = loopcc/hplcf; - swallf[i+1] = loopcc/(hplcf+hincf[0]); - swallf[i+2] = loopcc/(hplcf+hincf[1]); - swallf[i+3] = loopcc/(hplcf+hincf[2]); - hplcf += hincf[3]; -#endif // HIGH_PRECISION_SPRITE - } -#endif // CLASSIC_SLICE_BY_4 - - for (; i<=sx2; i++) - { - swall[i] = (krecipasm(hplc)<<2); - hplc += hinc[0]; -#ifdef HIGH_PRECISION_SPRITE - swallf[i] = loopcc/hplcf; - hplcf += hincf[0]; -#endif - } - - for (i=smostwallcnt-1; i>=0; i--) - { - j = smostwall[i]; - - if (xb1[j] > sx2 || xb2[j] < sx1) - continue; - - int32_t dalx2 = xb1[j]; - int32_t darx2 = xb2[j]; - - if (max(sy1,sy2) > min(yb1[j],yb2[j])) - { - if (min(sy1,sy2) > max(yb1[j],yb2[j])) - { - x = INT32_MIN; - } - else - { - x = thewall[j]; xp1 = wall[x].x; yp1 = wall[x].y; - x = wall[x].point2; xp2 = wall[x].x; yp2 = wall[x].y; - - z1 = (xp2-xp1)*(y1-yp1) - (yp2-yp1)*(x1-xp1); - z2 = (xp2-xp1)*(y2-yp1) - (yp2-yp1)*(x2-xp1); - if ((z1^z2) >= 0) - x = (z1+z2); - else - { - z1 = (x2-x1)*(yp1-y1) - (y2-y1)*(xp1-x1); - z2 = (x2-x1)*(yp2-y1) - (y2-y1)*(xp2-x1); - - if ((z1^z2) >= 0) - x = -(z1+z2); - else - { - if ((xp2-xp1)*(tspr->y-yp1) == (tspr->x-xp1)*(yp2-yp1)) - { - if (wall[thewall[j]].nextsector == tspr->sectnum) - x = INT32_MIN; - else - x = INT32_MAX; - } - else - { - //INTERSECTION! - x = (xp1-globalposx) + scale(xp2-xp1,z1,z1-z2); - y = (yp1-globalposy) + scale(yp2-yp1,z1,z1-z2); - - yp1 = dmulscale14(x,cosviewingrangeglobalang,y,sinviewingrangeglobalang); - - if (yp1 > 0) - { - xp1 = dmulscale14(y,cosglobalang,-x,singlobalang); - - x = halfxdimen + scale(xp1,halfxdimen,yp1); - if (xp1 >= 0) x++; //Fix for SIGNED divide - - if (z1 < 0) - { if (dalx2 < x) dalx2 = x; } - else - { if (darx2 > x) darx2 = x; } - x = INT32_MIN+1; - } - else - x = INT32_MAX; - } - } - } - } - - if (x < 0) - { - if (dalx2 < sx1) dalx2 = sx1; - if (darx2 > sx2) darx2 = sx2; - - switch (smostwalltype[i]) - { - case 0: - if (dalx2 <= darx2) - { - if ((dalx2 == sx1) && (darx2 == sx2)) return; - //clearbufbyte(&dwall[dalx2],(darx2-dalx2+1)*sizeof(dwall[0]),0L); - for (k=dalx2; k<=darx2; k++) dwall[k] = 0; - } - break; - case 1: - k = smoststart[i] - xb1[j]; - x = dalx2; -#ifdef CLASSIC_SLICE_BY_4 - for (; x<=darx2-2; x+=2) - { - if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; - if (smost[k+x+1] > uwall[x+1]) uwall[x+1] = smost[k+x+1]; - } -#endif - for (; x<=darx2; x++) - if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; - break; - case 2: - k = smoststart[i] - xb1[j]; - x = dalx2; -#ifdef CLASSIC_SLICE_BY_4 - for (; x<=darx2-4; x+=4) - { - if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; - if (smost[k+x+1] < dwall[x+1]) dwall[x+1] = smost[k+x+1]; - if (smost[k+x+2] < dwall[x+2]) dwall[x+2] = smost[k+x+2]; - if (smost[k+x+3] < dwall[x+3]) dwall[x+3] = smost[k+x+3]; - } -#endif - for (; x<=darx2; x++) - if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; - break; - } - } - } - } - - //sprite -#ifdef YAX_ENABLE - if (yax_globallev==YAX_MAXDRAWS || searchit==2) -#endif - if (searchit >= 1 && (searchx >= sx1 && searchx <= sx2)) - if (searchy >= uwall[searchx] && searchy <= dwall[searchx]) - { - searchsector = sectnum; searchwall = spritenum; - searchstat = 3; searchit = 1; - } - - drawing_sprite = 1; - - if ((cstat&2) == 0) - maskwallscan(sx1,sx2, (cstat&8)==0); - else - transmaskwallscan(sx1,sx2, (cstat&8)==0); - - drawing_sprite = 0; - } - else if ((cstat&48) == 32) - { - if ((cstat&64) != 0) - if ((globalposz > tspr->z) == ((cstat&8)==0)) - return; - - if ((cstat&4) > 0) off.x = -off.x; - if ((cstat&8) > 0) off.y = -off.y; - - const int32_t xspan = tilesiz[tilenum].x; - const int32_t yspan = tilesiz[tilenum].y; - - //Rotate center point - dax = tspr->x-globalposx; - day = tspr->y-globalposy; - rzi[0] = dmulscale10(cosglobalang,dax,singlobalang,day); - rxi[0] = dmulscale10(cosglobalang,day,-singlobalang,dax); - - //Get top-left corner - int32_t cosang = dmulscale14(sintable[(tspr->ang+512)&2047], cosglobalang, sintable[tspr->ang&2047], singlobalang); - int32_t sinang = dmulscale14(sintable[(tspr->ang+512)&2047], -singlobalang, sintable[tspr->ang&2047], cosglobalang); - dax = ((xspan>>1)+off.x)*tspr->xrepeat; - day = ((yspan>>1)+off.y)*tspr->yrepeat; - rzi[0] += dmulscale12(sinang,dax,cosang,day); - rxi[0] += dmulscale12(sinang,day,-cosang,dax); - - //Get other 3 corners - dax = xspan*tspr->xrepeat; - day = yspan*tspr->yrepeat; - rzi[1] = rzi[0]-mulscale12(sinang,dax); - rxi[1] = rxi[0]+mulscale12(cosang,dax); - dax = -mulscale12(cosang,day); - day = -mulscale12(sinang,day); - rzi[2] = rzi[1]+dax; rxi[2] = rxi[1]+day; - rzi[3] = rzi[0]+dax; rxi[3] = rxi[0]+day; - - //Put all points on same z - ryi[0] = scale((tspr->z-globalposz),yxaspect,320<<8); - if (ryi[0] == 0) return; - ryi[1] = ryi[2] = ryi[3] = ryi[0]; - - if ((cstat&4) == 0) - { z = 0; z1 = 1; z2 = 3; } - else - { z = 1; z1 = 0; z2 = 2; } - - dax = rzi[z1]-rzi[z]; day = rxi[z1]-rxi[z]; - int32_t bot = dmulscale8(dax,dax,day,day); - if ((klabs(dax)>>13) >= bot || (klabs(day)>>13) >= bot) - return; - globalx1 = divscale18(dax,bot); - globalx2 = divscale18(day,bot); - - dax = rzi[z2]-rzi[z]; day = rxi[z2]-rxi[z]; - bot = dmulscale8(dax,dax,day,day); - if ((klabs(dax)>>13) >= bot || (klabs(day)>>13) >= bot) - return; - globaly1 = divscale18(dax,bot); - globaly2 = divscale18(day,bot); - - //Calculate globals for hline texture mapping function - globalxpanning = (rxi[z]<<12); - globalypanning = (rzi[z]<<12); - globalzd = decltype(globalzd)(ryi[z])<<12; - - rzi[0] = mulscale16(rzi[0],viewingrange); - rzi[1] = mulscale16(rzi[1],viewingrange); - rzi[2] = mulscale16(rzi[2],viewingrange); - rzi[3] = mulscale16(rzi[3],viewingrange); - - if (ryi[0] < 0) //If ceilsprite is above you, reverse order of points - { - i = rxi[1]; rxi[1] = rxi[3]; rxi[3] = i; - i = rzi[1]; rzi[1] = rzi[3]; rzi[3] = i; - } - - //Clip polygon in 3-space - int32_t npoints = 4; - - //Clip edge 1 - int32_t npoints2 = 0; - int32_t zzsgn = rxi[0]+rzi[0], zsgn; - for (z=0; z= 0) - { - rxi2[npoints2] = rxi[z]; ryi2[npoints2] = ryi[z]; rzi2[npoints2] = rzi[z]; - npoints2++; - } - if ((zsgn^zzsgn) < 0) - { - int32_t t = divscale30(zsgn,zsgn-zzsgn); - rxi2[npoints2] = rxi[z] + mulscale30(t,rxi[zz]-rxi[z]); - ryi2[npoints2] = ryi[z] + mulscale30(t,ryi[zz]-ryi[z]); - rzi2[npoints2] = rzi[z] + mulscale30(t,rzi[zz]-rzi[z]); - npoints2++; - } - } - if (npoints2 <= 2) return; - - //Clip edge 2 - npoints = 0; - zzsgn = rxi2[0]-rzi2[0]; - for (z=0; z= 0) - { - rxi2[npoints2] = rxi[z]; - ryi2[npoints2] = ryi[z]; - rzi2[npoints2] = rzi[z]; - npoints2++; - } - if ((zsgn^zzsgn) < 0) - { - int32_t t = divscale30(zsgn,zsgn-zzsgn); - rxi2[npoints2] = rxi[z] + mulscale30(t,rxi[zz]-rxi[z]); - ryi2[npoints2] = ryi[z] + mulscale30(t,ryi[zz]-ryi[z]); - rzi2[npoints2] = rzi[z] + mulscale30(t,rzi[zz]-rzi[z]); - npoints2++; - } - } - if (npoints2 <= 2) return; - - //Clip edge 4 - npoints = 0; - zzsgn = ryi2[0]*halfxdimen + (rzi2[0]*(globalhoriz-ydimen)); - for (z=0; z (xdimen<<16)) xsi[z] = (xdimen<<16); - if (ysi[z] < ((int32_t)0<<16)) ysi[z] = ((int32_t)0<<16); - if (ysi[z] > ((int32_t)ydimen<<16)) ysi[z] = ((int32_t)ydimen<<16); - if (xsi[z] < lmax) lmax = xsi[z], lpoint = z; - if (xsi[z] > rmax) rmax = xsi[z], rpoint = z; - } - - //Get uwall arrays - for (z=lpoint; z!=rpoint; z=zz) - { - zz = z+1; if (zz == npoints) zz = 0; - - dax1 = ((xsi[z]+65535)>>16); - dax2 = ((xsi[zz]+65535)>>16); - if (dax2 > dax1) - { - int32_t yinc = divscale16(ysi[zz]-ysi[z],xsi[zz]-xsi[z]); - y = ysi[z] + mulscale16((dax1<<16)-xsi[z],yinc); - qinterpolatedown16short((intptr_t)(&uwall[dax1]),dax2-dax1,y,yinc); - } - } - - //Get dwall arrays - for (; z!=lpoint; z=zz) - { - zz = z+1; if (zz == npoints) zz = 0; - - dax1 = ((xsi[zz]+65535)>>16); - dax2 = ((xsi[z]+65535)>>16); - if (dax2 > dax1) - { - int32_t yinc = divscale16(ysi[zz]-ysi[z],xsi[zz]-xsi[z]); - y = ysi[zz] + mulscale16((dax1<<16)-xsi[zz],yinc); - qinterpolatedown16short((intptr_t)(&dwall[dax1]),dax2-dax1,y,yinc); - } - } - - - const int32_t lx = ((lmax+65535)>>16); - const int32_t rx = min(((rmax+65535)>>16), xdim-1); - // min(): OOB prevention. Simple test case: have a floor-aligned sprite - // to the right of the player. Slowly rotate right toward it. When it - // just becomes visible, the condition rx == xdim can occur. - - // Don't pointlessly keep going. If the following condition holds, the - // ceilspritescan() at the end of our block would not draw any lines, - // and moreover may access uwall[] OOB (with x1==xdim). - if (rx-1 < lx) - return; - - for (x=lx; x<=rx; x++) - { - uwall[x] = max(uwall[x],startumost[x+windowxy1.x]-windowxy1.y); - dwall[x] = min(dwall[x],startdmost[x+windowxy1.x]-windowxy1.y); - } - - //Additional uwall/dwall clipping goes here - for (i=smostwallcnt-1; i>=0; i--) - { - j = smostwall[i]; - if ((xb1[j] > rx) || (xb2[j] < lx)) continue; - if ((yp <= yb1[j]) && (yp <= yb2[j])) continue; - - //if (spritewallfront(tspr,thewall[j]) == 0) - x = thewall[j]; xp1 = wall[x].x; yp1 = wall[x].y; - x = wall[x].point2; xp2 = wall[x].x; yp2 = wall[x].y; - x = (xp2-xp1)*(tspr->y-yp1)-(tspr->x-xp1)*(yp2-yp1); - if ((yp > yb1[j]) && (yp > yb2[j])) x = -1; - if ((x >= 0) && ((x != 0) || (wall[thewall[j]].nextsector != tspr->sectnum))) continue; - - const int32_t dalx2 = max(xb1[j],lx); - const int32_t darx2 = min(xb2[j],rx); - - switch (smostwalltype[i]) - { - case 0: - if (dalx2 <= darx2) - { - if ((dalx2 == lx) && (darx2 == rx)) return; - //clearbufbyte(&dwall[dalx2],(darx2-dalx2+1)*sizeof(dwall[0]),0L); - for (x=dalx2; x<=darx2; x++) dwall[x] = 0; - } - break; - case 1: - k = smoststart[i] - xb1[j]; - for (x=dalx2; x<=darx2; x++) - if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; - break; - case 2: - k = smoststart[i] - xb1[j]; - for (x=dalx2; x<=darx2; x++) - if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; - break; - } - } - - //sprite -#ifdef YAX_ENABLE - if (yax_globallev==YAX_MAXDRAWS || searchit==2) -#endif - if (searchit >= 1 && (searchx >= lx && searchx <= rx)) - if (searchy >= uwall[searchx] && searchy <= dwall[searchx]) - { - searchsector = sectnum; searchwall = spritenum; - searchstat = 3; searchit = 1; - } - - globalorientation = cstat; - globalpicnum = tilenum; - if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0; - - tileLoad(globalpicnum); - - setgotpic(globalpicnum); - globalbufplc = (intptr_t)tilePtr(globalpicnum); - - globvis = mulscale16(globalhisibility,viewingrange); - if (sec->visibility != 0) globvis = mulscale4(globvis, (uint8_t)(sec->visibility+16)); - - x = picsiz[globalpicnum]; y = ((x>>4)&15); x &= 15; -#if 0 - if (pow2long[x] != xspan) - { - x++; - globalx1 = mulscale(globalx1,xspan,x); - globalx2 = mulscale(globalx2,xspan,x); - } -#endif - dax = globalxpanning; day = globalypanning; - globalxpanning = -dmulscale6(globalx1,day,globalx2,dax); - globalypanning = -dmulscale6(globaly1,day,globaly2,dax); - - globalx2 = mulscale16(globalx2,viewingrange); - globaly2 = mulscale16(globaly2,viewingrange); - globalzd = mulscale16(globalzd,viewingrangerecip); - - globalx1 = (globalx1-globalx2)*halfxdimen; - globaly1 = (globaly1-globaly2)*halfxdimen; - - if ((cstat&2) == 0) - msethlineshift(x,y); - else - tsethlineshift(x,y); - - globalispow2 = (pow2long[x]==xspan && pow2long[y]==yspan); - globalxspan = xspan; - globalyspan = yspan; - - //Draw it! - ceilspritescan(lx,rx-1); - globalispow2 = 1; - } - else if ((cstat&48) == 48) - { - const int32_t daxrepeat = ((sprite[spritenum].cstat&48)==16) ? - (tspr->xrepeat * 5) / 4 : - tspr->xrepeat; - - const int32_t lx = 0, rx = xdim-1; - - for (x=lx; x<=rx; x++) - { - lwall[x] = startumost[x+windowxy1.x]-windowxy1.y; - swall[x] = startdmost[x+windowxy1.x]-windowxy1.y; - } - for (i=smostwallcnt-1; i>=0; i--) - { - j = smostwall[i]; - if ((xb1[j] > rx) || (xb2[j] < lx)) continue; - if ((yp <= yb1[j]) && (yp <= yb2[j])) continue; - if (spritewallfront(tspr,(int32_t)thewall[j]) && ((yp <= yb1[j]) || (yp <= yb2[j]))) continue; - - const int32_t dalx2 = max(xb1[j],lx); - const int32_t darx2 = min(xb2[j],rx); - - switch (smostwalltype[i]) - { - case 0: - if (dalx2 <= darx2) - { - if ((dalx2 == lx) && (darx2 == rx)) return; - //clearbufbyte(&swall[dalx2],(darx2-dalx2+1)*sizeof(swall[0]),0L); - for (x=dalx2; x<=darx2; x++) swall[x] = 0; - } - break; - case 1: - k = smoststart[i] - xb1[j]; - x = dalx2; -#ifdef CLASSIC_SLICE_BY_4 - for (; x<=darx2-2; x+=2) - { - if (smost[k+x] > lwall[x]) lwall[x] = smost[k+x]; - if (smost[k+x+1] > lwall[x+1]) lwall[x+1] = smost[k+x+1]; - } -#endif - for (; x<=darx2; x++) - if (smost[k+x] > lwall[x]) lwall[x] = smost[k+x]; - break; - case 2: - k = smoststart[i] - xb1[j]; - x = dalx2; -#ifdef CLASSIC_SLICE_BY_4 - for (; x<=darx2-4; x+=4) - { - if (smost[k+x] < swall[x]) swall[x] = smost[k+x]; - if (smost[k+x+1] < swall[x+1]) swall[x+1] = smost[k+x+1]; - if (smost[k+x+2] < swall[x+2]) swall[x+2] = smost[k+x+2]; - if (smost[k+x+3] < swall[x+3]) swall[x+3] = smost[k+x+3]; - } -#endif - for (; x<=darx2; x++) - if (smost[k+x] < swall[x]) swall[x] = smost[k+x]; - break; - } - } - - if (lwall[rx] >= swall[rx]) - { - for (x=lx; xxrepeat = tspr->yrepeat = 255; - goto draw_as_face_sprite; - } - - int32_t nxrepeat, nyrepeat; - - if (voxscale[vtilenum] == 65536) - { - nxrepeat = (daxrepeat<<16); - nyrepeat = (((int32_t)tspr->yrepeat)<<16); - } - else - { - nxrepeat = daxrepeat*voxscale[vtilenum]; - nyrepeat = ((int32_t)tspr->yrepeat)*voxscale[vtilenum]; - } - - off.x = tspr->xoffset; - off.y = /*picanm[sprite[tspr->owner].picnum].yofs +*/ tspr->yoffset; - if (cstat & 4) off.x = -off.x; - if ((cstat & 8) && (tspr->cstat&48) != 0) off.y = -off.y; - tspr->z -= off.y * tspr->yrepeat << 2; - - if ((sprite[spritenum].cstat&CSTAT_SPRITE_ALIGNMENT) == CSTAT_SPRITE_ALIGNMENT_WALL) - { - const int32_t xv = tspr->xrepeat*sintable[(tspr->ang+2560+1536)&2047]; - const int32_t yv = tspr->xrepeat*sintable[(tspr->ang+2048+1536)&2047]; - - tspr->x -= mulscale16(xv, off.x); - tspr->y -= mulscale16(yv, off.x); - } - - globvis = globalvisibility; - if (sec->visibility != 0) globvis = mulscale4(globvis, (uint8_t)(sec->visibility+16)); - -#ifdef YAX_ENABLE - if (yax_globallev==YAX_MAXDRAWS || searchit==2) -#endif - if (searchit >= 1 && yp > (4<<8) && (searchy >= lwall[searchx] && searchy < swall[searchx])) - { - int32_t const xdsiz = divscale19(xdimenscale,yp); - int32_t const xv = mulscale16(nxrepeat,xyaspect); - - int32_t const xspan = ((B_LITTLE32(longptr[0]) + B_LITTLE32(longptr[1])) >> 1); - int32_t const yspan = B_LITTLE32(longptr[2]); - - vec2_t const siz = { mulscale_triple30(xdsiz, xv, xspan), mulscale_triple30(xdsiz, nyrepeat, yspan) }; - - //Watch out for divscale overflow - if (((xspan>>11) < siz.x) && (yspan < (siz.y>>1))) - { - x1 = xb-(siz.x>>1); - if (xspan&1) x1 += mulscale31(xdsiz,xv); //Odd xspans - i = mulscale30(xdsiz,xv*off.x); - if ((cstat&4) == 0) x1 -= i; else x1 += i; - - y1 = mulscale16(tspr->z-globalposz,xdsiz); - - if (!(cstat & 128)) - y1 -= mulscale16(mulscale22(B_LITTLE32(longptr[5]), nyrepeat), xdsiz); - //y1 -= mulscale30(xdsiz,nyrepeat*yoff); - y1 += (globalhoriz<<8)-siz.y; - //if (cstat&128) //Already fixed up above - y1 += (siz.y>>1); - - x2 = x1+siz.x-1; - y2 = y1+siz.y-1; - if ((y1|255) < (y2|255) && searchx >= (x1>>8)+1 && searchx <= (x2>>8)) - { - int32_t startum, startdm; - - if ((sec->ceilingstat&3) == 0) - startum = globalhoriz+mulscale24(xdsiz,sec->ceilingz-globalposz)-1; - else - startum = 0; - - if ((sec->floorstat&3) == 0) - startdm = globalhoriz+mulscale24(xdsiz,sec->floorz-globalposz)+1; - else - startdm = INT32_MAX; - - //sprite - if (searchy >= max(startum,(y1>>8)) && searchy < min(startdm,(y2>>8))) - { - searchsector = sectnum; searchwall = spritenum; - searchstat = 3; searchit = 1; - } - } - } - } - - x = tspr->x + spriteext[spritenum].position_offset.x; - y = tspr->y + spriteext[spritenum].position_offset.y; - z = tspr->z + spriteext[spritenum].position_offset.z; - - i = (int32_t)tspr->ang+1536; - i += spriteext[spritenum].angoff; - - const int32_t ceilingz = (sec->ceilingstat&3) == 0 ? sec->ceilingz : INT32_MIN; - const int32_t floorz = (sec->floorstat&3) == 0 ? sec->floorz : INT32_MAX; - - classicDrawVoxel(x,y,z,i,daxrepeat,(int32_t)tspr->yrepeat,vtilenum, - tspr->shade,tspr->pal,lwall.Data(),swall.Data(),tspr->cstat,(tspr->cstat&48)!=48,floorz,ceilingz); - } - - if (automapping == 1 && (unsigned)spritenum < MAXSPRITES) - show2dsprite[spritenum>>3] |= pow2char[spritenum&7]; -} - static void renderDrawSprite(int32_t snum) { - switch (videoGetRenderMode()) - { - case REND_CLASSIC: - classicDrawSprite(snum); - return; -#ifdef USE_OPENGL - case REND_POLYMOST: - polymost_drawsprite(snum); - return; -#endif - } + polymost_drawsprite(snum); } @@ -6050,86 +1750,9 @@ static void renderDrawSprite(int32_t snum) // static void renderDrawMaskedWall(int16_t damaskwallcnt) { - //============================================================================= //POLYMOST BEGINS -#ifdef USE_OPENGL - if (videoGetRenderMode() == REND_POLYMOST) { polymost_drawmaskwall(damaskwallcnt); return; } -#endif - //============================================================================= //POLYMOST ENDS - - int32_t z = maskwall[damaskwallcnt]; - auto wal = (uwallptr_t)&wall[thewall[z]]; - int32_t sectnum = thesector[z]; - auto sec = (usectorptr_t)§or[sectnum]; - auto nsec = (usectorptr_t)§or[wal->nextsector]; - int32_t z1 = max(nsec->ceilingz,sec->ceilingz); - int32_t z2 = min(nsec->floorz,sec->floorz); - - wallmost(uwall.Data(),z,sectnum,(uint8_t)0); - wallmost(uplc.Data(),z,(int32_t)wal->nextsector,(uint8_t)0); - for (bssize_t x=xb1[z]; x<=xb2[z]; x++) - if (uplc[x] > uwall[x]) - uwall[x] = uplc[x]; - wallmost(dwall.Data(),z,sectnum,(uint8_t)1); - wallmost(dplc.Data(),z,(int32_t)wal->nextsector,(uint8_t)1); - for (bssize_t x=xb1[z]; x<=xb2[z]; x++) - if (dplc[x] < dwall[x]) - dwall[x] = dplc[x]; - prepwall(z,wal); - - setup_globals_wall1(wal, wal->overpicnum); - setup_globals_wall2(wal, sec->visibility, z1, z2); - - for (bssize_t i=smostwallcnt-1; i>=0; i--) - { - int j=smostwall[i]; - if ((xb1[j] > xb2[z]) || (xb2[j] < xb1[z])) continue; - if (wallfront(j,z)) continue; - - int lx = max(xb1[j],xb1[z]); - int rx = min(xb2[j],xb2[z]); - - switch (smostwalltype[i]) - { - case 0: - if (lx <= rx) - { - if ((lx == xb1[z]) && (rx == xb2[z])) return; - //clearbufbyte(&dwall[lx],(rx-lx+1)*sizeof(dwall[0]),0L); - for (bssize_t x=lx; x<=rx; x++) dwall[x] = 0; - } - break; - case 1: - for (bssize_t x=lx, k = smoststart[i] - xb1[j]; x<=rx; x++) - if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x]; - break; - case 2: - for (bssize_t x=lx, k = smoststart[i] - xb1[j]; x<=rx; x++) - if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x]; - break; - } - } - - //maskwall - if (searchit >= 1 && (searchx >= xb1[z] && searchx <= xb2[z])) - if (searchy >= uwall[searchx] && searchy <= dwall[searchx]) - { - searchsector = sectnum; searchbottomwall = searchwall = thewall[z]; - searchstat = 4; searchit = 1; - } - - if ((globalorientation&128) == 0) - { - maskwallscan(xb1[z],xb2[z], 0); - } - else - { - if (globalorientation&128) -#ifdef NEW_MAP_FORMAT - setup_blend(wal->blend, globalorientation&512); -#else - setup_blend(wallext[thewall[z]].blend, globalorientation&512); -#endif - transmaskwallscan(xb1[z],xb2[z], 0); + if (videoGetRenderMode() == REND_POLYMOST) + { + polymost_drawmaskwall(damaskwallcnt); return; } } @@ -6330,9 +1953,6 @@ static int32_t engineLoadTables(void) for (i=0; i<2048; i++) reciptable[i] = divscale30(2048, i+2048); - for (i=0; i dmost[i]) - numhits--; - -// yaxdebug("cf %d, tlev %d, bunch %d: numhits=%d", yax_globalcf, yax_globallev, yax_globalbunch, numhits); - } -#endif - -/* - globparaceilclip = 1; - globparaflorclip = 1; - getzsofslope(globalcursectnum,globalposx,globalposy,&cz,&fz); - if (globalposz < cz) globparaceilclip = 0; - if (globalposz > fz) globparaflorclip = 0; -*/ - classicScanSector(globalcursectnum); - - if (inpreparemirror) - { - // INPREPAREMIRROR_NO_BUNCHES - // numbunches==0 can happen if the mirror is far away... the game code decides - // to draw it, but scansector gets zero bunches. Result: big screwup! - // Set inpreparemirror to 0 to indicate that we were unable to render the mirror - if (numbunches==0) - { - inpreparemirror = 0; - videoEndDrawing(); //!!! - return 0; - } - - mirrorsx1 = xdimen-1; mirrorsx2 = 0; - for (i=numscans-1; i>=0; i--) - { - if (wall[thewall[i]].nextsector >= 0) - { - if (xb1[i] < mirrorsx1) mirrorsx1 = xb1[i]; - if (xb2[i] > mirrorsx2) mirrorsx2 = xb2[i]; - } - } - - for (i=0; i 0) && (numhits > 0)) - { - Bmemset(tempbuf, 0, numbunches); - tempbuf[0] = 1; - - closest = 0; //Almost works, but not quite :( - for (i=1; i=0; z=bunchp2[z]) - show2dwall[thewall[z]>>3] |= pow2char[thewall[z]&7]; - } - - numbunches--; - bunchfirst[closest] = bunchfirst[numbunches]; - bunchlast[closest] = bunchlast[numbunches]; - } - - videoEndDrawing(); //}}} - return inpreparemirror; } @@ -7902,7 +3397,7 @@ void renderDrawMapView(int32_t dax, int32_t day, int32_t zoome, int16_t ang) { globalpalwritten = palookup[sec->floorpal]; if (!globalpalwritten) globalpalwritten = palookup[0]; // JBF: fixes null-pointer crash - setpalookupaddress(globalpalwritten); + //setpalookupaddress(globalpalwritten); } globalpicnum = sec->floorpicnum; if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0; @@ -8719,8 +4214,6 @@ int32_t videoSetGameMode(char davidoption, int32_t daupscaledxdim, int32_t daups //Force drawrooms to call dosetaspect & recalculate stuff oxyaspect = oxdimen = oviewingrange = -1; - calc_ylookup(bytesperline, ydim); - videoSetViewableArea(0L,0L,xdim-1,ydim-1); videoClearScreen(0L); @@ -10027,29 +5520,9 @@ void videoClearViewableArea(int32_t dacol) if (dacol == -1) dacol = 0; -#ifdef USE_OPENGL - if (videoGetRenderMode() >= REND_POLYMOST) - { - palette_t const p = paletteGetColor(dacol); + palette_t const p = paletteGetColor(dacol); - GLInterface.ClearScreen(PalEntry(p.r, p.g, p.b), false); - return; - } -#endif - - videoBeginDrawing(); //{{{ - //dacol += (dacol<<8); dacol += (dacol<<16); - int const dx = windowxy2.x-windowxy1.x+1; - intptr_t p = frameplace+ylookup[windowxy1.y]+windowxy1.x; - for (bssize_t y=windowxy1.y; y<=windowxy2.y; ++y) - { - //clearbufbyte((void*)p,dx,dacol); - Bmemset((void *)p,dacol,dx); - p += ylookup[1]; - } - videoEndDrawing(); //}}} - - faketimerhandler(); + GLInterface.ClearScreen(PalEntry(p.r, p.g, p.b), false); } @@ -10111,8 +5584,6 @@ void renderSetTarget(int16_t tilenume, int32_t xsiz, int32_t ysiz) ydim = xsiz*4; videoSetViewableArea(0,0,ysiz*4-1,xsiz*4-1); renderSetAspect(65536,65536); - - calc_ylookup(ysiz, xsiz); } @@ -10132,9 +5603,6 @@ void renderRestoreTarget() videoSetViewableArea(bakwindowxy1.x,bakwindowxy1.y, bakwindowxy2.x,bakwindowxy2.y); - calc_ylookup((setviewcnt == 0) ? bytesperline : bakxsiz, - bakysiz); - modechange=1; } @@ -10172,61 +5640,8 @@ void renderPrepareMirror(int32_t dax, int32_t day, int32_t daz, fix16_t daang, f // void renderCompleteMirror(void) { -#ifdef USE_OPENGL - if (videoGetRenderMode() == REND_POLYMOST) - polymost_completeMirror(); -#endif - - // Don't try to complete a mirror if we haven't drawn the reflection for one - if (!inpreparemirror) { return; } + polymost_completeMirror(); inpreparemirror = 0; - -#ifdef USE_OPENGL - if (videoGetRenderMode() != REND_CLASSIC) - return; -#endif - - // The mirroring code maps the rightmost pixel to the right neighbor of the - // leftmost one (see copybufreverse() call below). Thus, the leftmost would - // be mapped to the right neighbor of the rightmost one, which would be out - // of bounds. - if (mirrorsx1 == 0) - mirrorsx1 = 1; - - // Require that the mirror is at least one pixel wide before padding. - if (mirrorsx1 > mirrorsx2) - return; - - // Variables mirrorsx{1,2} refer to the source scene here, the one drawn - // from the inside of the mirror. - - videoBeginDrawing(); - - // Width in pixels (screen x's are inclusive on both sides): - int const width = mirrorsx2-mirrorsx1+1; - // Height in pixels (screen y's are half-open because they come from umost/dmost): - int const height = mirrorsy2-mirrorsy1; - - // Address of the mirror wall's top left corner in the source scene: - intptr_t s = (intptr_t) mirrorBuffer.Data() + ylookup[windowxy1.y+mirrorsy1] + windowxy1.x+mirrorsx1; - - // Pointer to the mirror line's left corner in the destination: - intptr_t d = (intptr_t) frameplace + ylookup[windowxy1.y+mirrorsy1] + windowxy2.x-mirrorsx2; - - for (bssize_t y=0; y= bytesperline*ydim) - printf("oob read: mirrorsx1=%d, mirrorsx2=%d\n", mirrorsx1, mirrorsx2); -#endif - copybufreverse((void *)(s+width-1), (void *)(d+1), width); - - s += ylookup[1]; - d += ylookup[1]; - faketimerhandler(); - } - - videoEndDrawing(); } @@ -10537,14 +5952,8 @@ int32_t videoSetRenderMode(int32_t renderer) UNREFERENCED_PARAMETER(renderer); #ifdef USE_OPENGL - if (bpp == 8) - { - GLInterface.EnableBlend(false); - GLInterface.EnableAlphaTest(false); - renderer = REND_CLASSIC; - } - else renderer = REND_POLYMOST; + renderer = REND_POLYMOST; basepalreset = 1; diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index a3d419250..a0961fb0e 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -13,7 +13,6 @@ #include "imagehelpers.h" #include "palette.h" -#include "a.h" #include "superfasthash.h" #include "common.h" #include "../../glbackend/glbackend.h" @@ -72,23 +71,6 @@ int DetermineTranslucency(const uint8_t *table) void fullscreen_tint_gl(PalEntry pe); -void setup_blend(int32_t blend, int32_t doreverse) -{ - if (blendtable[blend] == NULL) - blend = 0; - - if (globalblend != blend) - { - globalblend = blend; - fixtransluscence(FP_OFF(paletteGetBlendTable(blend))); - } - - if (doreverse) - settransreverse(); - else - settransnormal(); -} - static void alloc_palookup(int32_t pal) { // The asm functions vlineasm1, mvlineasm1 (maybe others?) access the next @@ -286,9 +268,9 @@ void palettePostLoadTables(void) globalpal = 0; globalpalwritten = palookup[0]; - setpalookupaddress(globalpalwritten); - - fixtransluscence(FP_OFF(blendtable[0])); + // Do we still need these? + //setpalookupaddress(globalpalwritten); + //fixtransluscence(FP_OFF(blendtable[0])); char const * const palookup0 = palookup[0]; diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index 8fa69d58a..4e0951954 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -1,7 +1,6 @@ // SDL interface layer for the Build Engine // Use SDL 1.2 or 2.0 from http://www.libsdl.org -#include "a.h" #include "build.h" #include "common.h" @@ -38,40 +37,6 @@ char modechange=1; char offscreenrendering=0; -// Calculate ylookup[] and call setvlinebpl() -void calc_ylookup(int32_t bpl, int32_t lastyidx) -{ - int32_t i, j = 0; - static int32_t ylookupsiz; - - Bassert(lastyidx <= MAXYDIM); - - lastyidx++; - - if (lastyidx > ylookupsiz) - { - ylookup.Resize(lastyidx); - ylookupsiz = lastyidx; - } - - for (i = 0; i <= lastyidx - 4; i += 4) - { - ylookup[i] = j; - ylookup[i + 1] = j + bpl; - ylookup[i + 2] = j + (bpl << 1); - ylookup[i + 3] = j + (bpl * 3); - j += (bpl << 2); - } - - for (; i < lastyidx; i++) - { - ylookup[i] = j; - j += bpl; - } - - setvlinebpl(bpl); -} - // // begindrawing() -- locks the framebuffer for drawing // @@ -129,7 +94,6 @@ void videoBeginDrawing(void) if (modechange) { bytesperline = xdim; - calc_ylookup(bytesperline, ydim); modechange=0; } } diff --git a/source/common/rendering/gl/renderer/gl_renderer.cpp b/source/common/rendering/gl/renderer/gl_renderer.cpp index d53708ed8..206b85f59 100644 --- a/source/common/rendering/gl/renderer/gl_renderer.cpp +++ b/source/common/rendering/gl/renderer/gl_renderer.cpp @@ -216,13 +216,11 @@ void FGLRenderer::WriteSavePic ( FileWriter *file, int width, int height) ydim = height; videoSetViewableArea(0, 0, width - 1, height - 1); renderSetAspect(65536, 65536); - calc_ylookup(width, height); bool didit = gi->GenerateSavePic(); xdim = oldx; ydim = oldy; videoSetViewableArea(oldwindowxy1.x, oldwindowxy1.y, oldwindowxy2.x, oldwindowxy2.y); - calc_ylookup(bytesperline, ydim); modechange = 1; // The 2D drawers can contain some garbage from the dirty render setup. Get rid of that first. diff --git a/source/common/screenshot.cpp b/source/common/screenshot.cpp index 7bcaf0662..4705cbdea 100644 --- a/source/common/screenshot.cpp +++ b/source/common/screenshot.cpp @@ -141,18 +141,6 @@ static int SaveScreenshot() memcpy(imgBuf.Data() + (ydim - i - 1) * bytesPerLine, rowBuf.Data(), bytesPerLine); } } - else - { - for (int i = 0; i < 256; ++i) - { - Palette[i].r = curpalettefaded[i].r; - Palette[i].g = curpalettefaded[i].g; - Palette[i].b = curpalettefaded[i].b; - } - - for (int i = 0; i < ydim; ++i) - memcpy(imgBuf.Data() + i * xdim, (uint8_t *)frameplace + ylookup[i], xdim); - } videoEndDrawing(); diff --git a/source/duke3d/src/duke3d.h b/source/duke3d/src/duke3d.h index 454a6765f..42d9480d9 100644 --- a/source/duke3d/src/duke3d.h +++ b/source/duke3d/src/duke3d.h @@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define duke3d_h_ // JBF -#include "a.h" #include "baselayer.h" #include "build.h" diff --git a/source/rr/src/duke3d.h b/source/rr/src/duke3d.h index a51ec6a40..6a33d2579 100644 --- a/source/rr/src/duke3d.h +++ b/source/rr/src/duke3d.h @@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define duke3d_h_ // JBF -#include "a.h" #include "baselayer.h" #include "build.h"