Skip to content

Commit

Permalink
- use a sprite flag to mark mapped sprites.
Browse files Browse the repository at this point in the history
This avoids another global array which needs to be addressed by sprite index.
  • Loading branch information
coelckers committed Oct 14, 2021
1 parent 88e86b4 commit 62d0d37
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions source/build/include/buildtypes.h
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/build/src/polymost.cpp
Expand Up @@ -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:
;
Expand Down
5 changes: 1 addition & 4 deletions source/core/automap.cpp
Expand Up @@ -63,7 +63,6 @@ bool automapping;
bool gFullMap;
FixedBitArray<MAXSECTORS> show2dsector;
FixedBitArray<MAXWALLS> show2dwall;
FixedBitArray<MAXSPRITES> show2dsprite;
static int x_min_bound = INT_MAX, y_min_bound, x_max_bound, y_max_bound;

CVAR(Color, am_twosidedcolor, 0xaaaaaa, CVAR_ARCHIVE)
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -287,7 +285,6 @@ void ClearAutomap()
{
show2dsector.Zero();
show2dwall.Zero();
show2dsprite.Zero();
x_min_bound = INT_MAX;
}

Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion source/core/automap.h
Expand Up @@ -12,7 +12,6 @@ extern bool automapping;
extern bool gFullMap;
extern FixedBitArray<MAXSECTORS> show2dsector;
extern FixedBitArray<MAXWALLS> show2dwall;
extern FixedBitArray<MAXSPRITES> show2dsprite;

void SerializeAutomap(FSerializer& arc);
void ClearAutomap();
Expand Down
2 changes: 1 addition & 1 deletion source/core/rendering/scene/hw_drawinfo.cpp
Expand Up @@ -282,7 +282,7 @@ void HWDrawInfo::DispatchSprites()
continue;

if ((unsigned)spritenum < MAXSPRITES)
show2dsprite.Set(spritenum);
sprite[spritenum].cstat2 |= CSTAT2_SPRITE_MAPPED;

setgotpic(tilenum);

Expand Down
5 changes: 2 additions & 3 deletions source/games/blood/src/actor.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions source/games/blood/src/nnexts.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/games/blood/src/player.cpp
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions source/games/duke/src/spawn.cpp
Expand Up @@ -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] = {};
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/draw.cpp
Expand Up @@ -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];
Expand Down

0 comments on commit 62d0d37

Please sign in to comment.