From 62d0d3712eaad67d0413bf892aeebf837883551f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 5 Sep 2021 12:25:52 +0200 Subject: [PATCH] - use a sprite flag to mark mapped sprites. This avoids another global array which needs to be addressed by sprite index. --- source/build/include/buildtypes.h | 1 + source/build/src/polymost.cpp | 2 +- source/core/automap.cpp | 5 +---- source/core/automap.h | 1 - source/core/rendering/scene/hw_drawinfo.cpp | 2 +- source/games/blood/src/actor.cpp | 5 ++--- source/games/blood/src/nnexts.cpp | 7 ++++--- source/games/blood/src/player.cpp | 2 +- source/games/duke/src/spawn.cpp | 4 ++-- source/games/sw/src/draw.cpp | 2 +- 10 files changed, 14 insertions(+), 17 deletions(-) diff --git a/source/build/include/buildtypes.h b/source/build/include/buildtypes.h index 97f922eb329..7a3b792ad0f 100644 --- a/source/build/include/buildtypes.h +++ b/source/build/include/buildtypes.h @@ -191,6 +191,7 @@ enum { CSTAT2_SPRITE_MDLROTATE = 1, // Only for tsprites: rotate if this is a model or voxel. CSTAT2_SPRITE_NOFIND = 2, // Invisible to neartag and hitscan + CSTAT2_SPRITE_MAPPED = 4, // sprite was mapped for automap }; enum diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 02704327307..ef9c09da5e7 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -3253,7 +3253,7 @@ void polymost_drawsprite(int32_t snum) } if ((unsigned)spritenum < MAXSPRITES) - show2dsprite.Set(spritenum); + sprite[spritenum].cstat2 |= CSTAT2_SPRITE_MAPPED; _drawsprite_return: ; diff --git a/source/core/automap.cpp b/source/core/automap.cpp index 98a0b5c6695..51df70fdf1e 100644 --- a/source/core/automap.cpp +++ b/source/core/automap.cpp @@ -63,7 +63,6 @@ bool automapping; bool gFullMap; FixedBitArray show2dsector; FixedBitArray show2dwall; -FixedBitArray show2dsprite; static int x_min_bound = INT_MAX, y_min_bound, x_max_bound, y_max_bound; CVAR(Color, am_twosidedcolor, 0xaaaaaa, CVAR_ARCHIVE) @@ -271,7 +270,6 @@ void SerializeAutomap(FSerializer& arc) // Only store what's needed. Unfortunately for sprites it is not that easy .SerializeMemory("mappedsectors", show2dsector.Storage(), (numsectors + 7) / 8) .SerializeMemory("mappedwalls", show2dwall.Storage(), (numwalls + 7) / 8) - .SerializeMemory("mappedsprites", show2dsprite.Storage(), MAXSPRITES / 8) .EndObject(); } } @@ -287,7 +285,6 @@ void ClearAutomap() { show2dsector.Zero(); show2dwall.Zero(); - show2dsprite.Zero(); x_min_bound = INT_MAX; } @@ -630,7 +627,7 @@ void renderDrawMapView(int cposx, int cposy, int czoom, int cang) vertices.Resize(4); for (auto sn : floorsprites) { - if (!gFullMap && !show2dsprite[sn]) continue; + if (!gFullMap && !(sprite[sn].cstat2 & CSTAT2_SPRITE_MAPPED)) continue; auto spr = &sprite[sn]; vec2_t pp[4]; GetFlatSpritePosition(spr, spr->pos.vec2, pp, true); diff --git a/source/core/automap.h b/source/core/automap.h index 14c10e0b12f..ad8731440c3 100644 --- a/source/core/automap.h +++ b/source/core/automap.h @@ -12,7 +12,6 @@ extern bool automapping; extern bool gFullMap; extern FixedBitArray show2dsector; extern FixedBitArray show2dwall; -extern FixedBitArray show2dsprite; void SerializeAutomap(FSerializer& arc); void ClearAutomap(); diff --git a/source/core/rendering/scene/hw_drawinfo.cpp b/source/core/rendering/scene/hw_drawinfo.cpp index 7e84bbde952..848e6fa0823 100644 --- a/source/core/rendering/scene/hw_drawinfo.cpp +++ b/source/core/rendering/scene/hw_drawinfo.cpp @@ -282,7 +282,7 @@ void HWDrawInfo::DispatchSprites() continue; if ((unsigned)spritenum < MAXSPRITES) - show2dsprite.Set(spritenum); + sprite[spritenum].cstat2 |= CSTAT2_SPRITE_MAPPED; setgotpic(tilenum); diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index 47ad71ce6d4..4f02e7399dd 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -6546,7 +6546,7 @@ DBloodActor* actSpawnThing(int nSector, int x, int y, int z, int nThingType) pSprite->pal = pThingInfo->pal; if (pThingInfo->xrepeat) pSprite->xrepeat = pThingInfo->xrepeat; if (pThingInfo->yrepeat) pSprite->yrepeat = pThingInfo->yrepeat; - show2dsprite.Set(pSprite->index); + pSprite->cstat2 |= CSTAT2_SPRITE_MAPPED; switch (nThingType) { case kThingVoodooHead: @@ -6764,8 +6764,7 @@ DBloodActor* actFireMissile(DBloodActor* actor, int a2, int a3, int a4, int a5, } auto spawned = actSpawnSprite(pSprite->sectnum, x, y, z, 5, 1); spritetype* pMissile = &spawned->s(); - int nMissile = pMissile->index; - show2dsprite.Set(nMissile); + pMissile->cstat2 |= CSTAT2_SPRITE_MAPPED; pMissile->type = nType; pMissile->shade = pMissileInfo->shade; pMissile->pal = 0; diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index c2d1be05926..3a7e13d2ec1 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -1193,9 +1193,9 @@ void nnExtProcessSuperSprites() { int index = sprite[gSightSpritesList[i]].index; // sprite is drawn for one of players - if ((pXSightSpr->unused3 & kTriggerSpriteScreen) && show2dsprite[index]) { + if ((pXSightSpr->unused3 & kTriggerSpriteScreen) && (gSightSpritesList[i]->s().cstat2 & CSTAT2_SPRITE_MAPPED)) trTriggerSprite(index, pXSightSpr, kCmdSpriteSight); - show2dsprite.Clear(index); + gSightSpritesList[i]->s().cstat2 &= ~CSTAT2_SPRITE_MAPPED; continue; } @@ -2521,7 +2521,7 @@ void usePropertiesChanger(XSPRITE* pXSource, short objType, int objIndex) { // set new cstat if ((pSource->flags & kModernTypeFlag1)) pSprite->cstat |= pXSource->data4; // relative - else pSprite->cstat = pXSource->data4; // absolute + else pSprite->cstat = pXSource->data4 & 0xffff; // absolute // and handle exceptions if ((old & 0x1000) && !(pSprite->cstat & 0x1000)) pSprite->cstat |= 0x1000; //kSpritePushable @@ -7839,6 +7839,7 @@ void callbackUniMissileBurst(int nSprite) // 22 pBurst->shade = pSprite->shade; pBurst->picnum = pSprite->picnum; + pBurst->cstat = pSprite->cstat; if ((pBurst->cstat & CSTAT_SPRITE_BLOCK)) { pBurst->cstat &= ~CSTAT_SPRITE_BLOCK; // we don't want missiles impact each other diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index e5ac25729e1..3df3083c720 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -673,7 +673,7 @@ void playerStart(int nPlayer, int bNewLevel) playerResetPosture(pPlayer); seqSpawn(pDudeInfo->seqStartID, 3, pSprite->extra, -1); if (pPlayer == gMe) - show2dsprite.Set(pSprite->index); + actor->s().cstat2 |= CSTAT2_SPRITE_MAPPED; int top, bottom; GetSpriteExtents(pSprite, &top, &bottom); pSprite->z -= bottom - pSprite->z; diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index 71f10735908..24a5ef14196 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -119,8 +119,8 @@ DDukeActor* EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed ch s->hitag = 0; } - if (show2dsector[s->sectnum]) show2dsprite.Set(i); - else show2dsprite.Clear(i); + if (show2dsector[s->sectnum]) act->s->cstat2 |= CSTAT2_SPRITE_MAPPED; + else act->s->cstat2 &= ~CSTAT2_SPRITE_MAPPED; spriteext[i] = {}; spritesmooth[i] = {}; diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 83b234ebac2..d333c4a6a2a 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1738,7 +1738,7 @@ bool GameInterface::DrawAutomapPlayer(int cposx, int cposy, int czoom, int cang, goto SHOWSPRITE; } } - if (gFullMap || show2dsprite[j]) + if (gFullMap || (sprite[j].cstat2 & CSTAT2_SPRITE_MAPPED)) { SHOWSPRITE: spr = &sprite[j];