diff --git a/source/common/2d/v_2ddrawer.cpp b/source/common/2d/v_2ddrawer.cpp index 2971e4f4c..1316dfa86 100644 --- a/source/common/2d/v_2ddrawer.cpp +++ b/source/common/2d/v_2ddrawer.cpp @@ -1040,7 +1040,7 @@ void F2DDrawer::ClearScreen(PalEntry color) // //========================================================================== -void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha) +void F2DDrawer::AddLine(const DVector2& v1, const DVector2& v2, const IntRect* clip, uint32_t color, uint8_t alpha) { PalEntry p = (PalEntry)color; p.a = alpha; @@ -1064,8 +1064,8 @@ void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRec dg.transform = this->transform; dg.transform.Cells[0][2] += offset.X; dg.transform.Cells[1][2] += offset.Y; - mVertices[dg.mVertIndex].Set(x1, y1, 0, 0, 0, p); - mVertices[dg.mVertIndex+1].Set(x2, y2, 0, 0, 0, p); + mVertices[dg.mVertIndex].Set(v1.X, v1.Y, 0, 0, 0, p); + mVertices[dg.mVertIndex+1].Set(v2.X, v2.Y, 0, 0, 0, p); AddCommand(&dg); } @@ -1075,23 +1075,20 @@ void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRec // //========================================================================== -void F2DDrawer::AddThickLine(double x1, double y1, double x2, double y2, double thickness, uint32_t color, uint8_t alpha) +void F2DDrawer::AddThickLine(const DVector2& v1, const DVector2& v2, double thickness, uint32_t color, uint8_t alpha) { PalEntry p = (PalEntry)color; p.a = alpha; - DVector2 point0(x1, y1); - DVector2 point1(x2, y2); - - DVector2 delta = point1 - point0; - DVector2 perp(-delta.Y, delta.X); + DVector2 delta = v2 - v1; + DVector2 perp = delta.Rotated90CCW(); perp.MakeUnit(); perp *= thickness / 2; - DVector2 corner0 = point0 + perp; - DVector2 corner1 = point0 - perp; - DVector2 corner2 = point1 + perp; - DVector2 corner3 = point1 - perp; + DVector2 corner0 = v1 + perp; + DVector2 corner1 = v1 - perp; + DVector2 corner2 = v2 + perp; + DVector2 corner3 = v2 - perp; RenderCommand dg; diff --git a/source/common/2d/v_2ddrawer.h b/source/common/2d/v_2ddrawer.h index 038de6199..82c8aeada 100644 --- a/source/common/2d/v_2ddrawer.h +++ b/source/common/2d/v_2ddrawer.h @@ -227,8 +227,8 @@ public: void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color); - void AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha = 255); - void AddThickLine(double x1, double y1, double x2, double y2, double thickness, uint32_t color, uint8_t alpha = 255); + void AddLine(const DVector2& v1, const DVector2& v2, const IntRect* clip, uint32_t color, uint8_t alpha = 255); + void AddThickLine(const DVector2& v1, const DVector2& v2, double thickness, uint32_t color, uint8_t alpha = 255); void AddPixel(int x1, int y1, uint32_t color); void AddEnableStencil(bool on); diff --git a/source/common/2d/v_draw.cpp b/source/common/2d/v_draw.cpp index 3d56829ba..f740ce4b3 100644 --- a/source/common/2d/v_draw.cpp +++ b/source/common/2d/v_draw.cpp @@ -1555,10 +1555,10 @@ void VirtualToRealCoordsInt(F2DDrawer *drawer, int &x, int &y, int &w, int &h, // //========================================================================== -static void DrawLine(int x0, int y0, int x1, int y1, uint32_t realcolor, int alpha) +static void DrawLine(const DVector2& v1, const DVector2& v2, uint32_t realcolor, int alpha) { if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); - twod->AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, realcolor | MAKEARGB(255, 0, 0, 0), alpha); + twod->AddLine(v1, v2, nullptr, realcolor | MAKEARGB(255, 0, 0, 0), alpha); } DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine) @@ -1570,7 +1570,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine) PARAM_INT(y1); PARAM_INT(color); PARAM_INT(alpha); - DrawLine(x0, y0, x1, y1, color, alpha); + DrawLine(DVector2(x0, y0), DVector2(x1, y1), color, alpha); return 0; } @@ -1583,15 +1583,15 @@ DEFINE_ACTION_FUNCTION(FCanvas, DrawLine) PARAM_INT(y1); PARAM_INT(color); PARAM_INT(alpha); - self->Drawer.AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, color | MAKEARGB(255, 0, 0, 0), alpha); + self->Drawer.AddLine(DVector2(x0, y0), DVector2(x1, y1), nullptr, color | MAKEARGB(255, 0, 0, 0), alpha); self->Tex->NeedUpdate(); return 0; } -static void DrawThickLine(int x0, int y0, int x1, int y1, double thickness, uint32_t realcolor, int alpha) +static void DrawThickLine(const DVector2& v1, const DVector2& v2, double thickness, uint32_t realcolor, int alpha) { if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); - twod->AddThickLine(x0, y0, x1, y1, thickness, realcolor, alpha); + twod->AddThickLine(v1, v2, thickness, realcolor, alpha); } DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawThickLine, DrawThickLine) @@ -1604,7 +1604,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawThickLine, DrawThickLine) PARAM_FLOAT(thickness); PARAM_INT(color); PARAM_INT(alpha); - DrawThickLine(x0, y0, x1, y1, thickness, color, alpha); + DrawThickLine(DVector2(x0, y0), DVector2(x1, y1), thickness, color, alpha); return 0; } @@ -1618,7 +1618,7 @@ DEFINE_ACTION_FUNCTION(FCanvas, DrawThickLine) PARAM_FLOAT(thickness); PARAM_INT(color); PARAM_INT(alpha); - self->Drawer.AddThickLine(x0, y0, x1, y1, thickness, color, alpha); + self->Drawer.AddThickLine(DVector2(x0, y0), DVector2(x1, y1), thickness, color, alpha); self->Tex->NeedUpdate(); return 0; } diff --git a/source/core/automap.cpp b/source/core/automap.cpp index 409329ff9..43b7899ba 100644 --- a/source/core/automap.cpp +++ b/source/core/automap.cpp @@ -292,15 +292,15 @@ void MarkSectorSeen(sectortype* sec) // //--------------------------------------------------------------------------- -void drawlinergb(const double x1, const double y1, const double x2, const double y2, PalEntry p) +void drawlinergb(const DVector2& v1, const DVector2& v2, PalEntry p) { if (am_linethickness <= 1) { - twod->AddLine(x1, y1, x2, y2, &viewport3d, p, uint8_t(am_linealpha * 255)); + twod->AddLine(v1, v2, &viewport3d, p, uint8_t(am_linealpha * 255)); } else { - twod->AddThickLine(x1, y1, x2, y2, am_linethickness, p, uint8_t(am_linealpha * 255)); + twod->AddThickLine(v1, v2, am_linethickness, p, uint8_t(am_linealpha * 255)); } } @@ -408,7 +408,7 @@ static void drawredlines(const DVector2& cpos, const double sine, const double c { auto v1 = OutAutomapVector(wal.pos - cpos, sine, cosine, gZoom, xydim); auto v2 = OutAutomapVector(wal.point2Wall()->pos - cpos, sine, cosine, gZoom, xydim); - drawlinergb(v1.X, v1.Y, v2.X, v2.Y, RedLineColor()); + drawlinergb(v1, v2, RedLineColor()); } } } @@ -436,7 +436,7 @@ static void drawwhitelines(const DVector2& cpos, const double sine, const double auto v1 = OutAutomapVector(wal.pos - cpos, sine, cosine, gZoom, xydim); auto v2 = OutAutomapVector(wal.point2Wall()->pos - cpos, sine, cosine, gZoom, xydim); - drawlinergb(v1.X, v1.Y, v2.X, v2.Y, WhiteLineColor()); + drawlinergb(v1, v2, WhiteLineColor()); } } } @@ -449,6 +449,7 @@ static void drawwhitelines(const DVector2& cpos, const double sine, const double static void DrawPlayerArrow(const DVector2& cpos, const DAngle cang, const double czoom, const DAngle pl_angle) { +#if 0 static constexpr int arrow[] = { 0, 65536, 0, -65536, @@ -484,6 +485,7 @@ static void DrawPlayerArrow(const DVector2& cpos, const DAngle cang, const doubl drawlinergb(sx1, sy1, sx2, sy2, WhiteLineColor()); } +#endif } diff --git a/source/core/automap.h b/source/core/automap.h index 6b3fa2e20..5e23a972c 100644 --- a/source/core/automap.h +++ b/source/core/automap.h @@ -18,7 +18,7 @@ void ClearAutomap(); 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 double x1, const double y1, const double x2, const double y2, PalEntry p); +void drawlinergb(const DVector2& v1, const DVector2& v2, PalEntry p); inline DVector2 OutAutomapVector(const DVector2& pos, const double sine, const double cosine, const double zoom = 1., const DVector2& xydim = { 0, 0 }) { diff --git a/source/core/menu/usermap.cpp b/source/core/menu/usermap.cpp index 89fc47495..dc7ec239c 100644 --- a/source/core/menu/usermap.cpp +++ b/source/core/menu/usermap.cpp @@ -226,29 +226,22 @@ DEFINE_ACTION_FUNCTION(_UserMapMenu, DrawPreview) } float scalex = float(width / (maxx - minx)); float scaley = float(height / (maxy - miny)); - float centerx = (minx + maxx) * 0.5f; - float centery = (miny + maxy) * 0.5f; - float dcenterx = left + (width * 0.5f); - float dcentery = top + (height * 0.5f); float scale = min(scalex, scaley); - float drawleft = dcenterx - (centerx - minx) * scale; - float drawtop = dcentery - (centery - miny) * scale; + + DVector2 center = { (minx + maxx) * 0.5, (miny + maxy) * 0.5 }; + DVector2 dcenter = { left + (width * 0.5), top + (height * 0.5) }; for (auto& wal : entry->walls) { if (wal.nextwall < 0) continue; auto point2 = &entry->walls[wal.point2]; - twod->AddLine(dcenterx + (wal.pos.X - centerx) * scale, dcentery + (wal.pos.Y - centery) * scale, - dcenterx + (point2->pos.X - centerx) * scale, dcentery + (point2->pos.Y - centery) * scale, - nullptr, 0xff808080); + twod->AddLine(dcenter + (wal.pos - center) * scale, dcenter + (point2->pos - center) * scale, nullptr, 0xff808080); } for (auto& wal : entry->walls) { if (wal.nextwall >= 0) continue; auto point2 = &entry->walls[wal.point2]; - twod->AddLine(dcenterx + (wal.pos.X - centerx) * scale, dcentery + (wal.pos.Y - centery) * scale, - dcenterx + (point2->pos.X - centerx) * scale, dcentery + (point2->pos.Y - centery) * scale, - nullptr, 0xffffffff); + twod->AddLine(dcenter + (wal.pos - center) * scale, dcenter + (point2->pos - center) * scale, nullptr, 0xffffffff); } return 0; } diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index bd7ac2e93..3a9a95f47 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -413,9 +413,9 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, v3 = DVector2(b1.X + b2.Y, b1.Y - b2.X) + xydim; v4 = b1 + b2 + xydim; - drawlinergb(v1.X, v1.Y, v4.X, v4.Y, col); - drawlinergb(v2.X, v2.Y, v4.X, v4.Y, col); - drawlinergb(v3.X, v3.Y, v4.X, v4.Y, col); + drawlinergb(v1, v4, col); + drawlinergb(v2, v4, col); + drawlinergb(v3, v4, col); break; case CSTAT_SPRITE_ALIGNMENT_WALL: @@ -434,7 +434,7 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, v1 = OutAutomapVector(b1 - cpos, cangsin, cangcos, czoom, xydim); v2 = OutAutomapVector(b2 - cpos, cangsin, cangcos, czoom, xydim); - drawlinergb(v1.X, v1.Y, v2.X, v2.Y, col); + drawlinergb(v1, v2, col); } break; @@ -474,10 +474,10 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, v3 = OutAutomapVector(b3 - cpos, cangsin, cangcos, czoom, xydim); v4 = OutAutomapVector(b4 - cpos, cangsin, cangcos, czoom, xydim); - drawlinergb(v1.X, v1.Y, v2.X, v2.Y, col); - drawlinergb(v2.X, v2.Y, v3.X, v3.Y, col); - drawlinergb(v3.X, v3.Y, v4.X, v4.Y, col); - drawlinergb(v4.X, v4.Y, v1.X, v1.Y, col); + drawlinergb(v1, v2, col); + drawlinergb(v2, v3, col); + drawlinergb(v3, v4, col); + drawlinergb(v4, v1, col); break; } } diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 90ecef1cb..eaaa60729 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1655,7 +1655,7 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, v1 = OutAutomapVector(b1 - cpos, cangsin, cangcos, czoom, xydim); v2 = OutAutomapVector(b2 - cpos, cangsin, cangcos, czoom, xydim); - drawlinergb(v1.X, v1.Y, v2.X, v2.Y, col); + drawlinergb(v1, v2, col); break; case CSTAT_SPRITE_ALIGNMENT_FLOOR: // Floor sprite if (automapMode == am_overlay) @@ -1690,10 +1690,10 @@ bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, v3 = OutAutomapVector(b3 - cpos, cangsin, cangcos, czoom, xydim); v4 = OutAutomapVector(b4 - cpos, cangsin, cangcos, czoom, xydim); - drawlinergb(v1.X, v1.Y, v2.X, v2.Y, col); - drawlinergb(v2.X, v2.Y, v3.X, v3.Y, col); - drawlinergb(v3.X, v3.Y, v4.X, v4.Y, col); - drawlinergb(v4.X, v4.Y, v1.X, v1.Y, col); + drawlinergb(v1, v2, col); + drawlinergb(v2, v3, col); + drawlinergb(v3, v4, col); + drawlinergb(v4, v1, col); } break; }