natiny_resource_load_async
void natiny_resource_load_async(
const char* path,
natiny_resource_async_cb callback,
void* userdata
);
Asynchronously loads a resource out of the mounted folders, or from disk (the network on web) when no mount holds it. The callback fires when loading completes.
Parameters
| Name | Type | Description |
|---|---|---|
path |
const char* |
Name of the file inside a mounted folder, such as "textures/hero.png" |
callback |
natiny_resource_async_cb |
Called when loading completes |
userdata |
void* |
User pointer passed to the callback |
Callback
The callback receives:
- success - 1 on success, 0 on failure.
- data - pointer to loaded bytes (valid only during callback).
- data_len - number of loaded bytes.
- userdata - forwarded user pointer.
Example
void on_loaded(int success, const uint8_t* data, uint32_t data_len, void* ud) {
if (!success || !data || data_len == 0) {
return;
}
NatinyResource res = natiny_resource_from_data(data, data_len);
/* use res */
natiny_resource_destroy(res);
}
void start_load(void) {
natiny_resource_load_async("textures/hero.png", on_loaded, NULL);
}
Notes
- On the web this is the call that pays off: packs fetched here are kept in
the browser's IndexedDB under a key carrying their hash, so a returning
player downloads nothing that has not changed. The synchronous
natiny_resource_load()cannot reach that store and goes to the network.