| 21 | } |
| 22 | |
| 23 | void TMXDef::loadAsync(String filename, const std::function<void(bool)>& callback) { |
| 24 | this->retain(); |
| 25 | auto file = filename.toString(); |
| 26 | SharedContent.getThread()->run([file, this]() { |
| 27 | return Values::alloc(this->_map.loadUnsafe(file)); |
| 28 | }, |
| 29 | [callback, this](Own<Values> values) { |
| 30 | bool done = false; |
| 31 | values->get(done); |
| 32 | if (!done) { |
| 33 | callback(false); |
| 34 | return; |
| 35 | } |
| 36 | std::unordered_set<std::string> images; |
| 37 | for (const auto& tileset : this->_map.getTilesets()) { |
| 38 | images.insert(tileset.getImagePath()); |
| 39 | } |
| 40 | auto imageCopies = std::make_shared<std::unordered_set<std::string>>(images); |
| 41 | for (const auto& image : images) { |
| 42 | SharedTextureCache.loadAsync(image, [image, imageCopies, callback](Texture2D* tex) { |
| 43 | if (imageCopies->empty()) { |
| 44 | return; |
| 45 | } |
| 46 | if (tex) { |
| 47 | imageCopies->erase(image); |
| 48 | } else { |
| 49 | imageCopies->clear(); |
| 50 | callback(false); |
| 51 | return; |
| 52 | } |
| 53 | if (imageCopies->empty()) { |
| 54 | callback(true); |
| 55 | } |
| 56 | }); |
| 57 | } |
| 58 | this->release(); |
| 59 | }); |
| 60 | } |
| 61 | |
| 62 | /* TMXCache */ |
| 63 |
nothing calls this directly
no test coverage detected