void TilemapLayer::SetMapData(const std::vector<short>& nmap_data) { if (map_data != nmap_data) { // Create the tiles data cache CreateTileCache(nmap_data); if (layer == 0) { autotiles_ab_map.clear(); autotiles_d_map.clear(); autotiles_ab_next = 0; autotiles_d_next = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (data_cache[x][y].ID < BLOCK_C) { // If blocks A and B GenerateAutotileAB(data_cache[x][y].ID, 0); GenerateAutotileAB(data_cache[x][y].ID, 1); GenerateAutotileAB(data_cache[x][y].ID, 2); } else if (data_cache[x][y].ID >= BLOCK_D && data_cache[x][y].ID < BLOCK_E) { // If block D GenerateAutotileD(data_cache[x][y].ID); } } } autotiles_ab_screen = GenerateAutotiles(autotiles_ab_next, autotiles_ab_map); autotiles_d_screen = GenerateAutotiles(autotiles_d_next, autotiles_d_map); } } map_data = nmap_data; }
void TilemapLayer::SetMapData(std::vector<short> nmap_data) { if (map_data != nmap_data) { // Create the tiles data cache data_cache.resize(width); for (int x = 0; x < width; x++) { data_cache[x].resize(height); for (int y = 0; y < height; y++) { TileData tile; // Get the tile ID tile.ID = nmap_data[x + y * width]; tile.z = 0; // Calculate the tile Z if (!passable.empty()) { if (tile.ID >= BLOCK_F) { if ((passable[substitutions[tile.ID - BLOCK_F]] & Passable::Above) != 0) tile.z = 32; } else if (tile.ID >= BLOCK_E) { if ((passable[substitutions[tile.ID - BLOCK_E + 18]] & Passable::Above) != 0) tile.z = 32; } else if (tile.ID >= BLOCK_D) { if ((passable[(tile.ID - BLOCK_D) / 50 + 6] & (Passable::Wall | Passable::Above)) != 0) tile.z = 32; } else if (tile.ID >= BLOCK_C) { if ((passable[(tile.ID - BLOCK_C) / 50 + 3] & Passable::Above) != 0) tile.z = 32; } else { if ((passable[tile.ID / 1000] & Passable::Above) != 0) tile.z = 32; } } data_cache[x][y] = tile; } } if (layer == 0) { autotiles_ab_map.clear(); autotiles_d_map.clear(); autotiles_ab_next = 0; autotiles_d_next = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (data_cache[x][y].ID < BLOCK_C) { // If blocks A and B GenerateAutotileAB(data_cache[x][y].ID, 0); GenerateAutotileAB(data_cache[x][y].ID, 1); GenerateAutotileAB(data_cache[x][y].ID, 2); } else if (data_cache[x][y].ID >= BLOCK_D && data_cache[x][y].ID < BLOCK_E) { // If block D GenerateAutotileD(data_cache[x][y].ID); } } } autotiles_ab_screen = GenerateAutotiles(autotiles_ab_next, autotiles_ab_map); autotiles_d_screen = GenerateAutotiles(autotiles_d_next, autotiles_d_map); } } map_data = nmap_data; }