- Optimise automap sector loops in Duke/SW automap code.

This commit is contained in:
Mitchell Richters 2022-09-06 09:52:58 +10:00 committed by Christoph Oelckers
parent db5db7d9b3
commit ab77d77a53
2 changed files with 45 additions and 38 deletions

View file

@ -388,32 +388,37 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos,
auto cangvect = cang.ToVector();
// Draw sprites
auto pactor = ps[screenpeek].GetActor();
for (unsigned ii = 0; ii < sector.Size(); ii++)
if (gFullMap)
{
if (!gFullMap || !show2dsector[ii]) continue;
DukeSectIterator it(ii);
while (auto act = it.Next())
for (unsigned ii = 0; ii < sector.Size(); ii++)
{
if (act == pactor || (act->spr.cstat & CSTAT_SPRITE_INVISIBLE) || act->spr.cstat == CSTAT_SPRITE_BLOCK_ALL || act->spr.xrepeat == 0) continue;
PalEntry col = act->spr.cstat & CSTAT_SPRITE_BLOCK ? PalEntry(170, 0, 170) : PalEntry(0, 170, 170);
auto sprpos = act->spr.pos.XY() - cpos;
if ((act->spr.cstat & CSTAT_SPRITE_BLOCK_ALL) != 0) switch (act->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK)
if (show2dsector[ii]) continue;
DukeSectIterator it(ii);
while (auto act = it.Next())
{
case CSTAT_SPRITE_ALIGNMENT_FACING:
DrawAutomapAlignmentFacing(act->spr, sprpos, cangvect, czoom, xydim, col);
break;
if (act == ps[screenpeek].actor || (act->spr.cstat & CSTAT_SPRITE_INVISIBLE) || act->spr.cstat == CSTAT_SPRITE_BLOCK_ALL || act->spr.xrepeat == 0) continue;
case CSTAT_SPRITE_ALIGNMENT_WALL:
if (actorflag(act, SFLAG2_SHOWWALLSPRITEONMAP)) DrawAutomapAlignmentWall(act->spr, sprpos, cangvect, czoom, xydim, col);
break;
if ((act->spr.cstat & CSTAT_SPRITE_BLOCK_ALL) != 0)
{
PalEntry col = act->spr.cstat & CSTAT_SPRITE_BLOCK ? PalEntry(170, 0, 170) : PalEntry(0, 170, 170);
auto sprpos = act->spr.pos.XY() - cpos;
case CSTAT_SPRITE_ALIGNMENT_FLOOR:
case CSTAT_SPRITE_ALIGNMENT_SLOPE:
DrawAutomapAlignmentFloor(act->spr, sprpos, cangvect, czoom, xydim, col);
break;
switch (act->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK)
{
case CSTAT_SPRITE_ALIGNMENT_FACING:
DrawAutomapAlignmentFacing(act->spr, sprpos, cangvect, czoom, xydim, col);
break;
case CSTAT_SPRITE_ALIGNMENT_WALL:
if (actorflag(act, SFLAG2_SHOWWALLSPRITEONMAP)) DrawAutomapAlignmentWall(act->spr, sprpos, cangvect, czoom, xydim, col);
break;
case CSTAT_SPRITE_ALIGNMENT_FLOOR:
case CSTAT_SPRITE_ALIGNMENT_SLOPE:
DrawAutomapAlignmentFloor(act->spr, sprpos, cangvect, czoom, xydim, col);
break;
}
}
}
}
}

View file

@ -1580,27 +1580,29 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos,
auto cangvect = cang.ToVector();
// Draw sprites
for (unsigned i = 0; i < sector.Size(); i++)
if (gFullMap)
{
SWSectIterator it(i);
while (auto actor = it.Next())
for (unsigned i = 0; i < sector.Size(); i++)
{
if (gFullMap || (actor->spr.cstat2 & CSTAT2_SPRITE_MAPPED))
SWSectIterator it(i);
while (auto actor = it.Next())
{
// 1=white / 31=black / 44=green / 56=pink / 128=yellow / 210=blue / 248=orange / 255=purple
PalEntry col = (actor->spr.cstat & CSTAT_SPRITE_BLOCK) > 0 ? GPalette.BaseColors[248] : actor == Player[screenpeek].actor ? GPalette.BaseColors[31] : GPalette.BaseColors[56];
auto statnum = actor->spr.statnum;
auto sprxy = ((statnum >= 1) && (statnum <= 8) && (statnum != 2) ? actor->interpolatedvec3(smoothratio * (1. / MaxSmoothRatio)) : actor->spr.pos).XY() - cpos;
switch (actor->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK)
if (actor->spr.cstat2 & CSTAT2_SPRITE_MAPPED)
{
case CSTAT_SPRITE_ALIGNMENT_WALL: // Rotated sprite
DrawAutomapAlignmentWall(actor->spr, sprxy, cangvect, czoom, xydim, col);
break;
case CSTAT_SPRITE_ALIGNMENT_FLOOR: // Floor sprite
if (automapMode == am_overlay) DrawAutomapAlignmentFloor(actor->spr, sprxy, cangvect, czoom, xydim, col);
break;
// 1=white / 31=black / 44=green / 56=pink / 128=yellow / 210=blue / 248=orange / 255=purple
PalEntry col = (actor->spr.cstat & CSTAT_SPRITE_BLOCK) > 0 ? GPalette.BaseColors[248] : actor == Player[screenpeek].actor ? GPalette.BaseColors[31] : GPalette.BaseColors[56];
auto statnum = actor->spr.statnum;
auto sprxy = ((statnum >= 1) && (statnum <= 8) && (statnum != 2) ? actor->interpolatedvec3(smoothratio * (1. / MaxSmoothRatio)) : actor->spr.pos).XY() - cpos;
switch (actor->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK)
{
case CSTAT_SPRITE_ALIGNMENT_WALL: // Rotated sprite
DrawAutomapAlignmentWall(actor->spr, sprxy, cangvect, czoom, xydim, col);
break;
case CSTAT_SPRITE_ALIGNMENT_FLOOR: // Floor sprite
if (automapMode == am_overlay) DrawAutomapAlignmentFloor(actor->spr, sprxy, cangvect, czoom, xydim, col);
break;
}
}
}
}