mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Refactor DrawCircle
:
- improve argument names - remove duplicate computation by adding `SegmentsAngle` - rename variable `Array` to `aItems` - use `std::size` and `size_t` - remove unnecessary temporary variables
This commit is contained in:
parent
237fdc76db
commit
9ad097da4d
|
@ -1237,36 +1237,29 @@ void CGraphics_Threaded::QuadsText(float x, float y, float Size, const char *pTe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGraphics_Threaded::DrawCircle(float x, float y, float r, int Segments)
|
void CGraphics_Threaded::DrawCircle(float CenterX, float CenterY, float Radius, int Segments)
|
||||||
{
|
{
|
||||||
IGraphics::CFreeformItem Array[32];
|
IGraphics::CFreeformItem aItems[32];
|
||||||
int NumItems = 0;
|
size_t NumItems = 0;
|
||||||
float FSegments = (float)Segments;
|
const float SegmentsAngle = 2 * pi / Segments;
|
||||||
for(int i = 0; i < Segments; i += 2)
|
for(int i = 0; i < Segments; i += 2)
|
||||||
{
|
{
|
||||||
float a1 = i / FSegments * 2 * pi;
|
const float a1 = i * SegmentsAngle;
|
||||||
float a2 = (i + 1) / FSegments * 2 * pi;
|
const float a2 = (i + 1) * SegmentsAngle;
|
||||||
float a3 = (i + 2) / FSegments * 2 * pi;
|
const float a3 = (i + 2) * SegmentsAngle;
|
||||||
float Ca1 = cosf(a1);
|
aItems[NumItems++] = IGraphics::CFreeformItem(
|
||||||
float Ca2 = cosf(a2);
|
CenterX, CenterY,
|
||||||
float Ca3 = cosf(a3);
|
CenterX + cosf(a1) * Radius, CenterY + sinf(a1) * Radius,
|
||||||
float Sa1 = sinf(a1);
|
CenterX + cosf(a3) * Radius, CenterY + sinf(a3) * Radius,
|
||||||
float Sa2 = sinf(a2);
|
CenterX + cosf(a2) * Radius, CenterY + sinf(a2) * Radius);
|
||||||
float Sa3 = sinf(a3);
|
if(NumItems == std::size(aItems))
|
||||||
|
|
||||||
Array[NumItems++] = IGraphics::CFreeformItem(
|
|
||||||
x, y,
|
|
||||||
x + Ca1 * r, y + Sa1 * r,
|
|
||||||
x + Ca3 * r, y + Sa3 * r,
|
|
||||||
x + Ca2 * r, y + Sa2 * r);
|
|
||||||
if(NumItems == 32)
|
|
||||||
{
|
{
|
||||||
QuadsDrawFreeform(Array, 32);
|
QuadsDrawFreeform(aItems, std::size(aItems));
|
||||||
NumItems = 0;
|
NumItems = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(NumItems)
|
if(NumItems)
|
||||||
QuadsDrawFreeform(Array, NumItems);
|
QuadsDrawFreeform(aItems, NumItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGraphics_Threaded::RenderTileLayer(int BufferContainerIndex, const ColorRGBA &Color, char **pOffsets, unsigned int *pIndicedVertexDrawNum, size_t NumIndicesOffset)
|
void CGraphics_Threaded::RenderTileLayer(int BufferContainerIndex, const ColorRGBA &Color, char **pOffsets, unsigned int *pIndicedVertexDrawNum, size_t NumIndicesOffset)
|
||||||
|
|
|
@ -1127,7 +1127,7 @@ public:
|
||||||
void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) override;
|
void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) override;
|
||||||
void QuadsText(float x, float y, float Size, const char *pText) override;
|
void QuadsText(float x, float y, float Size, const char *pText) override;
|
||||||
|
|
||||||
void DrawCircle(float x, float y, float r, int Segments) override;
|
void DrawCircle(float CenterX, float CenterY, float Radius, int Segments) override;
|
||||||
|
|
||||||
const GL_STexCoord *GetCurTextureCoordinates() override
|
const GL_STexCoord *GetCurTextureCoordinates() override
|
||||||
{
|
{
|
||||||
|
|
|
@ -442,7 +442,7 @@ public:
|
||||||
virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0;
|
virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0;
|
||||||
virtual void QuadsText(float x, float y, float Size, const char *pText) = 0;
|
virtual void QuadsText(float x, float y, float Size, const char *pText) = 0;
|
||||||
|
|
||||||
virtual void DrawCircle(float x, float y, float r, int Segments) = 0;
|
virtual void DrawCircle(float CenterX, float CenterY, float Radius, int Segments) = 0;
|
||||||
|
|
||||||
struct CColorVertex
|
struct CColorVertex
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue