| 593 | } |
| 594 | |
| 595 | void 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; |
no test coverage detected