libAsset contains code for loading assets, like models, sounds etc, in a background thread without having you to fear about thread safety and such things.
The idea comes from this feature request from Jibb and his statement that A8 lacks of good asset preloading. The code has to purposes;
1) It saves you time waiting for this feature in A8.
2) It shows that one can easily build a bit more complex stuff in A8 and that it really isn't that limited as some people want it to be.


Usually you only need to call the wrapper functions for creating things. They all start with "la_" and then follows the usual Gamestudio name. So ent_create with background loading functionality would be la_ent_create.
Likewise, snd_create is la_snd_create.

If you want to load other assets or get some more info about the assets state, you can either use the high level int la_checkFile(STRING *file); function which returns 0 if the asset is currently being loaded, 1 if its loaded and -1 and -2 if there was a failure.
If this isn't enough for you, you have to dig a bit deeper, getting the la_asset struct from la_asset *la_assetForFile(char *file, char *filepath); and polling the la_asset struct repeatedly. You then also have to care about locking the loader, but usually, you never ever have to do this!

When you want the loader to reload a model, you first have to remove it. This is done via void la_assetRemove(char *file);. This function also takes care about assets that are currently being loaded in the background, so always use this function to remove assets!

The next useful function is int la_assetRemoveAll();. You MUST call this before calling add_new() because the loader works internally with add_buffer().
The drawback of this function is that it might does nothing when there are models loaded currently in the background. The function will then return 0, so you have to call it multiple times until it returns 0.
The simplified way is la_clear(), this will call la_assetRemoveAll() until everything is removed.


And finally, here is the download link with demo:
http://cl.ly/6wN1


Compatibility notes: Should work with A7 and A8, tested with A8.03 free.

Last edited by JustSid; 05/21/11 09:55. Reason: New version

Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com