mirror of
https://github.com/DrBeef/Raze.git
synced 2025-02-20 18:52:43 +00:00
- Pass DVector2
objects directly through to F2DDrawer::AddLine()
and F2DDrawer::AddThickLine()
.
* Since all the external code calling through to these methods are built on vectors, makes sense to pass them around by reference.
This commit is contained in:
parent
9e93b417b7
commit
d63fb33dd0
8 changed files with 46 additions and 54 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 })
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue