diff --git a/source/build/include/build.h b/source/build/include/build.h index 6a17bc425..8e70f7046 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -732,7 +732,7 @@ EXTERN int16_t headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1]; EXTERN int16_t prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES]; EXTERN int16_t nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES]; -EXTERN vec2_t tilesiz[MAXTILES]; +EXTERN vec2s_t tilesiz[MAXTILES]; EXTERN char picsiz[MAXTILES]; EXTERN char walock[MAXTILES]; diff --git a/source/build/include/compat.h b/source/build/include/compat.h index 027bea591..3140a7b26 100644 --- a/source/build/include/compat.h +++ b/source/build/include/compat.h @@ -707,6 +707,10 @@ typedef struct { int32_t x, y; } vec2_t; +typedef struct { + int16_t x, y; +} vec2s_t; + typedef struct { uint32_t x, y; } vec2u_t; diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index 39f5bbf94..73008c55f 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -200,7 +200,7 @@ static int32_t check_tile(const char *defcmd, int32_t tile, const scriptfile *sc static void tile_from_truecolpic(int32_t tile, const palette_t *picptr, int32_t alphacut) { - const vec2_t siz = tilesiz[tile]; + vec2s_t const siz = tilesiz[tile]; int32_t i, j, tsiz = siz.x * siz.y; maybe_grow_buffer(&faketilebuffer, &faketilebuffersiz, tsiz); @@ -223,7 +223,7 @@ static void tile_from_truecolpic(int32_t tile, const palette_t *picptr, int32_t static int32_t Defs_LoadTileIntoBuffer(int32_t const tile) { - vec2_t const siz = tilesiz[tile]; + vec2s_t const siz = tilesiz[tile]; int32_t const tsiz = siz.x * siz.y; if (EDUKE32_PREDICT_FALSE(tilesiz[tile].x <= 0 || tilesiz[tile].y <= 0)) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 87bb5fb0a..ac259ea24 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -1819,7 +1819,7 @@ void printbunches(void) #define WSHELPER_DECL inline //ATTRIBUTE((always_inline)) -static WSHELPER_DECL void tweak_tsizes(vec2_t *tsiz) +static WSHELPER_DECL void tweak_tsizes(vec2s_t *tsiz) { if (pow2long[picsiz[globalpicnum]&15] == tsiz->x) tsiz->x--; @@ -1832,7 +1832,7 @@ static WSHELPER_DECL void tweak_tsizes(vec2_t *tsiz) tsiz->y = -tsiz->y; } -static WSHELPER_DECL void calc_bufplc(intptr_t *bufplc, int32_t lw, vec2_t tsiz) +static WSHELPER_DECL void calc_bufplc(intptr_t *bufplc, int32_t lw, vec2s_t tsiz) { // CAUTION: lw can be negative! int32_t i = lw + globalxpanning; @@ -1905,7 +1905,7 @@ static void maskwallscan(int32_t x1, int32_t x2, int32_t saturatevplc) if ((uwall[x1] > ydimen) && (uwall[x2] > ydimen)) return; if ((dwall[x1] < 0) && (dwall[x2] < 0)) return; - vec2_t tsiz = tilesiz[globalpicnum]; + vec2s_t tsiz = tilesiz[globalpicnum]; if ((tsiz.x <= 0) || (tsiz.y <= 0)) return; setgotpic(globalpicnum); @@ -2908,7 +2908,7 @@ static void wallscan(int32_t x1, int32_t x2, int32_t x; intptr_t fpalookup; int32_t y1ve[4], y2ve[4]; - vec2_t tsiz; + vec2s_t tsiz; #ifdef MULTI_COLUMN_VLINE char bad; int32_t u4, d4, z; @@ -3059,7 +3059,7 @@ static void transmaskvline(int32_t x) intptr_t palookupoffs = FP_OFF(palookup[globalpal]) + getpalookupsh(mulscale16(swall[x],globvis)); - vec2_t ntsiz = { -tilesiz[globalpicnum].x, -tilesiz[globalpicnum].y }; + vec2s_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; @@ -3101,7 +3101,7 @@ static void transmaskvline2(int32_t x) setuptvlineasm2(globalshiftval,palookupoffse[0],palookupoffse[1]); - vec2_t const ntsiz = { -tilesiz[globalpicnum].x, -tilesiz[globalpicnum].y }; + vec2s_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); @@ -4835,7 +4835,7 @@ draw_as_face_sprite: int const isiz = divscale19(xdimenscale,yp); int const xv = mulscale16(((int32_t)tspr->xrepeat)<<16,xyaspect); - vec2_t const span = tilesiz[tilenum]; + vec2s_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))) diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 4915769c5..5ff3fc295 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -928,9 +928,8 @@ void uploadtexture(int32_t doalloc, vec2_t siz, int32_t texfmt, if (!nomiptransfix) { vec2_t const tsizzle = { (tsiz.x + (1 << j)-1) >> j, (tsiz.y + (1 << j)-1) >> j }; - vec2_t const mnizzle = { siz3.x, siz3.y }; - fixtransparency(pic, tsizzle, mnizzle, dameth); + fixtransparency(pic, tsizzle, siz3, dameth); } if (j >= miplevel) @@ -998,7 +997,8 @@ static void polymost_setuptexture(const int32_t dameth, int filter) void gloadtile_art(int32_t dapic, int32_t dapal, int32_t tintpalnum, int32_t dashade, int32_t dameth, pthtyp *pth, int32_t doalloc) { static int32_t fullbrightloadingpass = 0; - vec2_t siz = { 0, 0 }, tsiz = tilesiz[dapic]; + vec2s_t const & tsizart = tilesiz[dapic]; + vec2_t siz = { 0, 0 }, tsiz = { tsizart.x, tsizart.y }; size_t const picdim = tsiz.x*tsiz.y; char hasalpha = 0, hasfullbright = 0; char npoty = 0; @@ -1653,7 +1653,8 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 //Load texture (globalpicnum) setgotpic(globalpicnum); - vec2_t tsiz = tilesiz[globalpicnum]; + vec2s_t const & tsizart = tilesiz[globalpicnum]; + vec2_t tsiz = { tsizart.x, tsizart.y }; if (!waloff[globalpicnum]) { @@ -4390,7 +4391,8 @@ void polymost_drawsprite(int32_t snum) pos.y -= (sintable[(tspr->ang) & 2047] >> 13); } - vec2_t tsiz = tilesiz[globalpicnum], oldsiz = tsiz; + vec2s_t const oldsiz = tilesiz[globalpicnum]; + vec2_t tsiz = { oldsiz.x, oldsiz.y }; if (usehightile && h_xsize[globalpicnum]) { @@ -4518,7 +4520,8 @@ void polymost_drawsprite(int32_t snum) pxy[2].y = pxy[3].y = s0.y; } - tilesiz[globalpicnum] = tsiz; + tilesiz[globalpicnum].x = tsiz.x; + tilesiz[globalpicnum].y = tsiz.y; pow2xsplit = 0; polymost_drawpoly(pxy, 4, method); @@ -4730,7 +4733,8 @@ void polymost_drawsprite(int32_t snum) vec2f_t const pxy[4] = { { sx0, sc0 }, { sx1, sc1 }, { sx1, sf1 }, { sx0, sf0 } }; - tilesiz[globalpicnum] = tsiz; + tilesiz[globalpicnum].x = tsiz.x; + tilesiz[globalpicnum].y = tsiz.y; pow2xsplit = 0; polymost_drawpoly(pxy, 4, method); @@ -4902,7 +4906,8 @@ void polymost_drawsprite(int32_t snum) drawpoly_trepeat = 1; } - tilesiz[globalpicnum] = tsiz; + tilesiz[globalpicnum].x = tsiz.x; + tilesiz[globalpicnum].y = tsiz.y; pow2xsplit = 0; polymost_drawpoly(pxy, npoints, method); @@ -4981,8 +4986,8 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a, if (dastat & RS_TOPLEFT) { - vec2_t siz = tilesiz[picnum]; - vec2_t off = { picanm[picnum].xofs + (siz.x >> 1), picanm[picnum].yofs + (siz.y >> 1) }; + vec2s_t siz = tilesiz[picnum]; + vec2s_t off = { (int16_t)((siz.x >> 1) + picanm[picnum].xofs), (int16_t)((siz.y >> 1) + picanm[picnum].yofs) }; d = (float)z * (1.0f / (65536.f * 16384.f)); cosang2 = cosang = (float)sintable[(a + 512) & 2047] * d; @@ -4995,8 +5000,9 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a, sinang2 *= d; } - f.x += -(float)off.x * cosang2 + (float)off.y * sinang2; - f.y += -(float)off.x * sinang - (float)off.y * cosang; + vec2f_t const foff = { (float)off.x, (float)off.y }; + f.x += -foff.x * cosang2 + foff.y * sinang2; + f.y += -foff.x * sinang - foff.y * cosang; } if (!(dastat & RS_AUTO)) @@ -5253,8 +5259,8 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 drawpoly_alpha = daalpha * (1.0f / 255.0f); drawpoly_blend = dablend; - vec2_t const siz = tilesiz[globalpicnum]; - vec2_t ofs = { 0, 0 }; + vec2s_t const siz = tilesiz[globalpicnum]; + vec2s_t ofs = { 0, 0 }; if (!(dastat & RS_TOPLEFT)) { @@ -5281,8 +5287,9 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 sinang2 *= d; } - float const cx = (float)sx * (1.0f / 65536.f) - (float)ofs.x * cosang2 + (float)ofs.y * sinang2; - float const cy = (float)sy * (1.0f / 65536.f) - (float)ofs.x * sinang - (float)ofs.y * cosang; + vec2f_t const fofs = { (float)ofs.x, (float)ofs.y }; + float const cx = (float)sx * (1.0f / 65536.f) - fofs.x * cosang2 + fofs.y * sinang2; + float const cy = (float)sy * (1.0f / 65536.f) - fofs.x * sinang - fofs.y * cosang; vec2f_t pxy[8] = { { cx, cy }, { cx + (float)siz.x * cosang2, cy + (float)siz.x * sinang }, diff --git a/source/build/src/tiles.cpp b/source/build/src/tiles.cpp index e0b33a708..eb1baba90 100644 --- a/source/build/src/tiles.cpp +++ b/source/build/src/tiles.cpp @@ -20,7 +20,7 @@ static int32_t tilefileoffs[MAXTILES]; // necessary (have per-map ART files). static uint8_t *g_bakTileFileNum; static int32_t *g_bakTileFileOffs; -static vec2_t *g_bakTileSiz; +static vec2s_t *g_bakTileSiz; static picanm_t *g_bakPicAnm; // NOTE: picsiz[] is not backed up, but recalculated when necessary. diff --git a/source/duke3d/src/gamevars.cpp b/source/duke3d/src/gamevars.cpp index 2f5074a55..e9d05c075 100644 --- a/source/duke3d/src/gamevars.cpp +++ b/source/duke3d/src/gamevars.cpp @@ -1526,8 +1526,8 @@ static void Gv_AddSystemVars(void) # endif // SYSTEM_GAMEARRAY - Gv_NewArray("tilesizx", (void *)&tilesiz[0].x, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFINT); - Gv_NewArray("tilesizy", (void *)&tilesiz[0].y, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFINT); + Gv_NewArray("tilesizx", (void *)&tilesiz[0].x, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFSHORT); + Gv_NewArray("tilesizy", (void *)&tilesiz[0].y, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFSHORT); #endif } diff --git a/source/duke3d/src/m32vars.cpp b/source/duke3d/src/m32vars.cpp index fd4c1da2f..70ffa62c2 100644 --- a/source/duke3d/src/m32vars.cpp +++ b/source/duke3d/src/m32vars.cpp @@ -78,8 +78,6 @@ int32_t Gv_NewArray(const char *pszLabel, void *arrayptr, int32_t asize, uint32_ ASSERT_IMPLIES(dwFlags&GAMEARRAY_TYPE_MASK, g_gameArrayCount==0 || (dwFlags&(GAMEARRAY_READONLY|GAMEARRAY_WARN))); - ASSERT_IMPLIES(dwFlags&GAMEARRAY_STRIDE2, dwFlags&GAMEARRAY_OFINT); - if (g_gameArrayCount >= MAXGAMEARRAYS) { C_CUSTOMERROR("too many arrays! (max: %d)", MAXGAMEARRAYS); @@ -672,8 +670,8 @@ static void Gv_AddSystemVars(void) Gv_NewArray("nextsectbunchf", (void *)nextsectbunch[1], MAXSECTORS, GAMEARRAY_READONLY|GAMEARRAY_OFSHORT); #endif Gv_NewArray("editorcolors", (void *)editorcolors, 256, GAMEARRAY_READONLY|GAMEARRAY_OFCHAR); - Gv_NewArray("tilesizx", (void *)&tilesiz[0].x, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFINT); - Gv_NewArray("tilesizy", (void *)&tilesiz[0].y, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFINT); + Gv_NewArray("tilesizx", (void *)&tilesiz[0].x, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFSHORT); + Gv_NewArray("tilesizy", (void *)&tilesiz[0].y, MAXTILES, GAMEARRAY_STRIDE2|GAMEARRAY_READONLY|GAMEARRAY_OFSHORT); // Gv_NewArray("picsiz", (void *)picsiz, MAXTILES, GAMEARRAY_READONLY|GAMEARRAY_OFCHAR); Gv_NewArray("picanm", (void *)picanm, MAXTILES, GAMEARRAY_READONLY|GAMEARRAY_OFINT);