diff --git a/source/build/include/pragmas.h b/source/build/include/pragmas.h index 528bd74e8..367fb4f20 100644 --- a/source/build/include/pragmas.h +++ b/source/build/include/pragmas.h @@ -79,29 +79,6 @@ EDUKE32_GENERATE_PRAGMAS #undef EDUKE32_SCALER_PRAGMA -template -static FORCE_INLINE void swapptr(T * const a, T * const b) -{ - T const t = *a; - *a = *b; - *b = t; -} - -#ifndef pragmas_have_swaps -#define swapchar swapptr -#define swapshort swapptr -#define swaplong swapptr -#define swapfloat swapptr -#define swapdouble swapptr -#define swap64bit swapptr - -static FORCE_INLINE void swapchar2(void *a, void *b, int32_t s) -{ - swapchar((char *)a, (char *)b); - swapchar((char *)a + 1, (char *)b + s); -} -#endif - #define klabs(x) abs(x) static inline constexpr int ksgn(int32_t a) { return (a > 0) - (a < 0); } diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index cea7fba8c..ae7c0ee08 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -234,7 +234,7 @@ static int32_t check_tile_range(const char *defcmd, int32_t *tilebeg, int32_t *t { Printf("Warning: %s: backwards tile range on line %s:%d\n", defcmd, script->filename, scriptfile_getlinum(script,cmdtokptr)); - swaplong(tilebeg, tileend); + std::swap(*tilebeg, *tileend); } if ((unsigned)*tilebeg >= MAXUSERTILES || (unsigned)*tileend >= MAXUSERTILES) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 6e44afa85..39498c78e 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -187,9 +187,9 @@ void setslope(int32_t sectnum, int32_t cf, int16_t slope) static int32_t getscore(int32_t w1c, int32_t w1f, int32_t w2c, int32_t w2f) { if (w1c > w1f) - swaplong(&w1c, &w1f); + std::swap(w1c, w1f); if (w2c > w2f) - swaplong(&w2c, &w2f); + std::swap(w2c, w2f); // now: c <= f for each "wall-vline" @@ -1429,9 +1429,9 @@ static void sortsprites(int const start, int const end) for (bssize_t l=i; l>=start; l-=gap) { if (spritesxyz[l].y <= spritesxyz[l+gap].y) break; - swapptr(&tspriteptr[l],&tspriteptr[l+gap]); - swaplong(&spritesxyz[l].x,&spritesxyz[l+gap].x); - swaplong(&spritesxyz[l].y,&spritesxyz[l+gap].y); + std::swap(tspriteptr[l],tspriteptr[l+gap]); + std::swap(spritesxyz[l].x,spritesxyz[l+gap].x); + std::swap(spritesxyz[l].y,spritesxyz[l+gap].y); } ys = spritesxyz[start].y; i = start; @@ -1471,7 +1471,7 @@ static void sortsprites(int const start, int const end) for (bssize_t l=i; l=0; j-=gap) { if (sprite[tsprite[j].owner].z <= sprite[tsprite[j+gap].owner].z) break; - swapshort(&tsprite[j].owner,&tsprite[j+gap].owner); + std::swap(tsprite[j].owner, tsprite[j+gap].owner); } for (s=sortnum-1; s>=0; s--) @@ -3430,7 +3430,7 @@ int32_t getsectordist(vec2_t const in, int const sectnum, vec2_t * const out /*= int findwallbetweensectors(int sect1, int sect2) { if (sector[sect1].wallnum > sector[sect2].wallnum) - swaplong(§1, §2); + std::swap(sect1, sect2); auto const sec = (usectorptr_t)§or[sect1]; int const last = sec->wallptr + sec->wallnum; diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index a0f0a2d95..ea54aa46f 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -917,8 +917,8 @@ static int32_t partition(uint16_t *indexes, float *depths, int32_t f, int32_t l) down--; if (up < down) { - swapfloat(&depths[up], &depths[down]); - swapshort(&indexes[up], &indexes[down]); + std::swap(depths[up], depths[down]); + std::swap(indexes[up], indexes[down]); } } while (down > up); diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 64ac613ea..42df205bd 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -635,10 +635,10 @@ static void polymost_domost(float x0, float y0, float x1, float y1, float y0top else //clip umost (ceiling) { if (x0 == x1) return; - swapfloat(&x0, &x1); - swapfloat(&y0, &y1); - swapfloat(&y0top, &y1top); - swapfloat(&y0bot, &y1bot); + std::swap(x0, x1); + std::swap(y0, y1); + std::swap(y0top, y1top); + std::swap(y0bot, y1bot); y0 += DOMOST_OFFSET; y1 += DOMOST_OFFSET; //necessary? } @@ -715,17 +715,17 @@ static void polymost_domost(float x0, float y0, float x1, float y1, float y0top float const fnx[2] = { dm0.x + ((n[0] / d[0]) * (dm1.x - dm0.x)), dm0.x + ((n[1] / d[1]) * (dm1.x - dm0.x)) }; - if ((Bfabsf(d[0]) > Bfabsf(n[0])) && (d[0] * n[0] >= 0.f) && (fnx[0] > n0.x) && (fnx[0] < n1.x)) + if ((fabsf(d[0]) > fabsf(n[0])) && (d[0] * n[0] >= 0.f) && (fnx[0] > n0.x) && (fnx[0] < n1.x)) spx[scnt] = fnx[0], spt[scnt++] = 0; - if ((Bfabsf(d[1]) > Bfabsf(n[1])) && (d[1] * n[1] >= 0.f) && (fnx[1] > n0.x) && (fnx[1] < n1.x)) + if ((fabsf(d[1]) > fabsf(n[1])) && (d[1] * n[1] >= 0.f) && (fnx[1] > n0.x) && (fnx[1] < n1.x)) spx[scnt] = fnx[1], spt[scnt++] = 1; //Nice hack to avoid full sort later :) if ((scnt >= 2) && (spx[scnt-1] < spx[scnt-2])) { - swapfloat(&spx[scnt-1], &spx[scnt-2]); - swaplong(&spt[scnt-1], &spt[scnt-2]); + std::swap(spx[scnt-1], spx[scnt-2]); + std::swap(spt[scnt-1], spt[scnt-2]); } //Test if right edge requires split @@ -1039,9 +1039,9 @@ static void polymost_internal_nonparallaxed(vec2f_t n0, vec2f_t n1, float ryp0, //Texture flipping if (globalorientation&4) { - swapdouble(&xtex.u, &xtex.v); - swapdouble(&ytex.u, &ytex.v); - swapdouble(&otex.u, &otex.v); + std::swap(xtex.u, xtex.v); + std::swap(ytex.u, ytex.v); + std::swap(otex.u, otex.v); } if (globalorientation&16) { xtex.u = -xtex.u; ytex.u = -ytex.u; otex.u = -otex.u; } @@ -3431,9 +3431,9 @@ void polymost_drawsprite(int32_t snum) if (globalorientation & 64) goto _drawsprite_return; // 1-sided sprite - swapfloat(&sx0, &sx1); - swapfloat(&sc0, &sc1); - swapfloat(&sf0, &sf1); + std::swap(sx0, sx1); + std::swap(sc0, sc1); + std::swap(sf0, sf1); } vec2f_t const pxy[4] = { { sx0, sc0 }, { sx1, sc1 }, { sx1, sf1 }, { sx0, sf0 } }; @@ -3502,8 +3502,8 @@ void polymost_drawsprite(int32_t snum) { static_assert(sizeof(uint64_t) == sizeof(vec2f_t)); - swap64bit(&pxy[0], &pxy[1]); - swap64bit(&pxy[2], &pxy[3]); + std::swap(pxy[0], pxy[1]); + std::swap(pxy[2], pxy[3]); } // Clip to SCISDIST plane