From 9ad097da4d4c55ecc8dff172ef3052090fc3419c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 9 Jul 2022 13:26:42 +0200 Subject: [PATCH] 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 --- src/engine/client/graphics_threaded.cpp | 37 ++++++++++--------------- src/engine/client/graphics_threaded.h | 2 +- src/engine/graphics.h | 2 +- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index b80a1e771..813ea8101 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -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]; - int NumItems = 0; - float FSegments = (float)Segments; + IGraphics::CFreeformItem aItems[32]; + size_t NumItems = 0; + const float SegmentsAngle = 2 * pi / Segments; for(int i = 0; i < Segments; i += 2) { - float a1 = i / FSegments * 2 * pi; - float a2 = (i + 1) / FSegments * 2 * pi; - float a3 = (i + 2) / FSegments * 2 * pi; - float Ca1 = cosf(a1); - float Ca2 = cosf(a2); - float Ca3 = cosf(a3); - float Sa1 = sinf(a1); - float Sa2 = sinf(a2); - float Sa3 = sinf(a3); - - 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) + const float a1 = i * SegmentsAngle; + const float a2 = (i + 1) * SegmentsAngle; + const float a3 = (i + 2) * SegmentsAngle; + aItems[NumItems++] = IGraphics::CFreeformItem( + CenterX, CenterY, + CenterX + cosf(a1) * Radius, CenterY + sinf(a1) * Radius, + CenterX + cosf(a3) * Radius, CenterY + sinf(a3) * Radius, + CenterX + cosf(a2) * Radius, CenterY + sinf(a2) * Radius); + if(NumItems == std::size(aItems)) { - QuadsDrawFreeform(Array, 32); + QuadsDrawFreeform(aItems, std::size(aItems)); NumItems = 0; } } 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) diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index f470cae36..8362d36ec 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -1127,7 +1127,7 @@ public: void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) 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 { diff --git a/src/engine/graphics.h b/src/engine/graphics.h index f13e3dee1..a434d9c06 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -442,7 +442,7 @@ public: virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 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 {