1#include "graphics_threaded.h"
2
3#include <engine/graphics.h>
4
5#include <generated/client_data.h>
6#include <generated/client_data7.h>
7
8void CGraphics_Threaded::SelectSprite(const CDataSprite *pSprite, int Flags)
9{
10 int x = pSprite->m_X;
11 int y = pSprite->m_Y;
12 int w = pSprite->m_W;
13 int h = pSprite->m_H;
14 int cx = pSprite->m_pSet->m_Gridx;
15 int cy = pSprite->m_pSet->m_Gridy;
16
17 GetSpriteScaleImpl(Width: w, Height: h, ScaleX&: m_SpriteScale.x, ScaleY&: m_SpriteScale.y);
18
19 float x1 = x / (float)cx + 0.5f / (float)(cx * 32);
20 float x2 = (x + w) / (float)cx - 0.5f / (float)(cx * 32);
21 float y1 = y / (float)cy + 0.5f / (float)(cy * 32);
22 float y2 = (y + h) / (float)cy - 0.5f / (float)(cy * 32);
23
24 if(Flags & SPRITE_FLAG_FLIP_Y)
25 std::swap(a&: y1, b&: y2);
26
27 if(Flags & SPRITE_FLAG_FLIP_X)
28 std::swap(a&: x1, b&: x2);
29
30 QuadsSetSubset(TlU: x1, TlV: y1, BrU: x2, BrV: y2);
31}
32
33void CGraphics_Threaded::SelectSprite(int Id, int Flags)
34{
35 dbg_assert(Id >= 0 && Id < g_pData->m_NumSprites, "Id invalid");
36 SelectSprite(pSprite: &g_pData->m_aSprites[Id], Flags);
37}
38
39void CGraphics_Threaded::SelectSprite7(int Id, int Flags)
40{
41 dbg_assert(Id >= 0 && Id < client_data7::g_pData->m_NumSprites, "Id invalid");
42 SelectSprite(pSprite: &client_data7::g_pData->m_aSprites[Id], Flags);
43}
44
45void CGraphics_Threaded::GetSpriteScale(const CDataSprite *pSprite, float &ScaleX, float &ScaleY) const
46{
47 int w = pSprite->m_W;
48 int h = pSprite->m_H;
49 GetSpriteScaleImpl(Width: w, Height: h, ScaleX, ScaleY);
50}
51
52void CGraphics_Threaded::GetSpriteScale(int Id, float &ScaleX, float &ScaleY) const
53{
54 GetSpriteScale(pSprite: &g_pData->m_aSprites[Id], ScaleX, ScaleY);
55}
56
57void CGraphics_Threaded::GetSpriteScaleImpl(int Width, int Height, float &ScaleX, float &ScaleY) const
58{
59 const float f = length(a: vec2(Width, Height));
60 ScaleX = Width / f;
61 ScaleY = Height / f;
62}
63
64void CGraphics_Threaded::DrawSprite(float x, float y, float Size)
65{
66 IGraphics::CQuadItem QuadItem(x, y, Size * m_SpriteScale.x, Size * m_SpriteScale.y);
67 QuadsDraw(pArray: &QuadItem, Num: 1);
68}
69
70void CGraphics_Threaded::DrawSprite(float x, float y, float ScaledWidth, float ScaledHeight)
71{
72 IGraphics::CQuadItem QuadItem(x, y, ScaledWidth, ScaledHeight);
73 QuadsDraw(pArray: &QuadItem, Num: 1);
74}
75
76int CGraphics_Threaded::QuadContainerAddSprite(int QuadContainerIndex, float x, float y, float Size)
77{
78 IGraphics::CQuadItem QuadItem(x, y, Size, Size);
79 return QuadContainerAddQuads(ContainerIndex: QuadContainerIndex, pArray: &QuadItem, Num: 1);
80}
81
82int CGraphics_Threaded::QuadContainerAddSprite(int QuadContainerIndex, float Size)
83{
84 IGraphics::CQuadItem QuadItem(-(Size) / 2.f, -(Size) / 2.f, (Size), (Size));
85 return QuadContainerAddQuads(ContainerIndex: QuadContainerIndex, pArray: &QuadItem, Num: 1);
86}
87
88int CGraphics_Threaded::QuadContainerAddSprite(int QuadContainerIndex, float Width, float Height)
89{
90 IGraphics::CQuadItem QuadItem(-(Width) / 2.f, -(Height) / 2.f, (Width), (Height));
91 return QuadContainerAddQuads(ContainerIndex: QuadContainerIndex, pArray: &QuadItem, Num: 1);
92}
93
94int CGraphics_Threaded::QuadContainerAddSprite(int QuadContainerIndex, float X, float Y, float Width, float Height)
95{
96 IGraphics::CQuadItem QuadItem(X, Y, Width, Height);
97 return QuadContainerAddQuads(ContainerIndex: QuadContainerIndex, pArray: &QuadItem, Num: 1);
98}
99