DDraceNetwork Docs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
render.h
Go to the documentation of this file.
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
7
8#include <base/color.h>
9#include <base/vmath.h>
10
11#include <game/client/skin.h>
12#include <game/client/ui_rect.h>
14
15#include <functional>
16#include <memory>
17
18class CAnimState;
19class CSpeedupTile;
20class CSwitchTile;
21class CTeleTile;
22class CTile;
23class CTuneTile;
24namespace client_data7 {
25struct CDataSprite;
26}
27struct CDataSprite;
28class CEnvPoint;
29class CEnvPointBezier;
31class CMapItemGroup;
32class CQuad;
33
35
37{
38public:
39 enum
40 {
43 };
44 unsigned m_Flags;
45
47
48 class CSixup
49 {
50 public:
54
55 void Reset();
56 bool operator==(const CSixup &Other) const;
57 bool operator!=(const CSixup &Other) const { return !(*this == Other); }
58 };
60
62 void Reset();
63 bool IsValid() const;
64 bool operator==(const CSkinDescriptor &Other) const;
65 bool operator!=(const CSkinDescriptor &Other) const { return !(*this == Other); }
66};
67
69{
70public:
72 {
73 Reset();
74 }
75
76 void Reset()
77 {
81 m_CustomColoredSkin = false;
82 m_BloodColor = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
83 m_ColorBody = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
84 m_ColorFeet = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
85 m_Size = 1.0f;
86 m_GotAirJump = true;
88 m_FeetFlipped = false;
89
90 for(auto &Sixup : m_aSixup)
91 Sixup.Reset();
92 }
93
94 void Apply(const CSkin *pSkin)
95 {
99 m_SkinMetrics = pSkin->m_Metrics;
100 }
101
102 void ApplyColors(bool CustomColoredSkin, int ColorBody, int ColorFeet)
103 {
104 m_CustomColoredSkin = CustomColoredSkin;
105 if(CustomColoredSkin)
106 {
107 m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(ColorBody).UnclampLighting(ColorHSLA::DARKEST_LGT));
108 m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(ColorFeet).UnclampLighting(ColorHSLA::DARKEST_LGT));
109 }
110 else
111 {
112 m_ColorBody = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
113 m_ColorFeet = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
114 }
115 }
116
119
121
124
127 float m_Size;
131
132 bool Valid() const
133 {
135 }
136
137 class CSixup
138 {
139 public:
140 void Reset()
141 {
142 for(auto &Texture : m_aOriginalTextures)
143 {
144 Texture.Invalidate();
145 }
146 for(auto &Texture : m_aColorableTextures)
147 {
148 Texture.Invalidate();
149 }
150 std::fill(std::begin(m_aUseCustomColors), std::end(m_aUseCustomColors), false);
151 std::fill(std::begin(m_aColors), std::end(m_aColors), ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
152 m_BloodColor = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
156 m_BotColor = ColorRGBA(0.0f, 0.0f, 0.0f, 0.0f);
157 }
158
168
170 {
172 }
173 };
174
176};
177
179{
180 friend class CGameClient;
183 std::function<void()> m_RefreshCallback = nullptr;
184
185public:
189 {
190 }
191
195 void SetRefreshCallback(const std::function<void()> &RefreshCallback) { m_RefreshCallback = RefreshCallback; }
196};
197
198// Tee Render Flags
199enum
200{
204};
205
206// sprite renderings
207enum
208{
211
214
216
218};
219
221{
222public:
223 virtual ~IEnvelopePointAccess() = default;
224 virtual int NumPoints() const = 0;
225 virtual const CEnvPoint *GetPoint(int Index) const = 0;
226 virtual const CEnvPointBezier *GetBezier(int Index) const = 0;
227};
228
230{
237
238public:
241 void SetPointsRange(int StartPoint, int NumPoints);
242 int StartPoint() const;
243 int NumPoints() const override;
244 int NumPointsMax() const;
245 const CEnvPoint *GetPoint(int Index) const override;
246 const CEnvPointBezier *GetBezier(int Index) const override;
247};
248
249typedef void (*ENVELOPE_EVAL)(int TimeOffsetMillis, int Env, ColorRGBA &Result, size_t Channels, void *pUser);
250
252{
255
257
258 static void GetRenderTeeBodyScale(float BaseSize, float &BodyScale);
259 static void GetRenderTeeFeetScale(float BaseSize, float &FeetScaleWidth, float &FeetScaleHeight);
260
261 void SelectSprite(const CDataSprite *pSprite, int Flags) const;
262
263 void RenderTee6(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha = 1.0f) const;
264 void RenderTee7(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha = 1.0f) const;
265
266public:
267 class IGraphics *Graphics() const { return m_pGraphics; }
268 class ITextRender *TextRender() const { return m_pTextRender; }
269
270 void Init(class IGraphics *pGraphics, class ITextRender *pTextRender);
271
272 void SelectSprite(int Id, int Flags = 0) const;
273 void SelectSprite7(int Id, int Flags = 0) const;
274
275 void GetSpriteScale(const CDataSprite *pSprite, float &ScaleX, float &ScaleY) const;
276 void GetSpriteScale(int Id, float &ScaleX, float &ScaleY) const;
277 void GetSpriteScaleImpl(int Width, int Height, float &ScaleX, float &ScaleY) const;
278
279 void DrawSprite(float x, float y, float Size) const;
280 void DrawSprite(float x, float y, float ScaledWidth, float ScaledHeight) const;
281 void RenderCursor(vec2 Center, float Size) const;
282 void RenderIcon(int ImageId, int SpriteId, const CUIRect *pRect, const ColorRGBA *pColor = nullptr) const;
283 int QuadContainerAddSprite(int QuadContainerIndex, float x, float y, float Size) const;
284 int QuadContainerAddSprite(int QuadContainerIndex, float Size) const;
285 int QuadContainerAddSprite(int QuadContainerIndex, float Width, float Height) const;
286 int QuadContainerAddSprite(int QuadContainerIndex, float X, float Y, float Width, float Height) const;
287
288 // larger rendering methods
289 static void GetRenderTeeBodySize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &BodyOffset, float &Width, float &Height);
290 static void GetRenderTeeFeetSize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &FeetOffset, float &Width, float &Height);
291 static void GetRenderTeeAnimScaleAndBaseSize(const CTeeRenderInfo *pInfo, float &AnimScale, float &BaseSize);
292
293 // returns the offset to use, to render the tee with @see RenderTee exactly in the mid
294 static void GetRenderTeeOffsetToRenderedTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &TeeOffsetToMid);
295 // object render methods
296 void RenderTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha = 1.0f) const;
297
298 // map render methods (render_map.cpp)
299 static void RenderEvalEnvelope(const IEnvelopePointAccess *pPoints, std::chrono::nanoseconds TimeNanos, ColorRGBA &Result, size_t Channels);
300 void RenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser) const;
301 void ForceRenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser, float Alpha = 1.0f) const;
302 void RenderTilemap(CTile *pTiles, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
303
304 // render a rectangle made of IndexIn tiles, over a background made of IndexOut tiles
305 // the rectangle include all tiles in [RectX, RectX+RectW-1] x [RectY, RectY+RectH-1]
306 void RenderTileRectangle(int RectX, int RectY, int RectW, int RectH, unsigned char IndexIn, unsigned char IndexOut, float Scale, ColorRGBA Color, int RenderFlags) const;
307
308 void RenderTile(int x, int y, unsigned char Index, float Scale, ColorRGBA Color) const;
309
310 // helpers
311 void CalcScreenParams(float Aspect, float Zoom, float *pWidth, float *pHeight);
312 void MapScreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY,
313 float ParallaxZoom, float OffsetX, float OffsetY, float Aspect, float Zoom, float *pPoints);
314 void MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup, float Zoom);
315 void MapScreenToInterface(float CenterX, float CenterY);
316
317 // DDRace
318
319 void RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale, int OverlayRenderFlags, float Alpha = 1.0f) const;
320 void RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, float Scale, int OverlayRenderFlags, float Alpha = 1.0f) const;
321 void RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float Scale, int OverlayRenderFlags, float Alpha = 1.0f) const;
322 void RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale, int OverlayRenderFlags, float Alpha = 1.0f) const;
323 void RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
324 void RenderSwitchmap(CSwitchTile *pSwitch, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
325 void RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
326};
327
328#endif
Definition: animstate.h:9
Definition: datafile.h:24
Definition: mapitems.h:403
Definition: mapitems.h:391
Definition: mapitems.h:373
Definition: gameclient.h:130
Definition: render.h:179
std::function< void()> m_RefreshCallback
Definition: render.h:183
void SetRefreshCallback(const std::function< void()> &RefreshCallback)
Definition: render.h:195
const CSkinDescriptor & SkinDescriptor() const
Definition: render.h:194
CSkinDescriptor m_SkinDescriptor
Definition: render.h:182
CManagedTeeRenderInfo(const CTeeRenderInfo &TeeRenderInfo, const CSkinDescriptor &SkinDescriptor)
Definition: render.h:186
const CTeeRenderInfo & TeeRenderInfo() const
Definition: render.h:193
CTeeRenderInfo m_TeeRenderInfo
Definition: render.h:181
CTeeRenderInfo & TeeRenderInfo()
Definition: render.h:192
Definition: render.h:230
int m_NumPoints
Definition: render.h:232
int NumPointsMax() const
Definition: render_map.cpp:100
int NumPoints() const override
Definition: render_map.cpp:95
int m_StartPoint
Definition: render.h:231
CEnvPoint * m_pPoints
Definition: render.h:234
int m_NumPointsMax
Definition: render.h:233
int StartPoint() const
Definition: render_map.cpp:90
CEnvPointBezier_upstream * m_pPointsBezierUpstream
Definition: render.h:236
const CEnvPointBezier * GetBezier(int Index) const override
Definition: render_map.cpp:116
CEnvPointBezier * m_pPointsBezier
Definition: render.h:235
const CEnvPoint * GetPoint(int Index) const override
Definition: render_map.cpp:105
void SetPointsRange(int StartPoint, int NumPoints)
Definition: render_map.cpp:84
CMapBasedEnvelopePointAccess(class CDataFileReader *pReader)
Definition: render_map.cpp:25
Definition: mapitems.h:295
Definition: mapitems.h:224
Definition: render.h:252
static void GetRenderTeeFeetSize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &FeetOffset, float &Width, float &Height)
Definition: render.cpp:281
void CalcScreenParams(float Aspect, float Zoom, float *pWidth, float *pHeight)
Definition: render.cpp:675
void RenderTilemap(CTile *pTiles, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const
Definition: render_map.cpp:499
void RenderTee7(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha=1.0f) const
Definition: render.cpp:354
void RenderTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha=1.0f) const
Definition: render.cpp:343
static void RenderEvalEnvelope(const IEnvelopePointAccess *pPoints, std::chrono::nanoseconds TimeNanos, ColorRGBA &Result, size_t Channels)
Definition: render_map.cpp:218
void RenderCursor(vec2 Center, float Size) const
Definition: render.cpp:201
static void GetRenderTeeAnimScaleAndBaseSize(const CTeeRenderInfo *pInfo, float &AnimScale, float &BaseSize)
Definition: render.cpp:249
void RenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser) const
Definition: render_map.cpp:333
void RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const
Definition: render_map.cpp:1239
void RenderIcon(int ImageId, int SpriteId, const CUIRect *pRect, const ColorRGBA *pColor=nullptr) const
Definition: render.cpp:213
void RenderTee6(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha=1.0f) const
Definition: render.cpp:573
void DrawSprite(float x, float y, float Size) const
Definition: render.cpp:189
void RenderTileRectangle(int RectX, int RectY, int RectW, int RectH, unsigned char IndexIn, unsigned char IndexOut, float Scale, ColorRGBA Color, int RenderFlags) const
Definition: render_map.cpp:406
static void GetRenderTeeFeetScale(float BaseSize, float &FeetScaleWidth, float &FeetScaleHeight)
Definition: render.cpp:261
class ITextRender * m_pTextRender
Definition: render.h:254
void RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float Scale, int OverlayRenderFlags, float Alpha=1.0f) const
Definition: render_map.cpp:849
static void GetRenderTeeBodyScale(float BaseSize, float &BodyScale)
Definition: render.cpp:255
static void GetRenderTeeOffsetToRenderedTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &TeeOffsetToMid)
Definition: render.cpp:295
void SelectSprite(const CDataSprite *pSprite, int Flags) const
Definition: render.cpp:133
void ForceRenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser, float Alpha=1.0f) const
Definition: render_map.cpp:341
void MapScreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY, float ParallaxZoom, float OffsetX, float OffsetY, float Aspect, float Zoom, float *pPoints)
Definition: render.cpp:702
void MapScreenToInterface(float CenterX, float CenterY)
Definition: render.cpp:729
void RenderSwitchmap(CSwitchTile *pSwitch, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const
Definition: render_map.cpp:1079
void GetSpriteScaleImpl(int Width, int Height, float &ScaleX, float &ScaleY) const
Definition: render.cpp:182
int QuadContainerAddSprite(int QuadContainerIndex, float x, float y, float Size) const
Definition: render.cpp:225
static void GetRenderTeeBodySize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &BodyOffset, float &Width, float &Height)
Definition: render.cpp:267
void SelectSprite7(int Id, int Flags=0) const
Definition: render.cpp:164
void RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, float Scale, int OverlayRenderFlags, float Alpha=1.0f) const
Definition: render_map.cpp:782
class IGraphics * Graphics() const
Definition: render.h:267
void Init(class IGraphics *pGraphics, class ITextRender *pTextRender)
Definition: render.cpp:95
class ITextRender * TextRender() const
Definition: render.h:268
void RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const
Definition: render_map.cpp:962
void RenderTile(int x, int y, unsigned char Index, float Scale, ColorRGBA Color) const
Definition: render_map.cpp:660
void RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale, int OverlayRenderFlags, float Alpha=1.0f) const
Definition: render_map.cpp:907
class IGraphics * m_pGraphics
Definition: render.h:253
void MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup, float Zoom)
Definition: render.cpp:720
void GetSpriteScale(const CDataSprite *pSprite, float &ScaleX, float &ScaleY) const
Definition: render.cpp:170
int m_TeeQuadContainerIndex
Definition: render.h:256
void RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale, int OverlayRenderFlags, float Alpha=1.0f) const
Definition: render_map.cpp:727
Definition: render.h:49
bool m_BotDecoration
Definition: render.h:52
bool operator!=(const CSixup &Other) const
Definition: render.h:57
bool operator==(const CSixup &Other) const
Definition: render.cpp:79
void Reset()
Definition: render.cpp:69
char m_aaSkinPartNames[protocol7::NUM_SKINPARTS][protocol7::MAX_SKIN_LENGTH]
Definition: render.h:51
bool m_XmasHat
Definition: render.h:53
Definition: render.h:37
CSixup m_aSixup[NUM_DUMMIES]
Definition: render.h:59
bool operator!=(const CSkinDescriptor &Other) const
Definition: render.h:65
bool operator==(const CSkinDescriptor &Other) const
Definition: render.cpp:40
unsigned m_Flags
Definition: render.h:44
bool IsValid() const
Definition: render.cpp:35
void Reset()
Definition: render.cpp:25
@ FLAG_SIX
Definition: render.h:41
@ FLAG_SEVEN
Definition: render.h:42
CSkinDescriptor()
Definition: render.cpp:20
char m_aSkinName[MAX_SKIN_LENGTH]
Definition: render.h:46
Definition: skin.h:79
void Reset()
Definition: skin.cpp:113
Definition: skin.h:16
IGraphics::CTextureHandle m_Body
Definition: skin.h:18
void Reset()
Definition: skin.cpp:8
Definition: skin.h:11
CSkinMetrics m_Metrics
Definition: skin.h:87
ColorRGBA m_BloodColor
Definition: skin.h:35
CSkinTextures m_OriginalSkin
Definition: skin.h:33
CSkinTextures m_ColorableSkin
Definition: skin.h:34
Definition: mapitems.h:527
Definition: mapitems.h:536
Definition: render.h:138
ColorRGBA m_BotColor
Definition: render.h:167
bool m_aUseCustomColors[protocol7::NUM_SKINPARTS]
Definition: render.h:161
void Reset()
Definition: render.h:140
ColorRGBA m_BloodColor
Definition: render.h:163
IGraphics::CTextureHandle m_aColorableTextures[protocol7::NUM_SKINPARTS]
Definition: render.h:160
IGraphics::CTextureHandle m_aOriginalTextures[protocol7::NUM_SKINPARTS]
Definition: render.h:159
const IGraphics::CTextureHandle & PartTexture(int Part) const
Definition: render.h:169
ColorRGBA m_aColors[protocol7::NUM_SKINPARTS]
Definition: render.h:162
int m_HatSpriteIndex
Definition: render.h:166
IGraphics::CTextureHandle m_HatTexture
Definition: render.h:164
IGraphics::CTextureHandle m_BotTexture
Definition: render.h:165
Definition: render.h:69
void Apply(const CSkin *pSkin)
Definition: render.h:94
void Reset()
Definition: render.h:76
bool Valid() const
Definition: render.h:132
ColorRGBA m_BloodColor
Definition: render.h:123
void ApplyColors(bool CustomColoredSkin, int ColorBody, int ColorFeet)
Definition: render.h:102
bool m_CustomColoredSkin
Definition: render.h:122
CTeeRenderInfo()
Definition: render.h:71
bool m_GotAirJump
Definition: render.h:128
CSkin::CSkinMetrics m_SkinMetrics
Definition: render.h:120
ColorRGBA m_ColorBody
Definition: render.h:125
bool m_FeetFlipped
Definition: render.h:130
CSkin::CSkinTextures m_ColorableRenderSkin
Definition: render.h:118
CSkin::CSkinTextures m_OriginalRenderSkin
Definition: render.h:117
int m_TeeRenderFlags
Definition: render.h:129
ColorRGBA m_ColorFeet
Definition: render.h:126
CSixup m_aSixup[NUM_DUMMIES]
Definition: render.h:175
float m_Size
Definition: render.h:127
Definition: mapitems.h:520
Definition: mapitems.h:238
Definition: mapitems.h:553
Definition: ui_rect.h:11
Definition: color.h:173
static constexpr const float DARKEST_LGT
Definition: color.h:178
Definition: color.h:210
Definition: render.h:221
virtual const CEnvPointBezier * GetBezier(int Index) const =0
virtual ~IEnvelopePointAccess()=default
virtual int NumPoints() const =0
virtual const CEnvPoint * GetPoint(int Index) const =0
Definition: graphics.h:201
void Invalidate()
Definition: graphics.h:214
bool IsValid() const
Definition: graphics.h:211
Definition: graphics.h:184
Definition: map.h:16
Definition: textrender.h:314
@ NUM_DUMMIES
Definition: enums.h:8
@ MAX_SKIN_LENGTH
Definition: protocol.h:100
Definition: render.h:24
@ NUM_SKINPARTS
Definition: protocol7.h:36
@ MAX_SKIN_LENGTH
Definition: protocol7.h:63
void(* ENVELOPE_EVAL)(int TimeOffsetMillis, int Env, ColorRGBA &Result, size_t Channels, void *pUser)
Definition: render.h:249
@ TEE_EFFECT_SPARKLE
Definition: render.h:203
@ TEE_NO_WEAPON
Definition: render.h:202
@ TEE_EFFECT_FROZEN
Definition: render.h:201
@ SPRITE_FLAG_FLIP_X
Definition: render.h:210
@ OVERLAYRENDERFLAG_TEXT
Definition: render.h:217
@ TILERENDERFLAG_EXTEND
Definition: render.h:215
@ SPRITE_FLAG_FLIP_Y
Definition: render.h:209
@ LAYERRENDERFLAG_OPAQUE
Definition: render.h:212
@ LAYERRENDERFLAG_TRANSPARENT
Definition: render.h:213
Definition: client_data.h:29
Definition: client_data7.h:32