mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-14 03:58:18 +00:00
Improve performance when rendering map overlay texts
The text color was previously set and reset for every individual number being rendered for non-empty tele, speedup, switch and tune tiles. The color is the same for all tiles from each entities layer, so most of these `TextColor` calls are unnecessary. Now the text color is only set and reset once when rendering each entities layer.
This commit is contained in:
parent
453bc0f66a
commit
4c2dfa24db
|
@ -724,8 +724,11 @@ void CRenderTools::RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale
|
||||||
return; // its useless to render text at this distance
|
return; // its useless to render text at this distance
|
||||||
|
|
||||||
float Size = g_Config.m_ClTextEntitiesSize / 100.f;
|
float Size = g_Config.m_ClTextEntitiesSize / 100.f;
|
||||||
|
char aBuf[16];
|
||||||
|
|
||||||
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||||
for(int y = StartY; y < EndY; y++)
|
for(int y = StartY; y < EndY; y++)
|
||||||
|
{
|
||||||
for(int x = StartX; x < EndX; x++)
|
for(int x = StartX; x < EndX; x++)
|
||||||
{
|
{
|
||||||
int mx = x;
|
int mx = x;
|
||||||
|
@ -745,21 +748,17 @@ void CRenderTools::RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale
|
||||||
unsigned char Index = pTele[c].m_Number;
|
unsigned char Index = pTele[c].m_Number;
|
||||||
if(Index && IsTeleTileNumberUsed(pTele[c].m_Type))
|
if(Index && IsTeleTileNumberUsed(pTele[c].m_Type))
|
||||||
{
|
{
|
||||||
char aBuf[16];
|
|
||||||
str_from_int(Index, aBuf);
|
str_from_int(Index, aBuf);
|
||||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
|
||||||
|
|
||||||
// Auto-resize text to fit inside the tile
|
// Auto-resize text to fit inside the tile
|
||||||
float ScaledWidth = TextRender()->TextWidth(Size * Scale, aBuf, -1);
|
float ScaledWidth = TextRender()->TextWidth(Size * Scale, aBuf, -1);
|
||||||
float Factor = clamp(Scale / ScaledWidth, 0.0f, 1.0f);
|
float Factor = clamp(Scale / ScaledWidth, 0.0f, 1.0f);
|
||||||
float LocalSize = Size * Factor;
|
float LocalSize = Size * Factor;
|
||||||
float ToCenterOffset = (1 - LocalSize) / 2.f;
|
float ToCenterOffset = (1 - LocalSize) / 2.f;
|
||||||
TextRender()->Text((mx + 0.5f) * Scale - (ScaledWidth * Factor) / 2.0f, (my + ToCenterOffset) * Scale, LocalSize * Scale, aBuf, -1.0f);
|
TextRender()->Text((mx + 0.5f) * Scale - (ScaledWidth * Factor) / 2.0f, (my + ToCenterOffset) * Scale, LocalSize * Scale, aBuf);
|
||||||
|
|
||||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
TextRender()->TextColor(TextRender()->DefaultTextColor());
|
||||||
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -778,8 +777,11 @@ void CRenderTools::RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, fl
|
||||||
|
|
||||||
float Size = g_Config.m_ClTextEntitiesSize / 100.f;
|
float Size = g_Config.m_ClTextEntitiesSize / 100.f;
|
||||||
float ToCenterOffset = (1 - Size) / 2.f;
|
float ToCenterOffset = (1 - Size) / 2.f;
|
||||||
|
char aBuf[16];
|
||||||
|
|
||||||
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||||
for(int y = StartY; y < EndY; y++)
|
for(int y = StartY; y < EndY; y++)
|
||||||
|
{
|
||||||
for(int x = StartX; x < EndX; x++)
|
for(int x = StartX; x < EndX; x++)
|
||||||
{
|
{
|
||||||
int mx = x;
|
int mx = x;
|
||||||
|
@ -803,32 +805,27 @@ void CRenderTools::RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, fl
|
||||||
// draw arrow
|
// draw arrow
|
||||||
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_SPEEDUP_ARROW].m_Id);
|
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_SPEEDUP_ARROW].m_Id);
|
||||||
Graphics()->QuadsBegin();
|
Graphics()->QuadsBegin();
|
||||||
Graphics()->SetColor(255.0f, 255.0f, 255.0f, Alpha);
|
Graphics()->SetColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||||
|
|
||||||
SelectSprite(SPRITE_SPEEDUP_ARROW);
|
SelectSprite(SPRITE_SPEEDUP_ARROW);
|
||||||
Graphics()->QuadsSetRotation(pSpeedup[c].m_Angle * (pi / 180.0f));
|
Graphics()->QuadsSetRotation(pSpeedup[c].m_Angle * (pi / 180.0f));
|
||||||
DrawSprite(mx * Scale + 16, my * Scale + 16, 35.0f);
|
DrawSprite(mx * Scale + 16, my * Scale + 16, 35.0f);
|
||||||
|
|
||||||
Graphics()->QuadsEnd();
|
Graphics()->QuadsEnd();
|
||||||
|
|
||||||
|
// draw force and max speed
|
||||||
if(g_Config.m_ClTextEntities)
|
if(g_Config.m_ClTextEntities)
|
||||||
{
|
{
|
||||||
// draw force
|
|
||||||
char aBuf[16];
|
|
||||||
str_from_int(Force, aBuf);
|
str_from_int(Force, aBuf);
|
||||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
TextRender()->Text(mx * Scale, (my + 0.5f + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf);
|
||||||
TextRender()->Text(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)
|
if(MaxSpeed)
|
||||||
{
|
{
|
||||||
str_from_int(MaxSpeed, aBuf);
|
str_from_int(MaxSpeed, aBuf);
|
||||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
TextRender()->Text(mx * Scale, (my + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf);
|
||||||
TextRender()->Text(mx * Scale, (my + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf, -1.0f);
|
|
||||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
TextRender()->TextColor(TextRender()->DefaultTextColor());
|
||||||
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,8 +847,11 @@ void CRenderTools::RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float
|
||||||
|
|
||||||
float Size = g_Config.m_ClTextEntitiesSize / 100.f;
|
float Size = g_Config.m_ClTextEntitiesSize / 100.f;
|
||||||
float ToCenterOffset = (1 - Size) / 2.f;
|
float ToCenterOffset = (1 - Size) / 2.f;
|
||||||
|
char aBuf[16];
|
||||||
|
|
||||||
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||||
for(int y = StartY; y < EndY; y++)
|
for(int y = StartY; y < EndY; y++)
|
||||||
|
{
|
||||||
for(int x = StartX; x < EndX; x++)
|
for(int x = StartX; x < EndX; x++)
|
||||||
{
|
{
|
||||||
int mx = x;
|
int mx = x;
|
||||||
|
@ -871,24 +871,19 @@ void CRenderTools::RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float
|
||||||
unsigned char Index = pSwitch[c].m_Number;
|
unsigned char Index = pSwitch[c].m_Number;
|
||||||
if(Index && IsSwitchTileNumberUsed(pSwitch[c].m_Type))
|
if(Index && IsSwitchTileNumberUsed(pSwitch[c].m_Type))
|
||||||
{
|
{
|
||||||
char aBuf[16];
|
|
||||||
str_from_int(Index, aBuf);
|
str_from_int(Index, aBuf);
|
||||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
TextRender()->Text(mx * Scale, (my + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf);
|
||||||
TextRender()->Text(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;
|
unsigned char Delay = pSwitch[c].m_Delay;
|
||||||
if(Delay && IsSwitchTileDelayUsed(pSwitch[c].m_Type))
|
if(Delay && IsSwitchTileDelayUsed(pSwitch[c].m_Type))
|
||||||
{
|
{
|
||||||
char aBuf[16];
|
|
||||||
str_from_int(Delay, aBuf);
|
str_from_int(Delay, aBuf);
|
||||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
TextRender()->Text(mx * Scale, (my + 0.5f + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf);
|
||||||
TextRender()->Text(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
TextRender()->TextColor(TextRender()->DefaultTextColor());
|
||||||
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -909,8 +904,11 @@ void CRenderTools::RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale
|
||||||
return; // its useless to render text at this distance
|
return; // its useless to render text at this distance
|
||||||
|
|
||||||
float Size = g_Config.m_ClTextEntitiesSize / 100.f;
|
float Size = g_Config.m_ClTextEntitiesSize / 100.f;
|
||||||
|
char aBuf[16];
|
||||||
|
|
||||||
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
||||||
for(int y = StartY; y < EndY; y++)
|
for(int y = StartY; y < EndY; y++)
|
||||||
|
{
|
||||||
for(int x = StartX; x < EndX; x++)
|
for(int x = StartX; x < EndX; x++)
|
||||||
{
|
{
|
||||||
int mx = x;
|
int mx = x;
|
||||||
|
@ -930,14 +928,12 @@ void CRenderTools::RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale
|
||||||
unsigned char Index = pTune[c].m_Number;
|
unsigned char Index = pTune[c].m_Number;
|
||||||
if(Index)
|
if(Index)
|
||||||
{
|
{
|
||||||
char aBuf[16];
|
|
||||||
str_from_int(Index, aBuf);
|
str_from_int(Index, aBuf);
|
||||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
|
TextRender()->Text(mx * Scale + 11.f, my * Scale + 6.f, Size * Scale / 1.5f - 5.f, aBuf); // numbers shouldn't be too big and in the center of the tile
|
||||||
TextRender()->Text(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
TextRender()->TextColor(TextRender()->DefaultTextColor());
|
||||||
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue