MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / loadAsync

Method loadAsync

Source/Cache/TextureCache.cpp:190–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190void TextureCache::loadAsync(String filename, const std::function<void(Texture2D*)>& handler) {
191 std::string fullPath = SharedContent.getFullPath(filename);
192 auto it = _textures.find(fullPath);
193 if (it != _textures.end()) {
194 handler(it->second);
195 return;
196 }
197 std::string file(filename.toString());
198 SharedContent.loadAsyncUnsafe(fullPath, [this, file, handler](uint8_t* data, int64_t size) {
199 if (!data) {
200 Error("failed to read file data from \"{}\".", file);
201 handler(nullptr);
202 return;
203 }
204 SharedAsyncThread.run(
205 [this, data, size]() {
206 bimg::ImageContainer* imageContainer = bimg::imageParse(&_allocator, data, s_cast<uint32_t>(size));
207 delete[] data;
208 return Values::alloc(imageContainer);
209 },
210 [this, file, handler](Own<Values> result) {
211 bimg::ImageContainer* imageContainer;
212 result->get(imageContainer);
213 if (Texture2D* texture = createTexture(&_allocator, imageContainer, file)) {
214 std::string fullPath = SharedContent.getFullPath(file);
215 _textures[fullPath] = texture;
216 handler(texture);
217 } else {
218 Error("texture format \"{}\" is not supported for \"{}\".", Path::getExt(file), file);
219 handler(nullptr);
220 }
221 });
222 });
223}
224
225bool TextureCache::unload(Texture2D* texture) {
226 for (auto it = _textures.begin(); it != _textures.end(); ++it) {

Callers

nothing calls this directly

Calls 12

handlerFunction · 0.85
getFullPathMethod · 0.80
loadAsyncUnsafeMethod · 0.80
createTextureFunction · 0.70
findMethod · 0.65
toStringMethod · 0.65
runMethod · 0.65
getMethod · 0.65
ErrorEnum · 0.50
imageParseFunction · 0.50
allocFunction · 0.50
endMethod · 0.45

Tested by

no test coverage detected