From 8e6a54a1e4871b72609f4dd6bcebb5a34f051e7d Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Thu, 26 Dec 2019 06:27:48 +0000 Subject: [PATCH] Mostly clean up the codebase in preparation for tspritetype != uspritetype Remaining exceptions: SW - ConnectCopySprite CON and M32Script - pSprite/pUSprite git-svn-id: https://svn.eduke32.com/eduke32@8519 1a8010ca-5511-0410-912e-c29ae57300e0 # Conflicts: # source/build/include/polymer.h # source/build/src/engine.cpp # source/build/src/engine_priv.h # source/build/src/polymer.cpp # source/build/src/polymost.cpp # source/duke3d/src/astub.cpp # source/duke3d/src/game.h # source/duke3d/src/m32common.cpp # source/duke3d/src/m32exec.cpp # source/duke3d/src/m32structures.cpp # source/kenbuild/src/bstub.cpp # source/kenbuild/src/game.cpp # source/sw/src/jnstub.cpp # source/sw/src/jsector.cpp --- source/build/include/build.h | 2 +- source/build/include/polymost.h | 2 +- source/build/src/engine.cpp | 72 ++------------------------------- source/build/src/engine_priv.h | 72 ++++++++++++++++++++++++++++++--- source/build/src/polymost.cpp | 7 ++-- source/duke3d/src/game.cpp | 5 ++- source/duke3d/src/game.h | 35 ++++++++-------- source/sw/src/draw.cpp | 48 ++++++++++------------ source/sw/src/jsector.cpp | 5 ++- source/sw/src/jsector.h | 2 +- 10 files changed, 122 insertions(+), 128 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index b1b3a1a75..502f3d8e5 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -337,7 +337,7 @@ typedef struct { uint8_t filler; float alpha; // NOTE: keep 'tspr' on an 8-byte boundary: - uspritetype *tspr; + tspriteptr_t tspr; #if !defined UINTPTR_MAX # error Need UINTPTR_MAX define to select between 32- and 64-bit structs #endif diff --git a/source/build/include/polymost.h b/source/build/include/polymost.h index cc1335e0f..bfe7a6a1c 100644 --- a/source/build/include/polymost.h +++ b/source/build/include/polymost.h @@ -39,7 +39,7 @@ void polymost_prepareMirror(int32_t dax, int32_t day, int32_t daz, fix16_t daang void polymost_completeMirror(); int32_t polymost_maskWallHasTranslucency(uwalltype const * const wall); -int32_t polymost_spriteHasTranslucency(uspritetype const * const tspr); +int32_t polymost_spriteHasTranslucency(tspritetype const * const tspr); float* multiplyMatrix4f(float m0[4*4], const float m1[4*4]); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 2e34d2d9c..a51456f77 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -823,7 +823,7 @@ static void yax_copytsprites() if (spritesortcnt >= maxspritesonscreen) break; - Bmemcpy(&tsprite[spritesortcnt], spr, sizeof(spritetype)); + Bmemcpy(&tsprite[spritesortcnt], spr, sizeof(tspritetype)); tsprite[spritesortcnt].owner = spritenum; tsprite[spritesortcnt].extra = 0; tsprite[spritesortcnt].sectnum = sectnum; // potentially tweak sectnum! @@ -1478,7 +1478,7 @@ int32_t renderAddTsprite(int16_t z, int16_t sectnum) if (spritesortcnt >= maxspritesonscreen) return 1; - Bmemcpy(&tsprite[spritesortcnt], spr, sizeof(spritetype)); + Bmemcpy(&tsprite[spritesortcnt], spr, sizeof(tspritetype)); tsprite[spritesortcnt].extra = 0; tsprite[spritesortcnt++].owner = z; @@ -2051,7 +2051,7 @@ int32_t wallfront(int32_t l1, int32_t l2) // // spritewallfront (internal) // -static inline int32_t spritewallfront(uspriteptr_t s, int32_t w) +static inline int32_t spritewallfront(tspritetype const * const s, int32_t w) { auto const wal = (uwallptr_t)&wall[w]; auto const wal2 = (uwallptr_t)&wall[wal->point2]; @@ -8863,7 +8863,7 @@ killsprite: if ((tspr->cstat & 48) != 16) tspriteptr[i]->ang = globalang; - get_wallspr_points((uspriteptr_t)tspr, &xx[0], &xx[1], &yy[0], &yy[1]); + get_wallspr_points(tspr, &xx[0], &xx[1], &yy[0], &yy[1]); if (!playing_blood? ((tspr->cstat & 48) == 0) : ((tspr->cstat & 48) != 16)) tspriteptr[i]->ang = oang; @@ -10604,70 +10604,6 @@ add_nextsector: return 0; } -// x1, y1: in/out -// rest x/y: out -void get_wallspr_points(uspriteptr_t const spr, int32_t *x1, int32_t *x2, - int32_t *y1, int32_t *y2) -{ - //These lines get the 2 points of the rotated sprite - //Given: (x1, y1) starts out as the center point - - const int32_t tilenum=spr->picnum, ang=spr->ang; - const int32_t xrepeat = spr->xrepeat; - int32_t xoff = picanm[tilenum].xofs + spr->xoffset; - int32_t k, l, dax, day; - - if (spr->cstat&4) - xoff = -xoff; - - dax = sintable[ang&2047]*xrepeat; - day = sintable[(ang+1536)&2047]*xrepeat; - - l = tilesiz[tilenum].x; - k = (l>>1)+xoff; - - *x1 -= mulscale16(dax,k); - *x2 = *x1 + mulscale16(dax,l); - - *y1 -= mulscale16(day,k); - *y2 = *y1 + mulscale16(day,l); -} - -// x1, y1: in/out -// rest x/y: out -void get_floorspr_points(uspriteptr_t const spr, int32_t px, int32_t py, - int32_t *x1, int32_t *x2, int32_t *x3, int32_t *x4, - int32_t *y1, int32_t *y2, int32_t *y3, int32_t *y4) -{ - const int32_t tilenum = spr->picnum; - const int32_t cosang = sintable[(spr->ang+512)&2047]; - const int32_t sinang = sintable[spr->ang&2047]; - - vec2_t const span = { tilesiz[tilenum].x, tilesiz[tilenum].y}; - vec2_t const repeat = { spr->xrepeat, spr->yrepeat }; - - vec2_t adjofs = { picanm[tilenum].xofs + spr->xoffset, picanm[tilenum].yofs + spr->yoffset }; - - if (spr->cstat & 4) - adjofs.x = -adjofs.x; - - if (spr->cstat & 8) - adjofs.y = -adjofs.y; - - vec2_t const center = { ((span.x >> 1) + adjofs.x) * repeat.x, ((span.y >> 1) + adjofs.y) * repeat.y }; - vec2_t const rspan = { span.x * repeat.x, span.y * repeat.y }; - vec2_t const ofs = { -mulscale16(cosang, rspan.y), -mulscale16(sinang, rspan.y) }; - - *x1 += dmulscale16(sinang, center.x, cosang, center.y) - px; - *y1 += dmulscale16(sinang, center.y, -cosang, center.x) - py; - - *x2 = *x1 - mulscale16(sinang, rspan.x); - *y2 = *y1 + mulscale16(cosang, rspan.x); - - *x3 = *x2 + ofs.x, *x4 = *x1 + ofs.x; - *y3 = *y2 + ofs.y, *y4 = *y1 + ofs.y; -} - // // neartag // diff --git a/source/build/src/engine_priv.h b/source/build/src/engine_priv.h index 490fee68a..f641fef14 100644 --- a/source/build/src/engine_priv.h +++ b/source/build/src/engine_priv.h @@ -132,12 +132,6 @@ extern int16_t bunchp2[MAXWALLSB]; extern int16_t numscans, numbunches; extern int32_t rxi[8], ryi[8]; -extern void get_wallspr_points(uspriteptr_t spr, int32_t *x1, int32_t *x2, - int32_t *y1, int32_t *y2); -extern void get_floorspr_points(uspriteptr_t spr, int32_t px, int32_t py, - int32_t *x1, int32_t *x2, int32_t *x3, int32_t *x4, - int32_t *y1, int32_t *y2, int32_t *y3, int32_t *y4); - // int32_t wallmost(int16_t *mostbuf, int32_t w, int32_t sectnum, char dastat); int32_t wallfront(int32_t l1, int32_t l2); @@ -239,4 +233,70 @@ template static FORCE_INLINE void tileUpdatePicnum(T * const tilept tile = RotTile(tile).newtile; } +// x1, y1: in/out +// rest x/y: out +template +static inline void get_wallspr_points(T const * const spr, int32_t *x1, int32_t *x2, + int32_t *y1, int32_t *y2) +{ + //These lines get the 2 points of the rotated sprite + //Given: (x1, y1) starts out as the center point + + const int32_t tilenum=spr->picnum, ang=spr->ang; + const int32_t xrepeat = spr->xrepeat; + int32_t xoff = picanm[tilenum].xofs + spr->xoffset; + int32_t k, l, dax, day; + + if (spr->cstat&4) + xoff = -xoff; + + dax = sintable[ang&2047]*xrepeat; + day = sintable[(ang+1536)&2047]*xrepeat; + + l = tilesiz[tilenum].x; + k = (l>>1)+xoff; + + *x1 -= mulscale16(dax,k); + *x2 = *x1 + mulscale16(dax,l); + + *y1 -= mulscale16(day,k); + *y2 = *y1 + mulscale16(day,l); +} + +// x1, y1: in/out +// rest x/y: out +template +static inline void get_floorspr_points(T const * const spr, int32_t px, int32_t py, + int32_t *x1, int32_t *x2, int32_t *x3, int32_t *x4, + int32_t *y1, int32_t *y2, int32_t *y3, int32_t *y4) +{ + const int32_t tilenum = spr->picnum; + const int32_t cosang = sintable[(spr->ang+512)&2047]; + const int32_t sinang = sintable[spr->ang&2047]; + + vec2_t const span = { tilesiz[tilenum].x, tilesiz[tilenum].y}; + vec2_t const repeat = { spr->xrepeat, spr->yrepeat }; + + vec2_t adjofs = { picanm[tilenum].xofs + spr->xoffset, picanm[tilenum].yofs + spr->yoffset }; + + if (spr->cstat & 4) + adjofs.x = -adjofs.x; + + if (spr->cstat & 8) + adjofs.y = -adjofs.y; + + vec2_t const center = { ((span.x >> 1) + adjofs.x) * repeat.x, ((span.y >> 1) + adjofs.y) * repeat.y }; + vec2_t const rspan = { span.x * repeat.x, span.y * repeat.y }; + vec2_t const ofs = { -mulscale16(cosang, rspan.y), -mulscale16(sinang, rspan.y) }; + + *x1 += dmulscale16(sinang, center.x, cosang, center.y) - px; + *y1 += dmulscale16(sinang, center.y, -cosang, center.x) - py; + + *x2 = *x1 - mulscale16(sinang, rspan.x); + *y2 = *y1 + mulscale16(cosang, rspan.x); + + *x3 = *x2 + ofs.x, *x4 = *x1 + ofs.x; + *y3 = *y2 + ofs.y, *y4 = *y1 + ofs.y; +} + #endif /* ENGINE_PRIV_H */ diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 5b41010b4..a8fc02509 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -416,7 +416,7 @@ int32_t polymost_maskWallHasTranslucency(uwalltype const * const wall) return tex && tex->GetTranslucency(); } -int32_t polymost_spriteHasTranslucency(uspritetype const * const tspr) +int32_t polymost_spriteHasTranslucency(tspritetype const * const tspr) { if ((tspr->cstat & (CSTAT_SPRITE_TRANSLUCENT | CSTAT_SPRITE_RESERVED1)) || ((unsigned)tspr->owner < MAXSPRITES && spriteext[tspr->owner].alpha)) @@ -3849,7 +3849,7 @@ void Polymost_prepare_loadboard(void) Bmemset(wsprinfo, 0, sizeof(wsprinfo)); } -static inline int32_t polymost_findwall(uspriteptr_t const tspr, vec2_t const * const tsiz, int32_t * rd) +static inline int32_t polymost_findwall(tspritetype const * const tspr, vec2_t const * const tsiz, int32_t * rd) { int32_t dist = 4, closest = -1; auto const sect = (usectortype * )§or[tspr->sectnum]; @@ -4573,8 +4573,7 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a, vec3f_t vec1; - uspritetype tspr; - Bmemset(&tspr, 0, sizeof(spritetype)); + tspritetype tspr{}; hudtyp const * const hud = tile2model[tilenum].hudmem[(dastat&4)>>2]; diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 6b005d4db..e16daa1ca 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -360,7 +360,7 @@ static void G_OROR_DupeSprites(spritetype const *sp) if (sprite[k].picnum != SECTOREFFECTOR && sprite[k].z >= sp->z) { - Bmemcpy(&tsprite[spritesortcnt], &sprite[k], sizeof(spritetype)); + Bmemcpy(&tsprite[spritesortcnt], &sprite[k], sizeof(tspritetype)); tsprite[spritesortcnt].x += (refsp->x - sp->x); tsprite[spritesortcnt].y += (refsp->y - sp->y); @@ -3621,6 +3621,7 @@ void G_DoSpriteAnimations(int32_t ourx, int32_t oury, int32_t ourz, int32_t oura const int32_t i = t->owner; // XXX: what's up with the (i < 0) check? // NOTE: not const spritetype because set at SET_SPRITE_NOT_TSPRITE (see below). + EDUKE32_STATIC_ASSERT(sizeof(uspritetype) == sizeof(tspritetype)); // see TSPRITE_SIZE auto const pSprite = (i < 0) ? (uspriteptr_t)&tsprite[j] : (uspriteptr_t)&sprite[i]; #ifndef EDUKE32_STANDALONE @@ -3762,7 +3763,7 @@ void G_DoSpriteAnimations(int32_t ourx, int32_t oury, int32_t ourz, int32_t oura { auto const newt = &tsprite[spritesortcnt++]; - Bmemcpy(newt, t, sizeof(spritetype)); + *newt = *t; newt->cstat |= 2|512; newt->x += (sintable[(newt->ang+512)&2047]>>12); diff --git a/source/duke3d/src/game.h b/source/duke3d/src/game.h index 45385896e..1983cde1d 100644 --- a/source/duke3d/src/game.h +++ b/source/duke3d/src/game.h @@ -462,23 +462,6 @@ static inline int G_GetMusicIdx(const char *str) return (ep * MAXLEVELS) + lev; } -static inline int G_GetViewscreenSizeShift(uspriteptr_t const spr) -{ -#if VIEWSCREENFACTOR == 0 - UNREFERENCED_PARAMETER(spr); - return VIEWSCREENFACTOR; -#else - static const int mask = (1<xrepeat & mask) | (spr->yrepeat & mask); - - for (int i=0; i < VIEWSCREENFACTOR; i++) - if (rem & (1< +static inline int G_GetViewscreenSizeShift(T const * spr) +{ +#if VIEWSCREENFACTOR == 0 + UNREFERENCED_PARAMETER(spr); + return VIEWSCREENFACTOR; +#else + static CONSTEXPR int const mask = (1<xrepeat & mask) | (spr->yrepeat & mask); + + for (int i=0; i < VIEWSCREENFACTOR; i++) + if (rem & (1<shade = sector[tsp->sectnum].floorshade - 25; @@ -104,7 +104,7 @@ GetRotation(short tSpriteNum, int viewx, int viewy) short rotation; extern short screenpeek; - uspritetype * tsp = &tsprite[tSpriteNum]; + tspriteptr_t tsp = &tsprite[tSpriteNum]; USERp tu = User[tsp->owner]; PLAYERp pp = Player + screenpeek; short angle2; @@ -172,7 +172,7 @@ directions was not standardized. int SetActorRotation(short tSpriteNum, int viewx, int viewy) { - uspritetype * tsp = &tsprite[tSpriteNum]; + tspriteptr_t tsp = &tsprite[tSpriteNum]; USERp tu = User[tsp->owner]; short StateOffset, Rotation; @@ -233,7 +233,7 @@ SetActorRotation(short tSpriteNum, int viewx, int viewy) } int -DoShadowFindGroundPoint(uspritetype * sp) +DoShadowFindGroundPoint(tspriteptr_t sp) { // USES TSPRITE !!!!! USERp u = User[sp->owner]; @@ -369,9 +369,9 @@ DoVoxelShadow(SPRITEp tspr) #endif void -DoShadows(uspritetype * tsp, int viewz) +DoShadows(tspriteptr_t tsp, int viewz) { - uspritetype * New = &tsprite[spritesortcnt]; + tspriteptr_t New = &tsprite[spritesortcnt]; USERp tu = User[tsp->owner]; int ground_dist = 0; int view_dist = 0; @@ -396,7 +396,7 @@ DoShadows(uspritetype * tsp, int viewz) } tsp->sectnum = sectnum; - memcpy(New, tsp, sizeof(SPRITE)); + *New = *tsp; // shadow is ALWAYS draw last - status is priority New->statnum = MAXSTATUS; New->sectnum = sectnum; @@ -464,9 +464,8 @@ DoShadows(uspritetype * tsp, int viewz) } void -DoMotionBlur(uspritetype const * tsp) +DoMotionBlur(tspritetype const * const tsp) { - uspritetype * New; USERp tu = User[tsp->owner]; int nx,ny,nz = 0,dx,dy,dz; short i, ang; @@ -537,8 +536,8 @@ DoMotionBlur(uspritetype const * tsp) for (i = 0; i < tu->motion_blur_num; i++) { - New = &tsprite[spritesortcnt]; - memcpy(New, tsp, sizeof(SPRITE)); + tspriteptr_t New = &tsprite[spritesortcnt]; + *New = *tsp; SET(New->cstat, CSTAT_SPRITE_TRANSLUCENT|CSTAT_SPRITE_TRANSLUCENT_INVERT); New->x += dx; @@ -569,7 +568,6 @@ void SetVoxelSprite(SPRITEp sp, short pic) void WarpCopySprite(void) { SPRITEp sp1, sp2, sp; - uspritetype * New; short sn, nsn; short sn2, nsn2; short spnum, next_spnum; @@ -602,8 +600,8 @@ void WarpCopySprite(void) if (sprite[spnum].picnum == ST1) continue; - New = &tsprite[spritesortcnt]; - memcpy(New, &sprite[spnum], sizeof(SPRITE)); + tspriteptr_t New = &tsprite[spritesortcnt]; + memcpy(New, &sprite[spnum], sizeof(tspritetype)); spritesortcnt++; New->owner = spnum; New->statnum = 0; @@ -626,8 +624,8 @@ void WarpCopySprite(void) if (sprite[spnum].picnum == ST1) continue; - New = &tsprite[spritesortcnt]; - memcpy(New, &sprite[spnum], sizeof(SPRITE)); + tspriteptr_t New = &tsprite[spritesortcnt]; + memcpy(New, &sprite[spnum], sizeof(tspritetype)); spritesortcnt++; New->owner = spnum; New->statnum = 0; @@ -646,7 +644,7 @@ void WarpCopySprite(void) } } -void DoStarView(uspritetype * tsp, USERp tu, int viewz) +void DoStarView(tspriteptr_t tsp, USERp tu, int viewz) { extern STATE s_Star[], s_StarDown[]; extern STATE s_StarStuck[], s_StarDownStuck[]; @@ -675,7 +673,6 @@ analyzesprites(int viewx, int viewy, int viewz, SWBOOL mirror) int tSpriteNum, j, k; short SpriteNum, pnum; int smr4, smr2; - uspritetype * tsp; USERp tu; static int ang = 0; PLAYERp pp = Player + screenpeek; @@ -690,7 +687,7 @@ analyzesprites(int viewx, int viewy, int viewz, SWBOOL mirror) for (tSpriteNum = spritesortcnt - 1; tSpriteNum >= 0; tSpriteNum--) { SpriteNum = tsprite[tSpriteNum].owner; - tsp = &tsprite[tSpriteNum]; + tspriteptr_t tsp = &tsprite[tSpriteNum]; tu = User[SpriteNum]; //if(tsp->statnum == STAT_GENERIC_QUEUE) @@ -901,7 +898,8 @@ analyzesprites(int viewx, int viewy, int viewz, SWBOOL mirror) if (OverlapDraw && FAF_ConnectArea(tsp->sectnum) && tsp->owner >= 0) { - ConnectCopySprite(tsp); + EDUKE32_STATIC_ASSERT(sizeof(uspritetype) == sizeof(tspritetype)); // see TSPRITE_SIZE + ConnectCopySprite((uspriteptr_t)tsp); } // @@ -977,8 +975,7 @@ analyzesprites(int viewx, int viewy, int viewz, SWBOOL mirror) } #if 1 -uspritetype * -get_tsprite(short SpriteNum) +tspriteptr_t get_tsprite(short SpriteNum) { int tSpriteNum; @@ -996,14 +993,13 @@ post_analyzesprites(void) { int tSpriteNum; short SpriteNum; - uspritetype * tsp; USERp tu; for (tSpriteNum = spritesortcnt - 1; tSpriteNum >= 0; tSpriteNum--) { SpriteNum = tsprite[tSpriteNum].owner; if (SpriteNum < 0) continue; // JBF: verify this is safe - tsp = &tsprite[tSpriteNum]; + tspriteptr_t tsp = &tsprite[tSpriteNum]; tu = User[SpriteNum]; if (tu) @@ -1011,7 +1007,7 @@ post_analyzesprites(void) if (tu->ID == FIREBALL_FLAMES && tu->Attach >= 0) { //uspritetype * const atsp = &sprite[tu->Attach]; - uspritetype * const atsp = get_tsprite(tu->Attach); + tspriteptr_t const atsp = get_tsprite(tu->Attach); if (!atsp) { @@ -1496,7 +1492,7 @@ void SpriteSortList2D(int tx, int ty) if (dist < 22000) { - memcpy(&tsprite[spritesortcnt], sp, sizeof(SPRITE)); + memcpy(&tsprite[spritesortcnt], sp, sizeof(tspritetype)); tsprite[spritesortcnt++].owner = i; } } diff --git a/source/sw/src/jsector.cpp b/source/sw/src/jsector.cpp index 16ab9c1a5..05fc7ab5f 100644 --- a/source/sw/src/jsector.cpp +++ b/source/sw/src/jsector.cpp @@ -806,7 +806,7 @@ JS_DrawMirrors(PLAYERp pp, int tx, int ty, int tz, short tpang, int tphoriz) } void -DoAutoSize(uspritetype * tspr) +DoAutoSize(tspriteptr_t tspr) { short i; @@ -957,7 +957,8 @@ DoAutoSize(uspritetype * tspr) // Rotation angles for sprites short rotang = 0; -void JAnalyzeSprites(uspritetype * tspr) +void +JAnalyzeSprites(tspriteptr_t tspr) { int i, currsprite; diff --git a/source/sw/src/jsector.h b/source/sw/src/jsector.h index 3ac8a8660..05f53dcba 100644 --- a/source/sw/src/jsector.h +++ b/source/sw/src/jsector.h @@ -70,7 +70,7 @@ extern short floormirrorsector[MAXMIRRORS]; extern SWBOOL mirrorinview; extern short NormalVisibility; -void JAnalyzeSprites(uspritetype * tspr); +void JAnalyzeSprites(tspriteptr_t tspr); void JS_DrawMirrors(PLAYERp pp,int tx,int ty,int tz,short tpang,int tphoriz); void JS_InitMirrors(void); void JS_InitLockouts(void);