| 632 | } |
| 633 | |
| 634 | BitmapRef TilemapLayer::GenerateAutotiles(int count, const std::unordered_map<uint32_t, TileXY>& map) { |
| 635 | int rows = (count + TILES_PER_ROW - 1) / TILES_PER_ROW; |
| 636 | BitmapRef tiles = Bitmap::Create(TILES_PER_ROW * TILE_SIZE, rows * TILE_SIZE); |
| 637 | tiles->Clear(); |
| 638 | Rect rect(0, 0, TILE_SIZE/2, TILE_SIZE/2); |
| 639 | |
| 640 | for (auto& p: map) { |
| 641 | uint32_t quarters_hash = p.first; |
| 642 | TileXY dst = p.second; |
| 643 | |
| 644 | // unpack the quarters data |
| 645 | for (int j = 0; j < 2; j++) { |
| 646 | for (int i = 0; i < 2; i++) { |
| 647 | constexpr int mask = ~(0xFu << 28); |
| 648 | |
| 649 | int x = quarters_hash >> 28; |
| 650 | quarters_hash &= mask; |
| 651 | quarters_hash <<= 4; |
| 652 | |
| 653 | int y = quarters_hash >> 28; |
| 654 | quarters_hash &= mask; |
| 655 | quarters_hash <<= 4; |
| 656 | |
| 657 | rect.x = (x * 2 + i) * (TILE_SIZE/2); |
| 658 | rect.y = (y * 2 + j) * (TILE_SIZE/2); |
| 659 | |
| 660 | tiles->BlitFast((dst.x * 2 + i) * (TILE_SIZE / 2), (dst.y * 2 + j) * (TILE_SIZE / 2), *chipset, rect, 255); |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | if (rows > 0) { |
| 666 | tiles->CheckPixels(Bitmap::Flag_Chipset | Bitmap::Flag_ReadOnly); |
| 667 | } |
| 668 | |
| 669 | return tiles; |
| 670 | } |
| 671 | |
| 672 | void TilemapLayer::SetChipset(BitmapRef const& nchipset) { |
| 673 | chipset = nchipset; |
nothing calls this directly
no test coverage detected