MCPcopy Create free account
hub / github.com/EasyRPG/Player / GenerateAutotiles

Method GenerateAutotiles

src/tilemap_layer.cpp:634–670  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

632}
633
634BitmapRef 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
672void TilemapLayer::SetChipset(BitmapRef const& nchipset) {
673 chipset = nchipset;

Callers

nothing calls this directly

Calls 3

BlitFastMethod · 0.80
CheckPixelsMethod · 0.80
ClearMethod · 0.45

Tested by

no test coverage detected