DDraceNetwork Docs
skin.h
Go to the documentation of this file.
1#ifndef GAME_CLIENT_SKIN_H
2#define GAME_CLIENT_SKIN_H
3
4#include <base/color.h>
5#include <base/system.h>
6#include <base/vmath.h>
7
8#include <engine/graphics.h>
10
11#include <limits>
12
13// do this better and nicer
14struct CSkin
15{
16private:
18
19public:
21 {
24
27
30
32
33 void Reset()
34 {
41 for(auto &Eye : m_aEyes)
43 }
44
45 void Unload(IGraphics *pGraphics)
46 {
47 pGraphics->UnloadTexture(&m_Body);
48 pGraphics->UnloadTexture(&m_BodyOutline);
49 pGraphics->UnloadTexture(&m_Feet);
50 pGraphics->UnloadTexture(&m_FeetOutline);
51 pGraphics->UnloadTexture(&m_Hands);
52 pGraphics->UnloadTexture(&m_HandsOutline);
53 for(auto &Eye : m_aEyes)
54 pGraphics->UnloadTexture(&Eye);
55 }
56 };
57
61
62 template<bool IsSizeType>
64 {
66 operator int() const { return m_Value; }
68 {
69 if(IsSizeType)
70 m_Value = maximum(m_Value, NewVal);
71 else
72 m_Value = minimum(m_Value, NewVal);
73 return *this;
74 }
75
77 {
78 Reset();
79 }
80
81 void Reset()
82 {
83 if(IsSizeType)
84 m_Value = std::numeric_limits<int>::lowest();
85 else
86 m_Value = std::numeric_limits<int>::max();
87 }
88 };
89
91 {
96
97 // these can be used to normalize the metrics
100
101 float WidthNormalized() const
102 {
103 return (float)m_Width / (float)m_MaxWidth;
104 }
105
106 float HeightNormalized() const
107 {
108 return (float)m_Height / (float)m_MaxHeight;
109 }
110
111 float OffsetXNormalized() const
112 {
113 return (float)m_OffsetX / (float)m_MaxWidth;
114 }
115
116 float OffsetYNormalized() const
117 {
118 return (float)m_OffsetY / (float)m_MaxHeight;
119 }
120
121 void Reset()
122 {
123 m_Width.Reset();
124 m_Height.Reset();
129 }
130 };
131
133 {
136
137 void Reset()
138 {
139 m_Body.Reset();
140 m_Feet.Reset();
141 }
142
144 {
145 Reset();
146 }
147 };
149
150 bool operator<(const CSkin &Other) const { return str_comp(m_aName, Other.m_aName) < 0; }
151 bool operator==(const CSkin &Other) const { return !str_comp(m_aName, Other.m_aName); }
152
153 CSkin(const char *pName)
154 {
155 str_copy(m_aName, pName);
156 }
157 CSkin(CSkin &&) = default;
158 CSkin &operator=(CSkin &&) = default;
159
160 const char *GetName() const { return m_aName; }
161
162 // has to be kept in sync with m_aSkinNameRestrictions
163 static bool IsValidName(const char *pName)
164 {
165 if(pName[0] == '\0' || str_length(pName) >= (int)sizeof(CSkin("").m_aName))
166 {
167 return false;
168 }
169
170 for(int i = 0; pName[i] != '\0'; ++i)
171 {
172 if(pName[i] == '"' || pName[i] == '/' || pName[i] == '\\')
173 {
174 return false;
175 }
176 }
177 return true;
178 }
179 static constexpr char m_aSkinNameRestrictions[] = "Skin names must be valid filenames shorter than 24 characters.";
180};
181
182#endif
Definition: color.h:210
Definition: graphics.h:200
Definition: graphics.h:183
virtual void UnloadTexture(CTextureHandle *pIndex)=0
@ MAX_SKIN_LENGTH
Definition: protocol.h:99
int str_length(const char *str)
Definition: system.cpp:2754
int str_comp(const char *a, const char *b)
Definition: system.cpp:2933
int str_copy(char *dst, const char *src, int dst_size)
Definition: system.cpp:2720
constexpr T minimum(T a, T b)
Definition: math.h:120
constexpr T maximum(T a, T b)
Definition: math.h:130
Definition: skin.h:64
int m_Value
Definition: skin.h:65
void Reset()
Definition: skin.h:81
SSkinMetricVariableInt & operator=(int NewVal)
Definition: skin.h:67
SSkinMetricVariableInt()
Definition: skin.h:76
Definition: skin.h:91
float OffsetXNormalized() const
Definition: skin.h:111
SSkinMetricVariableInt< true > m_MaxWidth
Definition: skin.h:98
void Reset()
Definition: skin.h:121
SSkinMetricVariableInt< true > m_Height
Definition: skin.h:93
SSkinMetricVariableInt< false > m_OffsetY
Definition: skin.h:95
SSkinMetricVariableInt< false > m_OffsetX
Definition: skin.h:94
SSkinMetricVariableInt< true > m_MaxHeight
Definition: skin.h:99
SSkinMetricVariableInt< true > m_Width
Definition: skin.h:92
float WidthNormalized() const
Definition: skin.h:101
float OffsetYNormalized() const
Definition: skin.h:116
float HeightNormalized() const
Definition: skin.h:106
Definition: skin.h:133
SSkinMetricVariable m_Feet
Definition: skin.h:135
SSkinMetricVariable m_Body
Definition: skin.h:134
void Reset()
Definition: skin.h:137
SSkinMetrics()
Definition: skin.h:143
Definition: skin.h:21
IGraphics::CTextureHandle m_BodyOutline
Definition: skin.h:23
IGraphics::CTextureHandle m_Hands
Definition: skin.h:28
IGraphics::CTextureHandle m_Feet
Definition: skin.h:25
IGraphics::CTextureHandle m_Body
Definition: skin.h:22
IGraphics::CTextureHandle m_aEyes[6]
Definition: skin.h:31
IGraphics::CTextureHandle m_FeetOutline
Definition: skin.h:26
void Unload(IGraphics *pGraphics)
Definition: skin.h:45
IGraphics::CTextureHandle m_HandsOutline
Definition: skin.h:29
void Reset()
Definition: skin.h:33
Definition: skin.h:15
const char * GetName() const
Definition: skin.h:160
bool operator<(const CSkin &Other) const
Definition: skin.h:150
SSkinMetrics m_Metrics
Definition: skin.h:148
static bool IsValidName(const char *pName)
Definition: skin.h:163
SSkinTextures m_ColorableSkin
Definition: skin.h:59
SSkinTextures m_OriginalSkin
Definition: skin.h:58
ColorRGBA m_BloodColor
Definition: skin.h:60
char m_aName[MAX_SKIN_LENGTH]
Definition: skin.h:17
CSkin(const char *pName)
Definition: skin.h:153
static constexpr char m_aSkinNameRestrictions[]
Definition: skin.h:179
CSkin(CSkin &&)=default
bool operator==(const CSkin &Other) const
Definition: skin.h:151
CSkin & operator=(CSkin &&)=default