DDraceNetwork Docs
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
15class CAnimState;
16class CSpeedupTile;
17class CSwitchTile;
18class CTeleTile;
19class CTile;
20class CTuneTile;
21namespace client_data7 {
22struct CDataSprite;
23}
24struct CDataSprite;
25struct CEnvPoint;
26struct CEnvPointBezier;
28struct CMapItemGroup;
29struct CQuad;
30
32
34{
35public:
37 {
38 Reset();
39 }
40
41 void Reset()
42 {
46 m_CustomColoredSkin = false;
47 m_BloodColor = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
48 m_ColorBody = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
49 m_ColorFeet = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
50 m_Size = 1.0f;
51 m_GotAirJump = true;
53 m_FeetFlipped = false;
54
55 for(auto &Sixup : m_aSixup)
56 Sixup.Reset();
57 }
58
59 void Apply(const CSkin *pSkin)
60 {
64 m_SkinMetrics = pSkin->m_Metrics;
65 }
66
67 void ApplyColors(bool CustomColoredSkin, int ColorBody, int ColorFeet)
68 {
69 m_CustomColoredSkin = CustomColoredSkin;
70 if(CustomColoredSkin)
71 {
72 m_ColorBody = color_cast<ColorRGBA>(ColorHSLA(ColorBody).UnclampLighting(ColorHSLA::DARKEST_LGT));
73 m_ColorFeet = color_cast<ColorRGBA>(ColorHSLA(ColorFeet).UnclampLighting(ColorHSLA::DARKEST_LGT));
74 }
75 else
76 {
77 m_ColorBody = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
78 m_ColorFeet = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
79 }
80 }
81
84
86
89
92 float m_Size;
96
97 bool Valid() const
98 {
100 }
101
102 class CSixup
103 {
104 public:
105 void Reset()
106 {
107 for(auto &Texture : m_aTextures)
108 Texture = IGraphics::CTextureHandle();
110 for(ColorRGBA &PartColor : m_aColors)
111 {
112 PartColor = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
113 }
115 m_BotColor = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
116 }
117 bool Valid() const
118 {
119 for(const auto &Texture : m_aTextures)
120 if(!Texture.IsValid())
121 return false;
122 return true;
123 }
124
131 };
132
134};
135
136// Tee Render Flags
137enum
138{
142};
143
144// sprite renderings
145enum
146{
149
152
154};
155
157{
158public:
159 virtual ~IEnvelopePointAccess() = default;
160 virtual int NumPoints() const = 0;
161 virtual const CEnvPoint *GetPoint(int Index) const = 0;
162 virtual const CEnvPointBezier *GetBezier(int Index) const = 0;
163};
164
166{
173
174public:
177 void SetPointsRange(int StartPoint, int NumPoints);
178 int StartPoint() const;
179 int NumPoints() const override;
180 int NumPointsMax() const;
181 const CEnvPoint *GetPoint(int Index) const override;
182 const CEnvPointBezier *GetBezier(int Index) const override;
183};
184
185typedef void (*ENVELOPE_EVAL)(int TimeOffsetMillis, int Env, ColorRGBA &Result, size_t Channels, void *pUser);
186
188{
191
193
194 static void GetRenderTeeBodyScale(float BaseSize, float &BodyScale);
195 static void GetRenderTeeFeetScale(float BaseSize, float &FeetScaleWidth, float &FeetScaleHeight);
196
197 void SelectSprite(const CDataSprite *pSprite, int Flags) const;
198
199 void RenderTee6(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha = 1.0f) const;
200 void RenderTee7(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha = 1.0f) const;
201
202public:
203 class IGraphics *Graphics() const { return m_pGraphics; }
204 class ITextRender *TextRender() const { return m_pTextRender; }
205
206 void Init(class IGraphics *pGraphics, class ITextRender *pTextRender);
207
208 void SelectSprite(int Id, int Flags = 0) const;
209 void SelectSprite7(int Id, int Flags = 0) const;
210
211 void GetSpriteScale(const CDataSprite *pSprite, float &ScaleX, float &ScaleY) const;
212 void GetSpriteScale(int Id, float &ScaleX, float &ScaleY) const;
213 void GetSpriteScaleImpl(int Width, int Height, float &ScaleX, float &ScaleY) const;
214
215 void DrawSprite(float x, float y, float Size) const;
216 void DrawSprite(float x, float y, float ScaledWidth, float ScaledHeight) const;
217 void RenderCursor(vec2 Center, float Size) const;
218 void RenderIcon(int ImageId, int SpriteId, const CUIRect *pRect, const ColorRGBA *pColor = nullptr) const;
219 int QuadContainerAddSprite(int QuadContainerIndex, float x, float y, float Size) const;
220 int QuadContainerAddSprite(int QuadContainerIndex, float Size) const;
221 int QuadContainerAddSprite(int QuadContainerIndex, float Width, float Height) const;
222 int QuadContainerAddSprite(int QuadContainerIndex, float X, float Y, float Width, float Height) const;
223
224 // larger rendering methods
225 static void GetRenderTeeBodySize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &BodyOffset, float &Width, float &Height);
226 static void GetRenderTeeFeetSize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &FeetOffset, float &Width, float &Height);
227 static void GetRenderTeeAnimScaleAndBaseSize(const CTeeRenderInfo *pInfo, float &AnimScale, float &BaseSize);
228
229 // returns the offset to use, to render the tee with @see RenderTee exactly in the mid
230 static void GetRenderTeeOffsetToRenderedTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &TeeOffsetToMid);
231 // object render methods
232 void RenderTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha = 1.0f) const;
233
234 // map render methods (render_map.cpp)
235 static void RenderEvalEnvelope(const IEnvelopePointAccess *pPoints, std::chrono::nanoseconds TimeNanos, ColorRGBA &Result, size_t Channels);
236 void RenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser) const;
237 void ForceRenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser, float Alpha = 1.0f) const;
238 void RenderTilemap(CTile *pTiles, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
239
240 // render a rectangle made of IndexIn tiles, over a background made of IndexOut tiles
241 // the rectangle include all tiles in [RectX, RectX+RectW-1] x [RectY, RectY+RectH-1]
242 void RenderTileRectangle(int RectX, int RectY, int RectW, int RectH, unsigned char IndexIn, unsigned char IndexOut, float Scale, ColorRGBA Color, int RenderFlags) const;
243
244 void RenderTile(int x, int y, unsigned char Index, float Scale, ColorRGBA Color) const;
245
246 // helpers
247 void CalcScreenParams(float Aspect, float Zoom, float *pWidth, float *pHeight);
248 void MapScreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY,
249 float ParallaxZoom, float OffsetX, float OffsetY, float Aspect, float Zoom, float *pPoints);
250 void MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup, float Zoom);
251 void MapScreenToInterface(float CenterX, float CenterY);
252
253 // DDRace
254
255 void RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale, float Alpha = 1.0f) const;
256 void RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, float Scale, float Alpha = 1.0f) const;
257 void RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float Scale, float Alpha = 1.0f) const;
258 void RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale, float Alpha = 1.0f) const;
259 void RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
260 void RenderSpeedupmap(CSpeedupTile *pSpeedup, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
261 void RenderSwitchmap(CSwitchTile *pSwitch, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
262 void RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const;
263};
264
265#endif
Definition: animstate.h:9
Definition: datafile.h:24
Definition: render.h:166
int m_NumPoints
Definition: render.h:168
int NumPointsMax() const
Definition: render_map.cpp:100
int NumPoints() const override
Definition: render_map.cpp:95
int m_StartPoint
Definition: render.h:167
CEnvPoint * m_pPoints
Definition: render.h:170
int m_NumPointsMax
Definition: render.h:169
int StartPoint() const
Definition: render_map.cpp:90
CEnvPointBezier_upstream * m_pPointsBezierUpstream
Definition: render.h:172
const CEnvPointBezier * GetBezier(int Index) const override
Definition: render_map.cpp:116
CEnvPointBezier * m_pPointsBezier
Definition: render.h:171
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: render.h:188
static void GetRenderTeeFeetSize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &FeetOffset, float &Width, float &Height)
Definition: render.cpp:209
void CalcScreenParams(float Aspect, float Zoom, float *pWidth, float *pHeight)
Definition: render.cpp:612
void RenderTilemap(CTile *pTiles, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const
Definition: render_map.cpp:509
void RenderTee7(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha=1.0f) const
Definition: render.cpp:282
void RenderTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha=1.0f) const
Definition: render.cpp:271
static void RenderEvalEnvelope(const IEnvelopePointAccess *pPoints, std::chrono::nanoseconds TimeNanos, ColorRGBA &Result, size_t Channels)
Definition: render_map.cpp:228
void RenderCursor(vec2 Center, float Size) const
Definition: render.cpp:129
static void GetRenderTeeAnimScaleAndBaseSize(const CTeeRenderInfo *pInfo, float &AnimScale, float &BaseSize)
Definition: render.cpp:177
void RenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser) const
Definition: render_map.cpp:343
void RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const
Definition: render_map.cpp:1361
void RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale, float Alpha=1.0f) const
Definition: render_map.cpp:917
void RenderIcon(int ImageId, int SpriteId, const CUIRect *pRect, const ColorRGBA *pColor=nullptr) const
Definition: render.cpp:141
void RenderTee6(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha=1.0f) const
Definition: render.cpp:510
void DrawSprite(float x, float y, float Size) const
Definition: render.cpp:117
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:416
static void GetRenderTeeFeetScale(float BaseSize, float &FeetScaleWidth, float &FeetScaleHeight)
Definition: render.cpp:189
class ITextRender * m_pTextRender
Definition: render.h:190
static void GetRenderTeeBodyScale(float BaseSize, float &BodyScale)
Definition: render.cpp:183
static void GetRenderTeeOffsetToRenderedTee(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &TeeOffsetToMid)
Definition: render.cpp:223
void SelectSprite(const CDataSprite *pSprite, int Flags) const
Definition: render.cpp:61
void ForceRenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser, float Alpha=1.0f) const
Definition: render_map.cpp:351
void RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, float Scale, float Alpha=1.0f) const
Definition: render_map.cpp:792
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:639
void MapScreenToInterface(float CenterX, float CenterY)
Definition: render.cpp:666
void RenderSwitchmap(CSwitchTile *pSwitch, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const
Definition: render_map.cpp:1201
void GetSpriteScaleImpl(int Width, int Height, float &ScaleX, float &ScaleY) const
Definition: render.cpp:110
int QuadContainerAddSprite(int QuadContainerIndex, float x, float y, float Size) const
Definition: render.cpp:153
static void GetRenderTeeBodySize(const CAnimState *pAnim, const CTeeRenderInfo *pInfo, vec2 &BodyOffset, float &Width, float &Height)
Definition: render.cpp:195
void SelectSprite7(int Id, int Flags=0) const
Definition: render.cpp:92
class IGraphics * Graphics() const
Definition: render.h:203
void RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float Scale, float Alpha=1.0f) const
Definition: render_map.cpp:859
void Init(class IGraphics *pGraphics, class ITextRender *pTextRender)
Definition: render.cpp:23
void RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale, float Alpha=1.0f) const
Definition: render_map.cpp:737
class ITextRender * TextRender() const
Definition: render.h:204
void RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const
Definition: render_map.cpp:967
void RenderTile(int x, int y, unsigned char Index, float Scale, ColorRGBA Color) const
Definition: render_map.cpp:670
class IGraphics * m_pGraphics
Definition: render.h:189
void MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup, float Zoom)
Definition: render.cpp:657
void GetSpriteScale(const CDataSprite *pSprite, float &ScaleX, float &ScaleY) const
Definition: render.cpp:98
int m_TeeQuadContainerIndex
Definition: render.h:192
void RenderSpeedupmap(CSpeedupTile *pSpeedup, int w, int h, float Scale, ColorRGBA Color, int RenderFlags) const
Definition: render_map.cpp:1084
Definition: mapitems.h:539
Definition: mapitems.h:548
Definition: render.h:103
ColorRGBA m_BotColor
Definition: render.h:130
void Reset()
Definition: render.h:105
IGraphics::CTextureHandle m_aTextures[protocol7::NUM_SKINPARTS]
Definition: render.h:125
bool Valid() const
Definition: render.h:117
ColorRGBA m_aColors[protocol7::NUM_SKINPARTS]
Definition: render.h:126
int m_HatSpriteIndex
Definition: render.h:129
IGraphics::CTextureHandle m_HatTexture
Definition: render.h:127
IGraphics::CTextureHandle m_BotTexture
Definition: render.h:128
Definition: render.h:34
void Apply(const CSkin *pSkin)
Definition: render.h:59
void Reset()
Definition: render.h:41
bool Valid() const
Definition: render.h:97
ColorRGBA m_BloodColor
Definition: render.h:88
void ApplyColors(bool CustomColoredSkin, int ColorBody, int ColorFeet)
Definition: render.h:67
bool m_CustomColoredSkin
Definition: render.h:87
CTeeRenderInfo()
Definition: render.h:36
bool m_GotAirJump
Definition: render.h:93
ColorRGBA m_ColorBody
Definition: render.h:90
CSkin::SSkinTextures m_ColorableRenderSkin
Definition: render.h:83
bool m_FeetFlipped
Definition: render.h:95
CSkin::SSkinTextures m_OriginalRenderSkin
Definition: render.h:82
int m_TeeRenderFlags
Definition: render.h:94
ColorRGBA m_ColorFeet
Definition: render.h:91
CSkin::SSkinMetrics m_SkinMetrics
Definition: render.h:85
CSixup m_aSixup[NUM_DUMMIES]
Definition: render.h:133
float m_Size
Definition: render.h:92
Definition: mapitems.h:532
Definition: mapitems.h:236
Definition: mapitems.h:565
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:157
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:200
bool IsValid() const
Definition: graphics.h:210
Definition: graphics.h:183
Definition: map.h:16
Definition: textrender.h:312
@ NUM_DUMMIES
Definition: enums.h:8
Definition: render.h:21
@ NUM_SKINPARTS
Definition: protocol7.h:36
@ SPRITE_FLAG_FLIP_X
Definition: render.h:148
@ TILERENDERFLAG_EXTEND
Definition: render.h:153
@ SPRITE_FLAG_FLIP_Y
Definition: render.h:147
@ LAYERRENDERFLAG_OPAQUE
Definition: render.h:150
@ LAYERRENDERFLAG_TRANSPARENT
Definition: render.h:151
void(* ENVELOPE_EVAL)(int TimeOffsetMillis, int Env, ColorRGBA &Result, size_t Channels, void *pUser)
Definition: render.h:185
@ TEE_EFFECT_SPARKLE
Definition: render.h:141
@ TEE_NO_WEAPON
Definition: render.h:140
@ TEE_EFFECT_FROZEN
Definition: render.h:139
Definition: client_data.h:29
Definition: mapitems.h:406
Definition: mapitems.h:395
Definition: mapitems.h:378
Definition: mapitems.h:298
Definition: mapitems.h:223
Definition: skin.h:133
void Reset()
Definition: skin.h:137
Definition: skin.h:21
IGraphics::CTextureHandle m_Body
Definition: skin.h:22
void Reset()
Definition: skin.h:33
Definition: skin.h:15
SSkinMetrics m_Metrics
Definition: skin.h:148
SSkinTextures m_ColorableSkin
Definition: skin.h:59
SSkinTextures m_OriginalSkin
Definition: skin.h:58
ColorRGBA m_BloodColor
Definition: skin.h:60
Definition: client_data7.h:32