mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #5122
5122: Cleanup CRenderTools r=heinrich5991 a=Robyt3 ## Checklist - [X] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
commit
3d244b728d
|
@ -751,7 +751,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
|
|||
str_format(aBuf, sizeof(aBuf), "%s", s->m_aName);
|
||||
SLabelProperties Props;
|
||||
Props.m_MaxWidth = Item.m_Rect.w;
|
||||
RenderTools()->UI()->DoLabelScaled(&Item.m_Rect, aBuf, 12.0f, TEXTALIGN_LEFT, Props);
|
||||
UI()->DoLabelScaled(&Item.m_Rect, aBuf, 12.0f, TEXTALIGN_LEFT, Props);
|
||||
if(g_Config.m_Debug)
|
||||
{
|
||||
ColorRGBA BloodColor = *UseCustomColor ? color_cast<ColorRGBA>(ColorHSLA(*ColorBody)) : s->m_BloodColor;
|
||||
|
|
|
@ -222,8 +222,7 @@ void CGameClient::OnInit()
|
|||
|
||||
// propagate pointers
|
||||
m_UI.Init(Graphics(), TextRender());
|
||||
|
||||
m_RenderTools.Init(Graphics(), UI(), this);
|
||||
m_RenderTools.Init(Graphics(), TextRender());
|
||||
|
||||
int64_t Start = time_get();
|
||||
|
||||
|
|
|
@ -19,11 +19,10 @@
|
|||
static float gs_SpriteWScale;
|
||||
static float gs_SpriteHScale;
|
||||
|
||||
void CRenderTools::Init(IGraphics *pGraphics, CUI *pUI, CGameClient *pGameClient)
|
||||
void CRenderTools::Init(IGraphics *pGraphics, ITextRender *pTextRender)
|
||||
{
|
||||
m_pGraphics = pGraphics;
|
||||
m_pUI = pUI;
|
||||
m_pGameClient = (CGameClient *)pGameClient;
|
||||
m_pTextRender = pTextRender;
|
||||
m_TeeQuadContainerIndex = Graphics()->CreateQuadContainer(false);
|
||||
Graphics()->SetColor(1.f, 1.f, 1.f, 1.f);
|
||||
|
||||
|
@ -65,21 +64,12 @@ void CRenderTools::SelectSprite(CDataSprite *pSpr, int Flags, int sx, int sy)
|
|||
float x2 = (x + w) / (float)cx - 0.5f / (float)(cx * 32);
|
||||
float y1 = y / (float)cy + 0.5f / (float)(cy * 32);
|
||||
float y2 = (y + h) / (float)cy - 0.5f / (float)(cy * 32);
|
||||
float Temp = 0;
|
||||
|
||||
if(Flags & SPRITE_FLAG_FLIP_Y)
|
||||
{
|
||||
Temp = y1;
|
||||
y1 = y2;
|
||||
y2 = Temp;
|
||||
}
|
||||
std::swap(y1, y2);
|
||||
|
||||
if(Flags & SPRITE_FLAG_FLIP_X)
|
||||
{
|
||||
Temp = x1;
|
||||
x1 = x2;
|
||||
x2 = Temp;
|
||||
}
|
||||
std::swap(x1, x2);
|
||||
|
||||
Graphics()->QuadsSetSubset(x1, y1, x2, y2);
|
||||
}
|
||||
|
@ -105,9 +95,9 @@ void CRenderTools::GetSpriteScale(struct CDataSprite *pSprite, float &ScaleX, fl
|
|||
GetSpriteScaleImpl(w, h, ScaleX, ScaleY);
|
||||
}
|
||||
|
||||
void CRenderTools::GetSpriteScale(int id, float &ScaleX, float &ScaleY)
|
||||
void CRenderTools::GetSpriteScale(int Id, float &ScaleX, float &ScaleY)
|
||||
{
|
||||
GetSpriteScale(&g_pData->m_aSprites[id], ScaleX, ScaleY);
|
||||
GetSpriteScale(&g_pData->m_aSprites[Id], ScaleX, ScaleY);
|
||||
}
|
||||
|
||||
void CRenderTools::GetSpriteScaleImpl(int Width, int Height, float &ScaleX, float &ScaleY)
|
||||
|
@ -483,7 +473,7 @@ void CRenderTools::DrawUIRect(const CUIRect *pRect, ColorRGBA Color, int Corners
|
|||
// TODO: FIX US
|
||||
Graphics()->QuadsBegin();
|
||||
Graphics()->SetColor(Color);
|
||||
DrawRoundRectExt(pRect->x, pRect->y, pRect->w, pRect->h, Rounding * UI()->Scale(), Corners);
|
||||
DrawRoundRectExt(pRect->x, pRect->y, pRect->w, pRect->h, Rounding * pRect->Scale(), Corners);
|
||||
Graphics()->QuadsEnd();
|
||||
}
|
||||
|
||||
|
@ -715,16 +705,16 @@ void CRenderTools::RenderTee(CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote
|
|||
Graphics()->QuadsSetRotation(pFoot->m_Angle * pi * 2);
|
||||
|
||||
bool Indicate = !pInfo->m_GotAirJump && g_Config.m_ClAirjumpindicator;
|
||||
float cs = 1.0f; // color scale
|
||||
float ColorScale = 1.0f;
|
||||
|
||||
if(!OutLine)
|
||||
{
|
||||
++QuadOffset;
|
||||
if(Indicate)
|
||||
cs = 0.5f;
|
||||
ColorScale = 0.5f;
|
||||
}
|
||||
|
||||
Graphics()->SetColor(pInfo->m_ColorFeet.r * cs, pInfo->m_ColorFeet.g * cs, pInfo->m_ColorFeet.b * cs, Alpha);
|
||||
Graphics()->SetColor(pInfo->m_ColorFeet.r * ColorScale, pInfo->m_ColorFeet.g * ColorScale, pInfo->m_ColorFeet.b * ColorScale, Alpha);
|
||||
|
||||
Graphics()->TextureSet(OutLine == 1 ? pSkinTextures->m_FeetOutline : pSkinTextures->m_Feet);
|
||||
Graphics()->RenderQuadContainerAsSprite(m_TeeQuadContainerIndex, QuadOffset, Position.x + pFoot->m_X * AnimScale, Position.y + pFoot->m_Y * AnimScale, w / 64.f, h / 32.f);
|
||||
|
|
|
@ -53,6 +53,9 @@ typedef void (*ENVELOPE_EVAL)(int TimeOffsetMillis, int Env, float *pChannels, v
|
|||
|
||||
class CRenderTools
|
||||
{
|
||||
class IGraphics *m_pGraphics;
|
||||
class ITextRender *m_pTextRender;
|
||||
|
||||
int m_TeeQuadContainerIndex;
|
||||
|
||||
void GetRenderTeeAnimScaleAndBaseSize(class CAnimState *pAnim, CTeeRenderInfo *pInfo, float &AnimScale, float &BaseSize);
|
||||
|
@ -60,24 +63,17 @@ class CRenderTools
|
|||
void GetRenderTeeFeetScale(float BaseSize, float &FeetScaleWidth, float &FeetScaleHeight);
|
||||
|
||||
public:
|
||||
class IGraphics *m_pGraphics;
|
||||
class CUI *m_pUI;
|
||||
class CGameClient *m_pGameClient;
|
||||
|
||||
class IGraphics *Graphics() const { return m_pGraphics; }
|
||||
class CUI *UI() const { return m_pUI; }
|
||||
class CGameClient *GameClient() const { return m_pGameClient; }
|
||||
class ITextRender *TextRender() const { return m_pTextRender; }
|
||||
|
||||
void Init(class IGraphics *pGraphics, class CUI *pUI, class CGameClient *pGameClient);
|
||||
|
||||
//typedef struct SPRITE;
|
||||
void Init(class IGraphics *pGraphics, class ITextRender *pTextRender);
|
||||
|
||||
void SelectSprite(struct CDataSprite *pSprite, int Flags = 0, int sx = 0, int sy = 0);
|
||||
void SelectSprite(int id, int Flags = 0, int sx = 0, int sy = 0);
|
||||
void SelectSprite(int Id, int Flags = 0, int sx = 0, int sy = 0);
|
||||
|
||||
void GetSpriteScale(client_data7::CDataSprite *pSprite, float &ScaleX, float &ScaleY);
|
||||
void GetSpriteScale(struct CDataSprite *pSprite, float &ScaleX, float &ScaleY);
|
||||
void GetSpriteScale(int id, float &ScaleX, float &ScaleY);
|
||||
void GetSpriteScale(int Id, float &ScaleX, float &ScaleY);
|
||||
void GetSpriteScaleImpl(int Width, int Height, float &ScaleX, float &ScaleY);
|
||||
|
||||
void DrawSprite(float x, float y, float size);
|
||||
|
@ -108,10 +104,10 @@ public:
|
|||
|
||||
// returns the offset to use, to render the tee with @see RenderTee exactly in the mid
|
||||
void GetRenderTeeOffsetToRenderedTee(class CAnimState *pAnim, CTeeRenderInfo *pInfo, vec2 &TeeOffsetToMid);
|
||||
// object render methods (gc_render_obj.cpp)
|
||||
// object render methods
|
||||
void RenderTee(class CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha = 1.0f);
|
||||
|
||||
// map render methods (gc_render_map.cpp)
|
||||
// map render methods (render_map.cpp)
|
||||
static void RenderEvalEnvelope(CEnvPoint *pPoints, int NumPoints, int Channels, int64_t TimeMicros, float *pResult);
|
||||
void RenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser);
|
||||
void ForceRenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser, float Alpha = 1.0f);
|
||||
|
|
|
@ -472,9 +472,9 @@ void CRenderTools::RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale
|
|||
{
|
||||
char aBuf[16];
|
||||
str_format(aBuf, sizeof(aBuf), "%d", Index);
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
UI()->TextRender()->Text(0, mx * Scale - 3.f, (my + ToCenterOffset) * Scale, Size * Scale, aBuf, -1.0f);
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
TextRender()->Text(0, mx * Scale - 3.f, (my + ToCenterOffset) * Scale, Size * Scale, aBuf, -1.0f);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -534,15 +534,15 @@ void CRenderTools::RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, fl
|
|||
// draw force
|
||||
char aBuf[16];
|
||||
str_format(aBuf, sizeof(aBuf), "%d", Force);
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
UI()->TextRender()->Text(0, mx * Scale, (my + 0.5f + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf, -1.0f);
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
TextRender()->Text(0, mx * Scale, (my + 0.5f + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf, -1.0f);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
if(MaxSpeed)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "%d", MaxSpeed);
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
UI()->TextRender()->Text(0, mx * Scale, (my + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf, -1.0f);
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
TextRender()->Text(0, mx * Scale, (my + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf, -1.0f);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -591,9 +591,9 @@ void CRenderTools::RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float
|
|||
{
|
||||
char aBuf[16];
|
||||
str_format(aBuf, sizeof(aBuf), "%d", Index);
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
UI()->TextRender()->Text(0, mx * Scale, (my + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf, -1.0f);
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
TextRender()->Text(0, mx * Scale, (my + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf, -1.0f);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
unsigned char Delay = pSwitch[c].m_Delay;
|
||||
|
@ -601,9 +601,9 @@ void CRenderTools::RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float
|
|||
{
|
||||
char aBuf[16];
|
||||
str_format(aBuf, sizeof(aBuf), "%d", Delay);
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
UI()->TextRender()->Text(0, mx * Scale, (my + 0.5f + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf, -1.0f);
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
TextRender()->Text(0, mx * Scale, (my + 0.5f + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf, -1.0f);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -650,9 +650,9 @@ void CRenderTools::RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale
|
|||
{
|
||||
char aBuf[16];
|
||||
str_format(aBuf, sizeof(aBuf), "%d", Index);
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
UI()->TextRender()->Text(0, mx * Scale + 11.f, my * Scale + 6.f, Size * Scale / 1.5f - 5.f, aBuf, -1.0f); // numbers shouldn't be too big and in the center of the tile
|
||||
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||
TextRender()->Text(0, mx * Scale + 11.f, my * Scale + 6.f, Size * Scale / 1.5f - 5.f, aBuf, -1.0f); // numbers shouldn't be too big and in the center of the tile
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
class CUIRect
|
||||
{
|
||||
public:
|
||||
// TODO: Refactor: Redo UI scaling
|
||||
float Scale() const;
|
||||
|
||||
public:
|
||||
float x, y, w, h;
|
||||
|
||||
/**
|
||||
|
|
|
@ -6342,9 +6342,8 @@ void CEditor::Init()
|
|||
m_pTextRender = Kernel()->RequestInterface<ITextRender>();
|
||||
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
||||
m_pSound = Kernel()->RequestInterface<ISound>();
|
||||
CGameClient *pGameClient = (CGameClient *)Kernel()->RequestInterface<IGameClient>();
|
||||
m_UI.Init(m_pGraphics, m_pTextRender);
|
||||
m_RenderTools.Init(m_pGraphics, &m_UI, pGameClient);
|
||||
m_RenderTools.Init(m_pGraphics, m_pTextRender);
|
||||
m_Map.m_pEditor = this;
|
||||
|
||||
UIEx()->Init(UI(), Kernel(), RenderTools(), Input()->GetEventsRaw(), Input()->GetEventCountRaw());
|
||||
|
|
Loading…
Reference in a new issue