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#ifndef GAME_CLIENT_RENDER_H
4#define GAME_CLIENT_RENDER_H
5
6#include <base/color.h>
7#include <base/vmath.h>
8
9#include <game/client/skin.h>
10#include <game/client/ui_rect.h>
11
12class CAnimState;
13class CSpeedupTile;
14class CSwitchTile;
15class CTeleTile;
16class CTile;
17class CTuneTile;
18namespace client_data7 {
19struct CDataSprite;
20}
21struct CDataSprite;
22struct CEnvPoint;
23struct CEnvPointBezier;
24struct CEnvPointBezier_upstream;
25struct CMapItemGroup;
26struct CQuad;
27
28class CTeeRenderInfo
29{
30public:
31 CTeeRenderInfo()
32 {
33 Reset();
34 }
35
36 void Reset()
37 {
38 m_OriginalRenderSkin.Reset();
39 m_ColorableRenderSkin.Reset();
40 m_SkinMetrics.Reset();
41 m_CustomColoredSkin = false;
42 m_BloodColor = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
43 m_ColorBody = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
44 m_ColorFeet = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
45 m_Size = 1.0f;
46 m_GotAirJump = true;
47 m_TeeRenderFlags = 0;
48 m_FeetFlipped = false;
49 }
50
51 CSkin::SSkinTextures m_OriginalRenderSkin;
52 CSkin::SSkinTextures m_ColorableRenderSkin;
53
54 CSkin::SSkinMetrics m_SkinMetrics;
55
56 bool m_CustomColoredSkin;
57 ColorRGBA m_BloodColor;
58
59 ColorRGBA m_ColorBody;
60 ColorRGBA m_ColorFeet;
61 float m_Size;
62 bool m_GotAirJump;
63 int m_TeeRenderFlags;
64 bool m_FeetFlipped;
65
66 bool Valid() const
67 {
68 return m_CustomColoredSkin ? m_ColorableRenderSkin.m_Body.IsValid() : m_OriginalRenderSkin.m_Body.IsValid();
69 }
70};
71
72// Tee Render Flags
73enum
74{
75 TEE_EFFECT_FROZEN = 1,
76 TEE_NO_WEAPON = 2,
77};
78
79// sprite renderings
80enum
81{
82 SPRITE_FLAG_FLIP_Y = 1,
83 SPRITE_FLAG_FLIP_X = 2,
84
85 LAYERRENDERFLAG_OPAQUE = 1,
86 LAYERRENDERFLAG_TRANSPARENT = 2,
87
88 TILERENDERFLAG_EXTEND = 4,
89};
90
91class IEnvelopePointAccess
92{
93public:
94 virtual ~IEnvelopePointAccess() = default;
95 virtual int NumPoints() const = 0;
96 virtual const CEnvPoint *GetPoint(int Index) const = 0;
97 virtual const CEnvPointBezier *GetBezier(int Index) const = 0;
98};
99
100class CMapBasedEnvelopePointAccess : public IEnvelopePointAccess
101{
102 int m_StartPoint;
103 int m_NumPoints;
104 int m_NumPointsMax;
105 CEnvPoint *m_pPoints;
106 CEnvPointBezier *m_pPointsBezier;
107 CEnvPointBezier_upstream *m_pPointsBezierUpstream;
108
109public:
110 CMapBasedEnvelopePointAccess(class CDataFileReader *pReader);
111 CMapBasedEnvelopePointAccess(class IMap *pMap);
112 void SetPointsRange(int StartPoint, int NumPoints);
113 int StartPoint() const;
114 int NumPoints() const override;
115 int NumPointsMax() const;
116 const CEnvPoint *GetPoint(int Index) const override;
117 const CEnvPointBezier *GetBezier(int Index) const override;
118};
119
120typedef void (*ENVELOPE_EVAL)(int TimeOffsetMillis, int Env, ColorRGBA &Result, size_t Channels, void *pUser);
121
122class CRenderTools
123{
124 class IGraphics *m_pGraphics;
125 class ITextRender *m_pTextRender;
126
127 int m_TeeQuadContainerIndex;
128
129 static void GetRenderTeeBodyScale(float BaseSize, float &BodyScale);
130 static void GetRenderTeeFeetScale(float BaseSize, float &FeetScaleWidth, float &FeetScaleHeight);
131
132public:
133 class IGraphics *Graphics() const { return m_pGraphics; }
134 class ITextRender *TextRender() const { return m_pTextRender; }
135
136 void Init(class IGraphics *pGraphics, class ITextRender *pTextRender);
137
138 void SelectSprite(CDataSprite *pSprite, int Flags = 0, int sx = 0, int sy = 0) const;
139 void SelectSprite(int Id, int Flags = 0, int sx = 0, int sy = 0) const;
140
141 void GetSpriteScale(const CDataSprite *pSprite, float &ScaleX, float &ScaleY) const;
142 void GetSpriteScale(int Id, float &ScaleX, float &ScaleY) const;
143 void GetSpriteScaleImpl(int Width, int Height, float &ScaleX, float &ScaleY) const;
144
145 void DrawSprite(float x, float y, float Size) const;
146 void DrawSprite(float x, float y, float ScaledWidth, float ScaledHeight) const;
147 void RenderCursor(vec2 Center, float Size) const;
148 void RenderIcon(int ImageId, int SpriteId, const CUIRect *pRect, const ColorRGBA *pColor = nullptr) const;
149 int QuadContainerAddSprite(int QuadContainerIndex, float x, float y, float Size) const;
150 int QuadContainerAddSprite(int QuadContainerIndex, float Size) const;
151 int QuadContainerAddSprite(int QuadContainerIndex, float Width, float Height) const;
152 int QuadContainerAddSprite(int QuadContainerIndex, float X, float Y, float Width, float Height) const;
153
154 // larger rendering methods
155 static void GetRenderTeeBodySize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &BodyOffset, float &Width, float &Height);
156 static void GetRenderTeeFeetSize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &FeetOffset, float &Width, float &Height);
157 static void GetRenderTeeAnimScaleAndBaseSize(const CTeeRenderInfo *pInfo, float &AnimScale, float &BaseSize);
158
159 // returns the offset to use, to render the tee with @see RenderTee exactly in the mid
160 static void GetRenderTeeOffsetToRenderedTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &TeeOffsetToMid);
161 // object render methods
162 void RenderTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha = 1.0f) const;
163
164 // map render methods (render_map.cpp)
165 static void RenderEvalEnvelope(const IEnvelopePointAccess *pPoints, std::chrono::nanoseconds TimeNanos, ColorRGBA &Result, size_t Channels);
166 void RenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser) const;
167 void ForceRenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser, float Alpha = 1.0f) const;
168 void RenderTilemap(CTile *pTiles, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
169
170 // render a rectangle made of IndexIn tiles, over a background made of IndexOut tiles
171 // the rectangle include all tiles in [RectX, RectX+RectW-1] x [RectY, RectY+RectH-1]
172 void RenderTileRectangle(int RectX, int RectY, int RectW, int RectH, unsigned char IndexIn, unsigned char IndexOut, float Scale, ColorRGBA Color, int RenderFlags) const;
173
174 // helpers
175 void CalcScreenParams(float Aspect, float Zoom, float *pWidth, float *pHeight);
176 void MapScreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY,
177 float ParallaxZoom, float OffsetX, float OffsetY, float Aspect, float Zoom, float *pPoints);
178 void MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup, float Zoom);
179 void MapScreenToInterface(float CenterX, float CenterY);
180
181 // DDRace
182
183 void RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale, float Alpha = 1.0f) const;
184 void RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, float Scale, float Alpha = 1.0f) const;
185 void RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float Scale, float Alpha = 1.0f) const;
186 void RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale, float Alpha = 1.0f) const;
187 void RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
188 void RenderSpeedupmap(CSpeedupTile *pSpeedup, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
189 void RenderSwitchmap(CSwitchTile *pSwitch, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
190 void RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
191};
192
193#endif
194