- Consolidate some duplicated automap code between Duke and SW.

This commit is contained in:
Mitchell Richters 2022-09-20 10:26:57 +10:00 committed by Christoph Oelckers
parent ef56d00d78
commit f236cc8728
4 changed files with 76 additions and 103 deletions

View file

@ -619,3 +619,73 @@ void DrawOverheadMap(const DVector2& plxy, const DAngle pl_angle, double const s
}
//---------------------------------------------------------------------------
//
// Draws lines for alls in Duke/SW when cstat is CSTAT_SPRITE_ALIGNMENT_WALL.
//
//---------------------------------------------------------------------------
void DrawAutomapAlignmentWall(const spritetype& spr, const DVector2& bpos, const DVector2& cangvect, const double czoom, const DVector2& xydim, const PalEntry& col)
{
auto xrep = spr.xrepeat * REPEAT_SCALE;
auto xspan = tileWidth(spr.picnum);
auto xoff = tileLeftOffset(spr.picnum) + spr.xoffset;
if ((spr.cstat & CSTAT_SPRITE_XFLIP) > 0) xoff = -xoff;
auto sprvec = spr.angle.ToVector().Rotated90CW() * xrep;
auto b1 = bpos - sprvec * ((xspan * 0.5) + xoff);
auto b2 = b1 + sprvec * xspan;
auto v1 = OutAutomapVector(b1, cangvect, czoom, xydim);
auto v2 = OutAutomapVector(b2, cangvect, czoom, xydim);
drawlinergb(v1, v2, col);
}
//---------------------------------------------------------------------------
//
// Draws lines for alls in Duke/SW when cstat is CSTAT_SPRITE_ALIGNMENT_FLOOR.
//
//---------------------------------------------------------------------------
void DrawAutomapAlignmentFloor(const spritetype& spr, const DVector2& bpos, const DVector2& cangvect, const double czoom, const DVector2& xydim, const PalEntry& col)
{
auto xrep = spr.xrepeat * REPEAT_SCALE;
auto yrep = spr.yrepeat * REPEAT_SCALE;
auto xspan = tileWidth(spr.picnum);
auto yspan = tileHeight(spr.picnum);
auto xoff = tileLeftOffset(spr.picnum);
auto yoff = tileTopOffset(spr.picnum);
if (isSWALL() || (spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLOPE)
{
xoff += spr.xoffset;
yoff += spr.yoffset;
}
if ((spr.cstat & CSTAT_SPRITE_XFLIP) > 0) xoff = -xoff;
if ((spr.cstat & CSTAT_SPRITE_YFLIP) > 0) yoff = -yoff;
auto sprvec = spr.angle.ToVector();
auto xscale = sprvec.Rotated90CW() * xspan * xrep;
auto yscale = sprvec * yspan * yrep;
auto xybase = DVector2(((xspan * 0.5) + xoff) * xrep, ((yspan * 0.5) + yoff) * yrep);
auto b1 = bpos + (xybase * sprvec.Y) + (xybase.Rotated90CW() * sprvec.X);
auto b2 = b1 - xscale;
auto b3 = b2 - yscale;
auto b4 = b1 - yscale;
auto v1 = OutAutomapVector(b1, cangvect, czoom, xydim);
auto v2 = OutAutomapVector(b2, cangvect, czoom, xydim);
auto v3 = OutAutomapVector(b3, cangvect, czoom, xydim);
auto v4 = OutAutomapVector(b4, cangvect, czoom, xydim);
drawlinergb(v1, v2, col);
drawlinergb(v2, v3, col);
drawlinergb(v3, v4, col);
drawlinergb(v4, v1, col);
}

View file

@ -19,6 +19,8 @@ void MarkSectorSeen(sectortype* sect);
void DrawOverheadMap(const DVector2& plxy, const DAngle pl_angle, double const smoothratio);
bool AM_Responder(event_t* ev, bool last);
void drawlinergb(const DVector2& v1, const DVector2& v2, PalEntry p);
void DrawAutomapAlignmentWall(const spritetype& spr, const DVector2& bpos, const DVector2& cangvect, const double czoom, const DVector2& xydim, const PalEntry& col);
void DrawAutomapAlignmentFloor(const spritetype& spr, const DVector2& bpos, const DVector2& cangvect, const double czoom, const DVector2& xydim, const PalEntry& col);
inline DVector2 OutAutomapVector(const DVector2& pos, const DVector2& angvect, const double zoom = 1., const DVector2& xydim = { 0, 0 })
{

View file

@ -415,63 +415,12 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos,
break;
case CSTAT_SPRITE_ALIGNMENT_WALL:
if (actorflag(act, SFLAG2_SHOWWALLSPRITEONMAP))
{
tilenum = act->spr.picnum;
xoff = tileLeftOffset(tilenum) + act->spr.xoffset;
if ((act->spr.cstat & CSTAT_SPRITE_XFLIP) > 0) xoff = -xoff;
xspan = tileWidth(tilenum);
b0 = act->spr.angle.ToVector().Rotated90CW() * act->spr.xrepeat * (1. / 64.);
b1 = act->spr.pos.XY() - b0 * ((xspan * 0.5) + xoff) - cpos;
b2 = b1 + b0 * xspan;
v1 = OutAutomapVector(b1, cangvect, czoom, xydim);
v2 = OutAutomapVector(b2, cangvect, czoom, xydim);
drawlinergb(v1, v2, col);
}
if (actorflag(act, SFLAG2_SHOWWALLSPRITEONMAP)) DrawAutomapAlignmentWall(act->spr, act->spr.pos.XY() - cpos, cangvect, czoom, xydim, col);
break;
case CSTAT_SPRITE_ALIGNMENT_FLOOR:
case CSTAT_SPRITE_ALIGNMENT_SLOPE:
tilenum = act->spr.picnum;
xoff = tileLeftOffset(tilenum);
yoff = tileTopOffset(tilenum);
if ((act->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLOPE)
{
xoff += act->spr.xoffset;
yoff += act->spr.yoffset;
}
if ((act->spr.cstat & CSTAT_SPRITE_XFLIP) > 0) xoff = -xoff;
if ((act->spr.cstat & CSTAT_SPRITE_YFLIP) > 0) yoff = -yoff;
xspan = tileWidth(tilenum);
auto xrep = act->spr.xrepeat * (1. / 64.);
yspan = tileHeight(tilenum);
auto yrep = act->spr.yrepeat * (1. / 64.);
auto sprvec = act->spr.angle.ToVector();
auto xscale = sprvec.Rotated90CW() * xspan * xrep;
auto yscale = sprvec * yspan * yrep;
b0 = DVector2(((xspan * 0.5) + xoff) * xrep, ((yspan * 0.5) + yoff) * yrep);
b1 = act->spr.pos.XY() + (b0 * sprvec.Y) + (b0.Rotated90CW() * sprvec.X) - cpos;
b2 = b1 - xscale;
b3 = b2 - yscale;
b4 = b1 - yscale;
v1 = OutAutomapVector(b1, cangvect, czoom, xydim);
v2 = OutAutomapVector(b2, cangvect, czoom, xydim);
v3 = OutAutomapVector(b3, cangvect, czoom, xydim);
v4 = OutAutomapVector(b4, cangvect, czoom, xydim);
drawlinergb(v1, v2, col);
drawlinergb(v2, v3, col);
drawlinergb(v3, v4, col);
drawlinergb(v4, v1, col);
DrawAutomapAlignmentFloor(act->spr, act->spr.pos.XY() - cpos, cangvect, czoom, xydim, col);
break;
}
}

View file

@ -1641,58 +1641,10 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos,
}
break;
case CSTAT_SPRITE_ALIGNMENT_WALL: // Rotated sprite
tilenum = actor->spr.picnum;
xoff = (int)tileLeftOffset(tilenum) + (int)actor->spr.xoffset;
if ((actor->spr.cstat & CSTAT_SPRITE_XFLIP) > 0)
xoff = -xoff;
xspan = tileWidth(tilenum);
b0 = actor->spr.angle.ToVector().Rotated90CW() * actor->spr.xrepeat * (1. / 64.);
b1 = sprxy - b0 * ((xspan * 0.5) + xoff) - cpos;
b2 = b1 + b0 * xspan;
v1 = OutAutomapVector(b1, cangvect, czoom, xydim);
v2 = OutAutomapVector(b2, cangvect, czoom, xydim);
drawlinergb(v1, v2, col);
DrawAutomapAlignmentWall(actor->spr, sprxy - cpos, cangvect, czoom, xydim, col);
break;
case CSTAT_SPRITE_ALIGNMENT_FLOOR: // Floor sprite
if (automapMode == am_overlay)
{
tilenum = actor->spr.picnum;
xoff = (int)tileLeftOffset(tilenum) + (int)actor->spr.xoffset;
yoff = (int)tileTopOffset(tilenum) + (int)actor->spr.yoffset;
if ((actor->spr.cstat & CSTAT_SPRITE_XFLIP) > 0)
xoff = -xoff;
if ((actor->spr.cstat & CSTAT_SPRITE_YFLIP) > 0)
yoff = -yoff;
xspan = tileWidth(tilenum);
auto xrep = actor->spr.xrepeat * (1. / 64.);
yspan = tileHeight(tilenum);
auto yrep = actor->spr.yrepeat * (1. / 64.);
auto sprvec = actor->spr.angle.ToVector();
auto xscale = sprvec.Rotated90CW() * xspan * xrep;
auto yscale = sprvec * yspan * yrep;
b0 = DVector2(((xspan * 0.5) + xoff) * xrep, ((yspan * 0.5) + yoff) * yrep);
b1 = sprxy + (b0 * sprvec.Y) + (b0.Rotated90CW() * sprvec.X) - cpos;
b2 = b1 - xscale;
b3 = b2 - yscale;
b4 = b1 - yscale;
v1 = OutAutomapVector(b1, cangvect, czoom, xydim);
v2 = OutAutomapVector(b2, cangvect, czoom, xydim);
v3 = OutAutomapVector(b3, cangvect, czoom, xydim);
v4 = OutAutomapVector(b4, cangvect, czoom, xydim);
drawlinergb(v1, v2, col);
drawlinergb(v2, v3, col);
drawlinergb(v3, v4, col);
drawlinergb(v4, v1, col);
}
if (automapMode == am_overlay) DrawAutomapAlignmentFloor(actor->spr, sprxy - cpos, cangvect, czoom, xydim, col);
break;
}
}