diff --git a/source/build/include/build.h b/source/build/include/build.h index 66cf2b117..20e66691e 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -449,6 +449,39 @@ static FORCE_INLINE void sprite_tracker_hook__(intptr_t const address) } #endif +static inline tspriteptr_t renderMakeTSpriteFromSprite(tspriteptr_t const tspr, uint16_t const spritenum) +{ + auto const spr = (uspriteptr_t)&sprite[spritenum]; + + tspr->pos = spr->pos; + tspr->cstat = spr->cstat; + tspr->picnum = spr->picnum; + tspr->shade = spr->shade; + tspr->pal = spr->pal; + tspr->blend = spr->blend; + tspr->xrepeat = spr->xrepeat; + tspr->yrepeat = spr->yrepeat; + tspr->xoffset = spr->xoffset; + tspr->yoffset = spr->yoffset; + tspr->sectnum = spr->sectnum; + tspr->statnum = spr->statnum; + tspr->ang = spr->ang; + tspr->vel = spr->vel; + tspr->lotag = spr->lotag; + tspr->hitag = spr->hitag; + + tspr->clipdist = 0; + tspr->owner = spritenum; + tspr->extra = 0; + + return tspr; +} + +static inline tspriteptr_t renderAddTSpriteFromSprite(uint16_t const spritenum) +{ + return renderMakeTSpriteFromSprite(&tsprite[spritesortcnt++], spritenum); +} + EXTERN int16_t maskwall[MAXWALLSB], maskwallcnt; EXTERN int16_t thewall[MAXWALLSB]; diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index ffd1b5992..04fa01fbd 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -824,11 +824,8 @@ static void yax_copytsprites() if (spritesortcnt >= maxspritesonscreen) break; - Bmemcpy(&tsprite[spritesortcnt], spr, sizeof(tspritetype)); - tsprite[spritesortcnt].owner = spritenum; - tsprite[spritesortcnt].extra = 0; - tsprite[spritesortcnt].sectnum = sectnum; // potentially tweak sectnum! - spritesortcnt++; + tspriteptr_t tsp = renderAddTSpriteFromSprite(spritenum); + tsp->sectnum = sectnum; // potentially tweak sectnum! } } @@ -1465,9 +1462,7 @@ int32_t renderAddTsprite(int16_t z, int16_t sectnum) if (spritesortcnt >= maxspritesonscreen) return 1; - Bmemcpy(&tsprite[spritesortcnt], spr, sizeof(tspritetype)); - tsprite[spritesortcnt].extra = 0; - tsprite[spritesortcnt++].owner = z; + renderAddTSpriteFromSprite(z); #ifdef YAX_ENABLE } diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 6cdbe7057..b11adc092 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -362,17 +362,14 @@ static void G_OROR_DupeSprites(spritetype const *sp) if (sprite[k].picnum != SECTOREFFECTOR && sprite[k].z >= sp->z) { - Bmemcpy(&tsprite[spritesortcnt], &sprite[k], sizeof(tspritetype)); + tspriteptr_t tsp = renderAddTSpriteFromSprite(k); - tsprite[spritesortcnt].x += (refsp->x - sp->x); - tsprite[spritesortcnt].y += (refsp->y - sp->y); - tsprite[spritesortcnt].z = tsprite[spritesortcnt].z - sp->z + actor[sp->yvel].ceilingz; - tsprite[spritesortcnt].sectnum = refsp->sectnum; - tsprite[spritesortcnt].owner = k; - tsprite[spritesortcnt].extra = 0; + tsp->x += (refsp->x - sp->x); + tsp->y += (refsp->y - sp->y); + tsp->z += -sp->z + actor[sp->yvel].ceilingz; + tsp->sectnum = refsp->sectnum; -// OSD_Printf("duped sprite of pic %d at %d %d %d\n",tsprite[spritesortcnt].picnum,tsprite[spritesortcnt].x,tsprite[spritesortcnt].y,tsprite[spritesortcnt].z); - spritesortcnt++; +// OSD_Printf("duped sprite of pic %d at %d %d %d\n",tsp->picnum,tsp->x,tsp->y,tsp->z); } } } diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index c8ea08e71..cf90b1a17 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -600,10 +600,7 @@ void WarpCopySprite(void) if (sprite[spnum].picnum == ST1) continue; - tspriteptr_t New = &tsprite[spritesortcnt]; - memcpy(New, &sprite[spnum], sizeof(tspritetype)); - spritesortcnt++; - New->owner = spnum; + tspriteptr_t New = renderAddTSpriteFromSprite(spnum); New->statnum = 0; xoff = sp1->x - New->x; @@ -624,10 +621,7 @@ void WarpCopySprite(void) if (sprite[spnum].picnum == ST1) continue; - tspriteptr_t New = &tsprite[spritesortcnt]; - memcpy(New, &sprite[spnum], sizeof(tspritetype)); - spritesortcnt++; - New->owner = spnum; + tspriteptr_t New = renderAddTSpriteFromSprite(spnum); New->statnum = 0; xoff = sp2->x - New->x; @@ -1492,8 +1486,7 @@ void SpriteSortList2D(int tx, int ty) if (dist < 22000) { - memcpy(&tsprite[spritesortcnt], sp, sizeof(tspritetype)); - tsprite[spritesortcnt++].owner = i; + renderAddTSpriteFromSprite(i); } } }