ddnet/src/game/client/skin.h

150 lines
3 KiB
C
Raw Normal View History

#ifndef GAME_CLIENT_SKIN_H
#define GAME_CLIENT_SKIN_H
#include <base/color.h>
#include <base/tl/sorted_array.h>
#include <base/vmath.h>
#include <engine/graphics.h>
2020-11-12 07:35:07 +00:00
#include <limits>
// do this better and nicer
struct CSkin
{
bool m_IsVanilla;
struct SSkinTextures
{
IGraphics::CTextureHandle m_Body;
IGraphics::CTextureHandle m_BodyOutline;
IGraphics::CTextureHandle m_Feet;
IGraphics::CTextureHandle m_FeetOutline;
IGraphics::CTextureHandle m_Hands;
IGraphics::CTextureHandle m_HandsOutline;
IGraphics::CTextureHandle m_Eyes[6];
void Reset()
{
m_Body = IGraphics::CTextureHandle();
m_BodyOutline = IGraphics::CTextureHandle();
m_Feet = IGraphics::CTextureHandle();
m_FeetOutline = IGraphics::CTextureHandle();
m_Hands = IGraphics::CTextureHandle();
m_HandsOutline = IGraphics::CTextureHandle();
2020-10-26 14:14:07 +00:00
for(auto &Eye : m_Eyes)
Eye = IGraphics::CTextureHandle();
}
};
SSkinTextures m_OriginalSkin;
SSkinTextures m_ColorableSkin;
char m_aName[24];
ColorRGBA m_BloodColor;
2020-11-12 07:35:07 +00:00
template<bool IsSizeType>
struct SSkinMetricVariableInt
2020-11-08 05:39:16 +00:00
{
2020-11-12 07:35:07 +00:00
int m_Value;
operator int() { return m_Value; }
SSkinMetricVariableInt &operator=(int NewVal)
{
if(IsSizeType)
m_Value = maximum(m_Value, NewVal);
else
m_Value = minimum(m_Value, NewVal);
return *this;
}
2020-11-08 05:39:16 +00:00
2020-11-12 07:35:07 +00:00
SSkinMetricVariableInt()
2020-11-08 05:39:16 +00:00
{
2020-11-12 07:35:07 +00:00
Reset();
2020-11-08 05:39:16 +00:00
}
2020-11-12 07:35:07 +00:00
void Reset()
2020-11-08 05:39:16 +00:00
{
2020-11-12 07:35:07 +00:00
if(IsSizeType)
m_Value = std::numeric_limits<int>::lowest();
else
m_Value = std::numeric_limits<int>::max();
2020-11-08 05:39:16 +00:00
}
2020-11-12 07:35:07 +00:00
};
struct SSkinMetricVariable
{
SSkinMetricVariableInt<true> m_Width;
SSkinMetricVariableInt<true> m_Height;
SSkinMetricVariableInt<false> m_OffsetX;
SSkinMetricVariableInt<false> m_OffsetY;
// these can be used to normalize the metrics
SSkinMetricVariableInt<true> m_MaxWidth;
SSkinMetricVariableInt<true> m_MaxHeight;
2020-11-08 05:39:16 +00:00
2020-11-12 07:35:07 +00:00
float WidthNormalized()
2020-11-08 05:39:16 +00:00
{
2020-11-12 07:35:07 +00:00
return (float)m_Width / (float)m_MaxWidth;
2020-11-08 05:39:16 +00:00
}
2020-11-12 07:35:07 +00:00
float HeightNormalized()
2020-11-08 05:39:16 +00:00
{
2020-11-12 07:35:07 +00:00
return (float)m_Height / (float)m_MaxHeight;
2020-11-08 05:39:16 +00:00
}
2020-11-12 07:35:07 +00:00
float OffsetXNormalized()
2020-11-08 05:39:16 +00:00
{
2020-11-12 07:35:07 +00:00
return (float)m_OffsetX / (float)m_MaxWidth;
2020-11-08 05:39:16 +00:00
}
2020-11-12 07:35:07 +00:00
float OffsetYNormalized()
2020-11-08 05:39:16 +00:00
{
2020-11-12 07:35:07 +00:00
return (float)m_OffsetY / (float)m_MaxHeight;
2020-11-08 05:39:16 +00:00
}
2020-11-12 07:35:07 +00:00
void Reset()
2020-11-08 05:39:16 +00:00
{
2020-11-12 07:35:07 +00:00
m_Width.Reset();
m_Height.Reset();
m_OffsetX.Reset();
m_OffsetY.Reset();
m_MaxWidth.Reset();
m_MaxHeight.Reset();
2020-11-08 05:39:16 +00:00
}
2020-11-12 07:35:07 +00:00
};
struct SSkinMetrics
{
SSkinMetricVariable m_Body;
SSkinMetricVariable m_Feet;
int m_FeetWidth;
int m_FeetHeight;
int m_FeetOffsetX;
int m_FeetOffsetY;
2020-11-08 05:39:16 +00:00
2020-11-12 07:35:07 +00:00
// these can be used to normalize the metrics
int m_FeetMaxWidth;
int m_FeetMaxHeight;
void Reset()
2020-11-08 05:39:16 +00:00
{
2020-11-12 07:35:07 +00:00
m_Body.Reset();
m_Feet.Reset();
2020-11-08 05:39:16 +00:00
}
2020-11-12 07:35:07 +00:00
SSkinMetrics()
2020-11-08 05:39:16 +00:00
{
2020-11-12 07:35:07 +00:00
Reset();
2020-11-08 05:39:16 +00:00
}
};
SSkinMetrics m_Metrics;
2020-10-30 09:05:46 +00:00
bool operator<(const CSkin &Other) const { return str_comp_nocase(m_aName, Other.m_aName) < 0; }
2020-10-30 09:05:46 +00:00
bool operator<(const char *pOther) const { return str_comp_nocase(m_aName, pOther) < 0; }
bool operator==(const char *pOther) const { return !str_comp_nocase(m_aName, pOther); }
};
#endif