1
1
#include " renderer.h"
2
2
3
- cRender::cRender (IDirect3DDevice9* device)
3
+ cRender::cRender (IDirect3DDevice9* device, bool bUseDynamicSinCos) :
4
+ m_bUseDynamicSinCos(bUseDynamicSinCos)
4
5
{
5
6
if (!device)
6
7
throw std::exception (" device == nullptr" );
@@ -15,14 +16,7 @@ cRender::~cRender()
15
16
delete[] i->second ;
16
17
i->second = nullptr ;
17
18
}
18
-
19
- for (auto & a : m_FontsList)
20
- if (*a.pFont )
21
- {
22
- (*a.pFont )->Release ();
23
- *a.pFont = nullptr ;
24
- }
25
-
19
+
26
20
m_pDevice = nullptr ;
27
21
}
28
22
@@ -76,42 +70,10 @@ void cRender::PushRenderState(const D3DRENDERSTATETYPE dwState, DWORD dwValue)
76
70
m_pDevice->SetRenderState (dwState, dwValue);
77
71
}
78
72
79
- void cRender::OnLostDevice ()
80
- {
81
- for (auto & a : m_FontsList)
82
- if (*a.pFont )
83
- (*a.pFont )->OnLostDevice ();
84
- }
85
-
86
- void cRender::OnResetDevice ()
87
- {
88
- for (auto & a : m_FontsList)
89
- if (*a.pFont )
90
- {
91
- (*a.pFont )->OnResetDevice ();
92
- a.update ();
93
- }
94
- }
95
-
96
- bool cRender::AddFont (ID3DXFont** pFont, const char * szName, uint8_t iSize, bool bAntiAliased)
97
- {
98
- font_t font;
99
-
100
- font.pDevice = m_pDevice;
101
- font.pFont = pFont;
102
- font.iSize = iSize;
103
- font.bAntiAliased = bAntiAliased;
104
- sprintf_s (font.szName , szName);
73
+ void cRender::OnLostDevice () { }
74
+ void cRender::OnResetDevice () { }
105
75
106
- if (!font.update ())
107
- return false ;
108
-
109
- m_FontsList.push_back (font);
110
-
111
- return true ;
112
- }
113
-
114
- void cRender::DrawString (int16_t x, int16_t y, color_t color, ID3DXFont* font, bool outlined, bool centered, const char * text, ...)
76
+ void cRender::DrawString (int16_t x, int16_t y, color_t color, cFont* font, bool outlined, bool centered, const char * text, ...)
115
77
{
116
78
va_list args;
117
79
char buf[256 ];
@@ -126,7 +88,7 @@ void cRender::DrawString(int16_t x, int16_t y, color_t color, ID3DXFont* font, b
126
88
if (centered)
127
89
{
128
90
RECT size_rect = { 0 };
129
- font->DrawTextA (NULL , buf, size, &size_rect, DT_CALCRECT | DT_NOCLIP, 0 );
91
+ font->GetFont ()-> DrawTextA (NULL , buf, size, &size_rect, DT_CALCRECT | DT_NOCLIP, 0 );
130
92
131
93
rect.left -= size_rect.right / 2 ;
132
94
rect.top -= size_rect.bottom / 2 ;
@@ -138,17 +100,17 @@ void cRender::DrawString(int16_t x, int16_t y, color_t color, ID3DXFont* font, b
138
100
auto outline_color = static_cast <const color_t >((color.color >> 24 ) << 24 );
139
101
140
102
rect.top ++;
141
- font->DrawTextA (NULL , buf, size, &rect, DT_NOCLIP, outline_color);// x; y + 1
103
+ font->GetFont ()-> DrawTextA (NULL , buf, size, &rect, DT_NOCLIP, outline_color);// x; y + 1
142
104
rect.left ++; rect.top --;
143
- font->DrawTextA (NULL , buf, size, &rect, DT_NOCLIP, outline_color);// x + 1; y
105
+ font->GetFont ()-> DrawTextA (NULL , buf, size, &rect, DT_NOCLIP, outline_color);// x + 1; y
144
106
rect.left --; rect.top --;
145
- font->DrawTextA (NULL , buf, size, &rect, DT_NOCLIP, outline_color);// x; y - 1
107
+ font->GetFont ()-> DrawTextA (NULL , buf, size, &rect, DT_NOCLIP, outline_color);// x; y - 1
146
108
rect.left --; rect.top ++;
147
- font->DrawTextA (NULL , buf, size, &rect, DT_NOCLIP, outline_color);// x - 1; y
109
+ font->GetFont ()-> DrawTextA (NULL , buf, size, &rect, DT_NOCLIP, outline_color);// x - 1; y
148
110
rect.left ++;
149
111
}
150
112
151
- font->DrawTextA (NULL , buf, size, &rect, DT_NOCLIP, color);
113
+ font->GetFont ()-> DrawTextA (NULL , buf, size, &rect, DT_NOCLIP, color);
152
114
}
153
115
154
116
void cRender::DrawLine (int16_t x1, int16_t y1, int16_t x2, int16_t y2, color_t color)
@@ -192,11 +154,6 @@ void cRender::DrawBox(int16_t x, int16_t y, int16_t width, int16_t height, color
192
154
m_pDevice->DrawPrimitiveUP (D3DPT_LINESTRIP, 4 , pVertex, sizeof (Vertex_t));
193
155
}
194
156
195
- void cRender::DrawGradientBox (int16_t x, int16_t y, int16_t width, int16_t height, color_t color1, color_t color2, bool vertical)
196
- {
197
- DrawGradientBox (x, y, width, height, color1, vertical ? color1 : color2, vertical ? color2 : color1, color2);
198
- }
199
-
200
157
void cRender::DrawGradientBox (int16_t x, int16_t y, int16_t width, int16_t height, color_t color1, color_t color2, color_t color3, color_t color4)
201
158
{
202
159
Vertex_t pVertex[4 ];
@@ -215,16 +172,22 @@ void cRender::DrawCircle(int16_t x, int16_t y, int16_t radius, uint16_t points,
215
172
216
173
Vertex_t* verticles = new Vertex_t[points + gradient + 1 ];
217
174
218
- #if _USE_DYNAMIC_SIN_COS != 1
219
- SinCos_t* pSinCos = GetSinCos (points);
220
- #endif // !_USE_DYNAMIC_SIN_COS
175
+ SinCos_t* pSinCos = m_bUseDynamicSinCos ? nullptr : GetSinCos (points);
221
176
222
177
if (gradient)
223
178
verticles[0 ] = Vertex_t (x, y, color2);
224
179
225
180
for (uint16_t i = gradient; i < points + gradient; i++)
226
181
{
227
- verticles[i] = Vertex_t (x + pSinCos[i - gradient].flCos * radius, y + pSinCos[i - gradient].flSin * radius, color1);
182
+ if (m_bUseDynamicSinCos)
183
+ {
184
+ const float angle = (2 * D3DX_PI) / points * (i - gradient);
185
+ verticles[i] = Vertex_t (x + cos (angle) *radius, y + sin (angle) * radius, color1);
186
+ }
187
+ else
188
+ {
189
+ verticles[i] = Vertex_t (x + pSinCos[i - gradient].flCos * radius, y + pSinCos[i - gradient].flSin * radius, color1);
190
+ }
228
191
229
192
if (filled)
230
193
{
@@ -276,24 +239,37 @@ void cRender::DrawRing(int16_t x, int16_t y, int16_t radius1, int16_t radius2, u
276
239
277
240
if (flags & RenderDrawType_Outlined)
278
241
{
279
- DrawCircle (x, y, radius1, points, RenderDrawType_Outlined, color1);
280
- DrawCircle (x, y, radius2, points, RenderDrawType_Outlined, color2);
242
+ DrawCircle (x, y, radius1, points, RenderDrawType_Outlined, color1, 0 );
243
+ DrawCircle (x, y, radius2, points, RenderDrawType_Outlined, color2, 0 );
281
244
return ;
282
245
}
283
246
284
247
constexpr uint8_t modifier = 4 ;
285
248
Vertex_t* verticles = new Vertex_t[points * modifier];
286
249
287
- SinCos_t* pSinCos = GetSinCos (points);
250
+ SinCos_t* pSinCos = m_bUseDynamicSinCos ? nullptr : GetSinCos (points);
288
251
289
252
for (uint16_t i = 0 ; i < points; i++)
290
253
{
291
254
uint16_t it = i * modifier;
255
+
256
+ if (m_bUseDynamicSinCos)
257
+ {
258
+ const float angle1 = (2 * D3DX_PI) / points * i;
259
+ const float angle2 = (2 * D3DX_PI) / points * (i + 1 );
292
260
293
- verticles[it] = Vertex_t (x + pSinCos[i].flCos * radius1, y + pSinCos[i].flSin * radius1, color1);
294
- verticles[it + 1 ] = Vertex_t (x + pSinCos[i].flCos * radius2, y + pSinCos[i].flSin * radius2, color2);
295
- verticles[it + 2 ] = Vertex_t (x + pSinCos[i + 1 ].flCos * radius1, y + pSinCos[i + 1 ].flSin * radius1, color1);
296
- verticles[it + 3 ] = Vertex_t (x + pSinCos[i + 1 ].flCos * radius2, y + pSinCos[i + 1 ].flSin * radius2, color2);
261
+ verticles[it] = Vertex_t (x + cos (angle1) * radius1, y + sin (angle1) * radius1, color1);
262
+ verticles[it + 1 ] = Vertex_t (x + cos (angle1) * radius2, y + sin (angle1) * radius2, color2);
263
+ verticles[it + 2 ] = Vertex_t (x + cos (angle2) * radius1, y + sin (angle2) * radius1, color1);
264
+ verticles[it + 3 ] = Vertex_t (x + cos (angle2) * radius2, y + sin (angle2) * radius2, color2);
265
+ }
266
+ else
267
+ {
268
+ verticles[it] = Vertex_t (x + pSinCos[i].flCos * radius1, y + pSinCos[i].flSin * radius1, color1);
269
+ verticles[it + 1 ] = Vertex_t (x + pSinCos[i].flCos * radius2, y + pSinCos[i].flSin * radius2, color2);
270
+ verticles[it + 2 ] = Vertex_t (x + pSinCos[i + 1 ].flCos * radius1, y + pSinCos[i + 1 ].flSin * radius1, color1);
271
+ verticles[it + 3 ] = Vertex_t (x + pSinCos[i + 1 ].flCos * radius2, y + pSinCos[i + 1 ].flSin * radius2, color2);
272
+ }
297
273
298
274
for (uint8_t a = 0 ; a < modifier; a++)
299
275
{
0 commit comments