1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#include "render.h"
4
5#include "animstate.h"
6
7#include <base/math.h>
8#include <base/str.h>
9
10#include <engine/graphics.h>
11#include <engine/shared/config.h>
12
13#include <generated/client_data.h>
14#include <generated/client_data7.h>
15#include <generated/protocol.h>
16#include <generated/protocol7.h>
17
18#include <game/mapitems.h>
19
20#include <cmath>
21
22CSkinDescriptor::CSkinDescriptor()
23{
24 Reset();
25}
26
27void CSkinDescriptor::Reset()
28{
29 m_Flags = 0;
30 m_aSkinName[0] = '\0';
31 for(auto &Sixup : m_aSixup)
32 {
33 Sixup.Reset();
34 }
35}
36
37bool CSkinDescriptor::IsValid() const
38{
39 return (m_Flags & (FLAG_SIX | FLAG_SEVEN)) != 0;
40}
41
42bool CSkinDescriptor::operator==(const CSkinDescriptor &Other) const
43{
44 if(m_Flags != Other.m_Flags)
45 {
46 return false;
47 }
48
49 if(m_Flags & FLAG_SIX)
50 {
51 if(str_comp(a: m_aSkinName, b: Other.m_aSkinName) != 0)
52 {
53 return false;
54 }
55 }
56
57 if(m_Flags & FLAG_SEVEN)
58 {
59 for(int Dummy = 0; Dummy < NUM_DUMMIES; Dummy++)
60 {
61 if(m_aSixup[Dummy] != Other.m_aSixup[Dummy])
62 {
63 return false;
64 }
65 }
66 }
67
68 return true;
69}
70
71void CSkinDescriptor::CSixup::Reset()
72{
73 for(auto &aSkinPartName : m_aaSkinPartNames)
74 {
75 aSkinPartName[0] = '\0';
76 }
77 m_BotDecoration = false;
78 m_XmasHat = false;
79}
80
81bool CSkinDescriptor::CSixup::operator==(const CSixup &Other) const
82{
83 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
84 {
85 if(str_comp(a: m_aaSkinPartNames[Part], b: Other.m_aaSkinPartNames[Part]) != 0)
86 {
87 return false;
88 }
89 }
90 return m_BotDecoration == Other.m_BotDecoration &&
91 m_XmasHat == Other.m_XmasHat;
92}
93
94void CRenderTools::Init(IGraphics *pGraphics, ITextRender *pTextRender)
95{
96 m_pGraphics = pGraphics;
97 m_pTextRender = pTextRender;
98 m_TeeQuadContainerIndex = Graphics()->CreateQuadContainer(AutomaticUpload: false);
99 Graphics()->SetColor(r: 1.f, g: 1.f, b: 1.f, a: 1.f);
100
101 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
102 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_TeeQuadContainerIndex, Size: 64.f);
103 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
104 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_TeeQuadContainerIndex, Size: 64.f);
105
106 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
107 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_TeeQuadContainerIndex, Size: 64.f * 0.4f);
108 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
109 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_TeeQuadContainerIndex, Size: 64.f * 0.4f);
110 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
111 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_TeeQuadContainerIndex, Size: 64.f * 0.4f);
112 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
113 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_TeeQuadContainerIndex, Size: 64.f * 0.4f);
114 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
115 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_TeeQuadContainerIndex, Size: 64.f * 0.4f);
116
117 // Feet
118 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
119 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_TeeQuadContainerIndex, X: -32.f, Y: -16.f, Width: 64.f, Height: 32.f);
120 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
121 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_TeeQuadContainerIndex, X: -32.f, Y: -16.f, Width: 64.f, Height: 32.f);
122
123 // Mirrored Feet
124 Graphics()->QuadsSetSubsetFree(x0: 1, y0: 0, x1: 0, y1: 0, x2: 0, y2: 1, x3: 1, y3: 1);
125 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_TeeQuadContainerIndex, X: -32.f, Y: -16.f, Width: 64.f, Height: 32.f);
126 Graphics()->QuadsSetSubsetFree(x0: 1, y0: 0, x1: 0, y1: 0, x2: 0, y2: 1, x3: 1, y3: 1);
127 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_TeeQuadContainerIndex, X: -32.f, Y: -16.f, Width: 64.f, Height: 32.f);
128
129 Graphics()->QuadContainerUpload(ContainerIndex: m_TeeQuadContainerIndex);
130}
131
132void CRenderTools::RenderCursor(vec2 Center, float Size) const
133{
134 Graphics()->WrapClamp();
135 Graphics()->TextureSet(Texture: g_pData->m_aImages[IMAGE_CURSOR].m_Id);
136 Graphics()->QuadsBegin();
137 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
138 IGraphics::CQuadItem QuadItem(Center.x, Center.y, Size, Size);
139 Graphics()->QuadsDrawTL(pArray: &QuadItem, Num: 1);
140 Graphics()->QuadsEnd();
141 Graphics()->WrapNormal();
142}
143
144void CRenderTools::RenderIcon(int ImageId, int SpriteId, const CUIRect *pRect, const ColorRGBA *pColor) const
145{
146 Graphics()->TextureSet(Texture: g_pData->m_aImages[ImageId].m_Id);
147 Graphics()->QuadsBegin();
148 Graphics()->SelectSprite(Id: SpriteId);
149 if(pColor)
150 Graphics()->SetColor(r: pColor->r * pColor->a, g: pColor->g * pColor->a, b: pColor->b * pColor->a, a: pColor->a);
151 IGraphics::CQuadItem QuadItem(pRect->x, pRect->y, pRect->w, pRect->h);
152 Graphics()->QuadsDrawTL(pArray: &QuadItem, Num: 1);
153 Graphics()->QuadsEnd();
154}
155
156void CRenderTools::GetRenderTeeAnimScaleAndBaseSize(const CTeeRenderInfo *pInfo, float &AnimScale, float &BaseSize)
157{
158 AnimScale = pInfo->m_Size * 1.0f / 64.0f;
159 BaseSize = pInfo->m_Size;
160}
161
162void CRenderTools::GetRenderTeeBodyScale(float BaseSize, float &BodyScale)
163{
164 BodyScale = g_Config.m_ClFatSkins ? BaseSize * 1.3f : BaseSize;
165 BodyScale /= 64.0f;
166}
167
168void CRenderTools::GetRenderTeeFeetScale(float BaseSize, float &FeetScaleWidth, float &FeetScaleHeight)
169{
170 FeetScaleWidth = BaseSize / 64.0f;
171 FeetScaleHeight = (BaseSize / 2) / 32.0f;
172}
173
174void CRenderTools::GetRenderTeeBodySize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &BodyOffset, float &Width, float &Height)
175{
176 float AnimScale, BaseSize;
177 GetRenderTeeAnimScaleAndBaseSize(pInfo, AnimScale, BaseSize);
178
179 float BodyScale;
180 GetRenderTeeBodyScale(BaseSize, BodyScale);
181
182 Width = pInfo->m_SkinMetrics.m_Body.WidthNormalized() * 64.0f * BodyScale;
183 Height = pInfo->m_SkinMetrics.m_Body.HeightNormalized() * 64.0f * BodyScale;
184 BodyOffset.x = pInfo->m_SkinMetrics.m_Body.OffsetXNormalized() * 64.0f * BodyScale;
185 BodyOffset.y = pInfo->m_SkinMetrics.m_Body.OffsetYNormalized() * 64.0f * BodyScale;
186}
187
188void CRenderTools::GetRenderTeeFeetSize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &FeetOffset, float &Width, float &Height)
189{
190 float AnimScale, BaseSize;
191 GetRenderTeeAnimScaleAndBaseSize(pInfo, AnimScale, BaseSize);
192
193 float FeetScaleWidth, FeetScaleHeight;
194 GetRenderTeeFeetScale(BaseSize, FeetScaleWidth, FeetScaleHeight);
195
196 Width = pInfo->m_SkinMetrics.m_Feet.WidthNormalized() * 64.0f * FeetScaleWidth;
197 Height = pInfo->m_SkinMetrics.m_Feet.HeightNormalized() * 32.0f * FeetScaleHeight;
198 FeetOffset.x = pInfo->m_SkinMetrics.m_Feet.OffsetXNormalized() * 64.0f * FeetScaleWidth;
199 FeetOffset.y = pInfo->m_SkinMetrics.m_Feet.OffsetYNormalized() * 32.0f * FeetScaleHeight;
200}
201
202void CRenderTools::GetRenderTeeOffsetToRenderedTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &TeeOffsetToMid)
203{
204 if(pInfo->m_aSixup[g_Config.m_ClDummy].PartTexture(Part: protocol7::SKINPART_BODY).IsValid())
205 {
206 TeeOffsetToMid = vec2(0.0f, pInfo->m_Size * 0.12f);
207 return;
208 }
209
210 float AnimScale, BaseSize;
211 GetRenderTeeAnimScaleAndBaseSize(pInfo, AnimScale, BaseSize);
212 vec2 BodyPos = vec2(pAnim->GetBody()->m_X, pAnim->GetBody()->m_Y) * AnimScale;
213
214 float AssumedScale = BaseSize / 64.0f;
215
216 // just use the lowest feet
217 vec2 FeetPos;
218 const CAnimKeyframe *pFoot = pAnim->GetFrontFoot();
219 FeetPos = vec2(pFoot->m_X * AnimScale, pFoot->m_Y * AnimScale);
220 pFoot = pAnim->GetBackFoot();
221 FeetPos = vec2(FeetPos.x, std::max(a: FeetPos.y, b: pFoot->m_Y * AnimScale));
222
223 vec2 BodyOffset;
224 float BodyWidth, BodyHeight;
225 GetRenderTeeBodySize(pAnim, pInfo, BodyOffset, Width&: BodyWidth, Height&: BodyHeight);
226
227 // -32 is the assumed min relative position for the quad
228 float MinY = -32.0f * AssumedScale;
229 // the body pos shifts the body away from center
230 MinY += BodyPos.y;
231 // the actual body is smaller though, because it doesn't use the full skin image in most cases
232 MinY += BodyOffset.y;
233
234 vec2 FeetOffset;
235 float FeetWidth, FeetHeight;
236 GetRenderTeeFeetSize(pAnim, pInfo, FeetOffset, Width&: FeetWidth, Height&: FeetHeight);
237
238 // MaxY builds up from the MinY
239 float MaxY = MinY + BodyHeight;
240 // if the body is smaller than the total feet offset, use feet
241 // since feet are smaller in height, respect the assumed relative position
242 MaxY = std::max(a: MaxY, b: (-16.0f * AssumedScale + FeetPos.y) + FeetOffset.y + FeetHeight);
243
244 // now we got the full rendered size
245 float FullHeight = (MaxY - MinY);
246
247 // next step is to calculate the offset that was created compared to the assumed relative position
248 float MidOfRendered = MinY + FullHeight / 2.0f;
249
250 // TODO: x coordinate is ignored for now, bcs it's not really used yet anyway
251 TeeOffsetToMid.x = 0;
252 // negative value, because the calculation that uses this offset should work with addition.
253 TeeOffsetToMid.y = -MidOfRendered;
254}
255
256void CRenderTools::RenderTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha) const
257{
258 if(pInfo->m_aSixup[g_Config.m_ClDummy].PartTexture(Part: protocol7::SKINPART_BODY).IsValid())
259 RenderTee7(pAnim, pInfo, Emote, Dir, Pos, Alpha);
260 else
261 RenderTee6(pAnim, pInfo, Emote, Dir, Pos, Alpha);
262
263 Graphics()->SetColor(r: 1.f, g: 1.f, b: 1.f, a: 1.f);
264 Graphics()->QuadsSetRotation(Angle: 0);
265}
266
267void CRenderTools::RenderIdleTeeAtCenter(const CTeeRenderInfo *pInfo, vec2 Center, int Emote, vec2 Dir, float Alpha) const
268{
269 const CAnimState *pIdleState = CAnimState::GetIdle();
270 vec2 OffsetToMid;
271 GetRenderTeeOffsetToRenderedTee(pAnim: pIdleState, pInfo, TeeOffsetToMid&: OffsetToMid);
272 RenderTee(pAnim: pIdleState, pInfo, Emote, Dir, Pos: Center + vec2(0.0f, OffsetToMid.y), Alpha);
273}
274
275void CRenderTools::RenderTee7(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha) const
276{
277 vec2 Direction = Dir;
278 vec2 Position = Pos;
279 const bool IsBot = pInfo->m_aSixup[g_Config.m_ClDummy].m_BotTexture.IsValid();
280
281 // first pass we draw the outline
282 // second pass we draw the filling
283 for(int Pass = 0; Pass < 2; Pass++)
284 {
285 bool OutLine = Pass == 0;
286
287 for(int Filling = 0; Filling < 2; Filling++)
288 {
289 float AnimScale = pInfo->m_Size * 1.0f / 64.0f;
290 float BaseSize = pInfo->m_Size;
291 if(Filling == 1)
292 {
293 vec2 BodyPos = Position + vec2(pAnim->GetBody()->m_X, pAnim->GetBody()->m_Y) * AnimScale;
294 IGraphics::CQuadItem BodyItem(BodyPos.x, BodyPos.y, BaseSize, BaseSize);
295 IGraphics::CQuadItem Item;
296
297 if(IsBot && !OutLine)
298 {
299 IGraphics::CQuadItem BotItem(BodyPos.x + (2.f / 3.f) * AnimScale, BodyPos.y + (-16 + 2.f / 3.f) * AnimScale, BaseSize, BaseSize); // x+0.66, y+0.66 to correct some rendering bug
300
301 // draw bot visuals (background)
302 Graphics()->TextureSet(Texture: pInfo->m_aSixup[g_Config.m_ClDummy].m_BotTexture);
303 Graphics()->QuadsBegin();
304 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
305 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_BOT_BACKGROUND);
306 Item = BotItem;
307 Graphics()->QuadsDraw(pArray: &Item, Num: 1);
308 Graphics()->QuadsEnd();
309
310 // draw bot visuals (foreground)
311 Graphics()->TextureSet(Texture: pInfo->m_aSixup[g_Config.m_ClDummy].m_BotTexture);
312 Graphics()->QuadsBegin();
313 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
314 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_BOT_FOREGROUND);
315 Item = BotItem;
316 Graphics()->QuadsDraw(pArray: &Item, Num: 1);
317 Graphics()->SetColor(pInfo->m_aSixup[g_Config.m_ClDummy].m_BotColor.WithAlpha(alpha: Alpha));
318 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_BOT_GLOW);
319 Item = BotItem;
320 Graphics()->QuadsDraw(pArray: &Item, Num: 1);
321 Graphics()->QuadsEnd();
322 }
323
324 // draw decoration
325 const IGraphics::CTextureHandle &DecorationTexture = pInfo->m_aSixup[g_Config.m_ClDummy].PartTexture(Part: protocol7::SKINPART_DECORATION);
326 if(DecorationTexture.IsValid())
327 {
328 Graphics()->TextureSet(Texture: DecorationTexture);
329 Graphics()->QuadsBegin();
330 Graphics()->QuadsSetRotation(Angle: pAnim->GetBody()->m_Angle * pi * 2);
331 Graphics()->SetColor(pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_DECORATION].WithAlpha(alpha: Alpha));
332 Graphics()->SelectSprite7(Id: OutLine ? client_data7::SPRITE_TEE_DECORATION_OUTLINE : client_data7::SPRITE_TEE_DECORATION);
333 Item = BodyItem;
334 Graphics()->QuadsDraw(pArray: &Item, Num: 1);
335 Graphics()->QuadsEnd();
336 }
337
338 // draw body (behind marking)
339 const IGraphics::CTextureHandle &BodyTexture = pInfo->m_aSixup[g_Config.m_ClDummy].PartTexture(Part: protocol7::SKINPART_BODY);
340 Graphics()->TextureSet(Texture: BodyTexture);
341 Graphics()->QuadsBegin();
342 Graphics()->QuadsSetRotation(Angle: pAnim->GetBody()->m_Angle * pi * 2);
343 if(OutLine)
344 {
345 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
346 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_BODY_OUTLINE);
347 }
348 else
349 {
350 Graphics()->SetColor(pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_BODY].WithAlpha(alpha: Alpha));
351 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_BODY);
352 }
353 Item = BodyItem;
354 Graphics()->QuadsDraw(pArray: &Item, Num: 1);
355 Graphics()->QuadsEnd();
356
357 // draw marking
358 const IGraphics::CTextureHandle &MarkingTexture = pInfo->m_aSixup[g_Config.m_ClDummy].PartTexture(Part: protocol7::SKINPART_MARKING);
359 if(MarkingTexture.IsValid() && !OutLine)
360 {
361 Graphics()->TextureSet(Texture: MarkingTexture);
362 Graphics()->QuadsBegin();
363 Graphics()->QuadsSetRotation(Angle: pAnim->GetBody()->m_Angle * pi * 2);
364 ColorRGBA MarkingColor = pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_MARKING];
365 Graphics()->SetColor(r: MarkingColor.r * MarkingColor.a, g: MarkingColor.g * MarkingColor.a, b: MarkingColor.b * MarkingColor.a, a: MarkingColor.a * Alpha);
366 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_MARKING);
367 Item = BodyItem;
368 Graphics()->QuadsDraw(pArray: &Item, Num: 1);
369 Graphics()->QuadsEnd();
370 }
371
372 // draw body (in front of marking)
373 if(!OutLine)
374 {
375 Graphics()->TextureSet(Texture: BodyTexture);
376 Graphics()->QuadsBegin();
377 Graphics()->QuadsSetRotation(Angle: pAnim->GetBody()->m_Angle * pi * 2);
378 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
379 for(int t = 0; t < 2; t++)
380 {
381 Graphics()->SelectSprite7(Id: t == 0 ? client_data7::SPRITE_TEE_BODY_SHADOW : client_data7::SPRITE_TEE_BODY_UPPER_OUTLINE);
382 Item = BodyItem;
383 Graphics()->QuadsDraw(pArray: &Item, Num: 1);
384 }
385 Graphics()->QuadsEnd();
386 }
387
388 // draw eyes
389 Graphics()->TextureSet(Texture: pInfo->m_aSixup[g_Config.m_ClDummy].PartTexture(Part: protocol7::SKINPART_EYES));
390 Graphics()->QuadsBegin();
391 Graphics()->QuadsSetRotation(Angle: pAnim->GetBody()->m_Angle * pi * 2);
392 if(IsBot)
393 {
394 Graphics()->SetColor(pInfo->m_aSixup[g_Config.m_ClDummy].m_BotColor.WithAlpha(alpha: Alpha));
395 Emote = EMOTE_SURPRISE;
396 }
397 else
398 {
399 Graphics()->SetColor(pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_EYES].WithAlpha(alpha: Alpha));
400 }
401 if(Pass == 1)
402 {
403 switch(Emote)
404 {
405 case EMOTE_PAIN:
406 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_EYES_PAIN);
407 break;
408 case EMOTE_HAPPY:
409 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_EYES_HAPPY);
410 break;
411 case EMOTE_SURPRISE:
412 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_EYES_SURPRISE);
413 break;
414 case EMOTE_ANGRY:
415 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_EYES_ANGRY);
416 break;
417 default:
418 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_EYES_NORMAL);
419 break;
420 }
421
422 float EyeScale = BaseSize * 0.60f;
423 float h = Emote == EMOTE_BLINK ? BaseSize * 0.15f / 2.0f : EyeScale / 2.0f;
424 vec2 Offset = vec2(Direction.x * 0.125f, -0.05f + Direction.y * 0.10f) * BaseSize;
425 IGraphics::CQuadItem QuadItem(BodyPos.x + Offset.x, BodyPos.y + Offset.y, EyeScale, h);
426 Graphics()->QuadsDraw(pArray: &QuadItem, Num: 1);
427 }
428 Graphics()->QuadsEnd();
429
430 // draw xmas hat
431 if(!OutLine && pInfo->m_aSixup[g_Config.m_ClDummy].m_HatTexture.IsValid())
432 {
433 Graphics()->TextureSet(Texture: pInfo->m_aSixup[g_Config.m_ClDummy].m_HatTexture);
434 Graphics()->QuadsBegin();
435 Graphics()->QuadsSetRotation(Angle: pAnim->GetBody()->m_Angle * pi * 2);
436 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
437 int Flag = Direction.x < 0.0f ? IGraphics::SPRITE_FLAG_FLIP_X : 0;
438 switch(pInfo->m_aSixup[g_Config.m_ClDummy].m_HatSpriteIndex)
439 {
440 case 0:
441 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_HATS_TOP1, Flags: Flag);
442 break;
443 case 1:
444 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_HATS_TOP2, Flags: Flag);
445 break;
446 case 2:
447 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_HATS_SIDE1, Flags: Flag);
448 break;
449 case 3:
450 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_HATS_SIDE2, Flags: Flag);
451 }
452 Item = BodyItem;
453 Graphics()->QuadsDraw(pArray: &Item, Num: 1);
454 Graphics()->QuadsEnd();
455 }
456 }
457
458 // draw feet
459 Graphics()->TextureSet(Texture: pInfo->m_aSixup[g_Config.m_ClDummy].PartTexture(Part: protocol7::SKINPART_FEET));
460 Graphics()->QuadsBegin();
461 const CAnimKeyframe *pFoot = Filling ? pAnim->GetFrontFoot() : pAnim->GetBackFoot();
462
463 float w = BaseSize / 2.1f;
464 float h = w;
465
466 Graphics()->QuadsSetRotation(Angle: pFoot->m_Angle * pi * 2);
467
468 if(OutLine)
469 {
470 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
471 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_FOOT_OUTLINE);
472 }
473 else
474 {
475 bool Indicate = !pInfo->m_GotAirJump && g_Config.m_ClAirjumpindicator;
476 float ColorScale = 1.0f;
477 if(Indicate)
478 ColorScale = 0.5f;
479 Graphics()->SetColor(
480 r: pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_FEET].r * ColorScale,
481 g: pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_FEET].g * ColorScale,
482 b: pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_FEET].b * ColorScale,
483 a: pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_FEET].a * Alpha);
484 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_FOOT);
485 }
486
487 IGraphics::CQuadItem QuadItem(Position.x + pFoot->m_X * AnimScale, Position.y + pFoot->m_Y * AnimScale, w, h);
488 Graphics()->QuadsDraw(pArray: &QuadItem, Num: 1);
489 Graphics()->QuadsEnd();
490 }
491 }
492}
493
494void CRenderTools::RenderTee6(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha) const
495{
496 vec2 Direction = Dir;
497 vec2 Position = Pos;
498
499 const CSkin::CSkinTextures *pSkinTextures = pInfo->m_CustomColoredSkin ? &pInfo->m_ColorableRenderSkin : &pInfo->m_OriginalRenderSkin;
500
501 // first pass we draw the outline
502 // second pass we draw the filling
503 for(int Pass = 0; Pass < 2; Pass++)
504 {
505 int OutLine = Pass == 0 ? 1 : 0;
506
507 for(int Filling = 0; Filling < 2; Filling++)
508 {
509 float AnimScale, BaseSize;
510 GetRenderTeeAnimScaleAndBaseSize(pInfo, AnimScale, BaseSize);
511 if(Filling == 1)
512 {
513 Graphics()->QuadsSetRotation(Angle: pAnim->GetBody()->m_Angle * pi * 2);
514
515 // draw body
516 Graphics()->SetColor(r: pInfo->m_ColorBody.r, g: pInfo->m_ColorBody.g, b: pInfo->m_ColorBody.b, a: Alpha);
517 vec2 BodyPos = Position + vec2(pAnim->GetBody()->m_X, pAnim->GetBody()->m_Y) * AnimScale;
518 float BodyScale;
519 GetRenderTeeBodyScale(BaseSize, BodyScale);
520 Graphics()->TextureSet(Texture: OutLine == 1 ? pSkinTextures->m_BodyOutline : pSkinTextures->m_Body);
521 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_TeeQuadContainerIndex, QuadOffset: OutLine, X: BodyPos.x, Y: BodyPos.y, ScaleX: BodyScale, ScaleY: BodyScale);
522
523 // draw eyes
524 if(Pass == 1)
525 {
526 int QuadOffset = 2;
527 int EyeQuadOffset = 0;
528 int TeeEye = 0;
529
530 switch(Emote)
531 {
532 case EMOTE_PAIN:
533 EyeQuadOffset = 0;
534 TeeEye = SPRITE_TEE_EYE_PAIN - SPRITE_TEE_EYE_NORMAL;
535 break;
536 case EMOTE_HAPPY:
537 EyeQuadOffset = 1;
538 TeeEye = SPRITE_TEE_EYE_HAPPY - SPRITE_TEE_EYE_NORMAL;
539 break;
540 case EMOTE_SURPRISE:
541 EyeQuadOffset = 2;
542 TeeEye = SPRITE_TEE_EYE_SURPRISE - SPRITE_TEE_EYE_NORMAL;
543 break;
544 case EMOTE_ANGRY:
545 EyeQuadOffset = 3;
546 TeeEye = SPRITE_TEE_EYE_ANGRY - SPRITE_TEE_EYE_NORMAL;
547 break;
548 default:
549 EyeQuadOffset = 4;
550 break;
551 }
552
553 float EyeScale = BaseSize * 0.40f;
554 float h = Emote == EMOTE_BLINK ? BaseSize * 0.15f : EyeScale;
555 float EyeSeparation = (0.075f - 0.010f * absolute(a: Direction.x)) * BaseSize;
556 vec2 Offset = vec2(Direction.x * 0.125f, -0.05f + Direction.y * 0.10f) * BaseSize;
557
558 Graphics()->TextureSet(Texture: pSkinTextures->m_aEyes[TeeEye]);
559 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_TeeQuadContainerIndex, QuadOffset: QuadOffset + EyeQuadOffset, X: BodyPos.x - EyeSeparation + Offset.x, Y: BodyPos.y + Offset.y, ScaleX: EyeScale / (64.f * 0.4f), ScaleY: h / (64.f * 0.4f));
560 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_TeeQuadContainerIndex, QuadOffset: QuadOffset + EyeQuadOffset, X: BodyPos.x + EyeSeparation + Offset.x, Y: BodyPos.y + Offset.y, ScaleX: -EyeScale / (64.f * 0.4f), ScaleY: h / (64.f * 0.4f));
561 }
562 }
563
564 // draw feet
565 const CAnimKeyframe *pFoot = Filling ? pAnim->GetFrontFoot() : pAnim->GetBackFoot();
566
567 float w = BaseSize;
568 float h = BaseSize / 2;
569
570 int QuadOffset = 7;
571 if(Dir.x < 0 && pInfo->m_FeetFlipped)
572 {
573 QuadOffset += 2;
574 }
575
576 Graphics()->QuadsSetRotation(Angle: pFoot->m_Angle * pi * 2);
577
578 bool Indicate = !pInfo->m_GotAirJump && g_Config.m_ClAirjumpindicator;
579 float ColorScale = 1.0f;
580
581 if(!OutLine)
582 {
583 ++QuadOffset;
584 if(Indicate)
585 ColorScale = 0.5f;
586 }
587
588 Graphics()->SetColor(r: pInfo->m_ColorFeet.r * ColorScale, g: pInfo->m_ColorFeet.g * ColorScale, b: pInfo->m_ColorFeet.b * ColorScale, a: Alpha);
589
590 Graphics()->TextureSet(Texture: OutLine == 1 ? pSkinTextures->m_FeetOutline : pSkinTextures->m_Feet);
591 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_TeeQuadContainerIndex, QuadOffset, X: Position.x + pFoot->m_X * AnimScale, Y: Position.y + pFoot->m_Y * AnimScale, ScaleX: w / 64.f, ScaleY: h / 32.f);
592 }
593 }
594}
595
596ColorRGBA CRenderTools::GetPingTextColor(int Latency)
597{
598 return color_cast<ColorRGBA>(hsl: ColorHSLA((300.0f - std::clamp(val: Latency, lo: 0, hi: 300)) / 1000.0f, 1.0f, 0.5f));
599}
600