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

Method RenderTilemap

src/game/map/render_map.cpp:595–754  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

593}
594
595void CRenderMap::RenderTilemap(CTile *pTiles, int w, int h, float Scale, ColorRGBA Color, int RenderFlags)
596{
597 float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
598 Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
599
600 // calculate the final pixelsize for the tiles
601 float TilePixelSize = 1024 / 32.0f;
602 float FinalTileSize = Scale / (ScreenX1 - ScreenX0) * Graphics()->ScreenWidth();
603 float FinalTilesetScale = FinalTileSize / TilePixelSize;
604
605 if(Graphics()->HasTextureArraysSupport())
606 Graphics()->QuadsTex3DBegin();
607 else
608 Graphics()->QuadsBegin();
609 Graphics()->SetColor(Color);
610 const bool ColorOpaque = Color.a > 254.0f / 255.0f;
611
612 int StartY = (int)(ScreenY0 / Scale) - 1;
613 int StartX = (int)(ScreenX0 / Scale) - 1;
614 int EndY = (int)(ScreenY1 / Scale) + 1;
615 int EndX = (int)(ScreenX1 / Scale) + 1;
616
617 // adjust the texture shift according to mipmap level
618 float TexSize = 1024.0f;
619 float Frac = (1.25f / TexSize) * (1 / FinalTilesetScale);
620 float Nudge = (0.5f / TexSize) * (1 / FinalTilesetScale);
621
622 for(int y = StartY; y < EndY; y++)
623 {
624 for(int x = StartX; x < EndX; x++)
625 {
626 int mx = x;
627 int my = y;
628
629 if(RenderFlags & TILERENDERFLAG_EXTEND)
630 {
631 if(mx < 0)
632 mx = 0;
633 if(mx >= w)
634 mx = w - 1;
635 if(my < 0)
636 my = 0;
637 if(my >= h)
638 my = h - 1;
639 }
640 else
641 {
642 if(mx < 0)
643 continue; // mx = 0;
644 if(mx >= w)
645 continue; // mx = w-1;
646 if(my < 0)
647 continue; // my = 0;
648 if(my >= h)
649 continue; // my = h-1;
650 }
651
652 int c = mx + my * w;

Callers 2

RenderMethod · 0.80

Calls 13

GraphicsFunction · 0.85
GetScreenMethod · 0.80
ScreenWidthMethod · 0.80
QuadsTex3DBeginMethod · 0.80
QuadsBeginMethod · 0.80
QuadsSetSubsetFreeMethod · 0.80
QuadsTex3DDrawTLMethod · 0.80
QuadsDrawTLMethod · 0.80
QuadsTex3DEndMethod · 0.80
QuadsEndMethod · 0.80
SetColorMethod · 0.45

Tested by

no test coverage detected