MCPcopy Create free account
hub / github.com/ddnet/ddnet / RenderTeleOverlay

Method RenderTeleOverlay

src/game/map/render_map.cpp:756–809  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

754}
755
756void CRenderMap::RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale, int OverlayRenderFlag, float Alpha)
757{
758 if(!(OverlayRenderFlag & OVERLAYRENDERFLAG_TEXT))
759 return;
760
761 float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
762 Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
763
764 int StartY = (int)(ScreenY0 / Scale) - 1;
765 int StartX = (int)(ScreenX0 / Scale) - 1;
766 int EndY = (int)(ScreenY1 / Scale) + 1;
767 int EndX = (int)(ScreenX1 / Scale) + 1;
768
769 if(EndX - StartX > Graphics()->ScreenWidth() / g_Config.m_GfxTextOverlay || EndY - StartY > Graphics()->ScreenHeight() / g_Config.m_GfxTextOverlay)
770 return; // its useless to render text at this distance
771
772 float Size = g_Config.m_ClTextEntitiesSize / 100.f;
773 char aBuf[16];
774
775 TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
776 for(int y = StartY; y < EndY; y++)
777 {
778 for(int x = StartX; x < EndX; x++)
779 {
780 int mx = x;
781 int my = y;
782
783 if(mx < 0)
784 continue; // mx = 0;
785 if(mx >= w)
786 continue; // mx = w-1;
787 if(my < 0)
788 continue; // my = 0;
789 if(my >= h)
790 continue; // my = h-1;
791
792 int c = mx + my * w;
793
794 unsigned char Index = pTele[c].m_Number;
795 if(Index && IsTeleTileNumberUsedAny(pTele[c].m_Type))
796 {
797 str_format(aBuf, sizeof(aBuf), "%d", Index);
798 // Auto-resize text to fit inside the tile
799 float ScaledWidth = TextRender()->TextWidth(Size * Scale, aBuf, -1);
800 float Factor = std::clamp(Scale / ScaledWidth, 0.0f, 1.0f);
801 float LocalSize = Size * Factor;
802 float ToCenterOffset = (1 - LocalSize) / 2.f;
803 TextRender()->Text((mx + 0.5f) * Scale - (ScaledWidth * Factor) / 2.0f, (my + ToCenterOffset) * Scale, LocalSize * Scale, aBuf);
804 }
805 }
806 }
807 TextRender()->TextColor(TextRender()->DefaultTextColor());
808 Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
809}
810
811void CRenderMap::RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, float Scale, int OverlayRenderFlag, float Alpha)
812{

Callers 2

RenderMethod · 0.80

Calls 12

GraphicsFunction · 0.85
TextRenderFunction · 0.85
IsTeleTileNumberUsedAnyFunction · 0.85
str_formatFunction · 0.85
GetScreenMethod · 0.80
ScreenWidthMethod · 0.80
ScreenHeightMethod · 0.80
TextColorMethod · 0.80
TextWidthMethod · 0.80
TextMethod · 0.80
DefaultTextColorMethod · 0.80
MapScreenMethod · 0.45

Tested by

no test coverage detected