Asynchronous loading best practice
BlitzMax Forums/BlitzMax Programming/Asynchronous loading best practice
| ||
Just wondering if anyone can suggest the best way of implementing asynchronous loading into a Blitzmax app. I don't intend to be streaming environments into a game as it is played, rather just display animated screens whilst the level resources (xml, images and sounds) are loaded. To me the simple option seems like I should display the animation in the main app thread and wait for a separate thread to load in the resources. Is this the standard approach in Blitzmax? Alternatively, would it better to implement an incremental loading class using bankstreams (such as Beaker's 'nibbler' in the code archives). I'm sure each method has its pros and cons but I thought I'd see what the community opinion was. |
| ||
I don't know about the best way, but this is one way... I seem to recall we found loading images directly in the thread like this was fine, but this came from an older example that loaded pixmaps in the thread to play it safe, then called LoadImage on each afterwards. Pretty sure that's not actually necessary. The "nibbler" thing is very clever though -- hadn't seen that before: Media file 'Nibbler' [bmax] Last edited 2012 |
| ||
I believe I have read that it is not safe to do rendering (or messing with the video card) on any thread but the main. I'd suggest you do as BlitzSupport's example does, but instead of loading the images, just load them as pixmaps (they are totally graphics API independent), and then feed them into LoadImage after everything is in memory and the loading thread as has finished. Last edited 2012 |
| ||
load them as pixmaps (they are totally graphics API independent), and then feed them into LoadImage after everything is in memory and the loading thread as has finished @kfprimm: That's what I used to do (see here), but it was pointed out elsewhere (by Gfk I believe) that LoadImage doesn't actually touch the graphics card -- you can confirm this by looking at "max2d.mod/image.bmx". It's only when you actually call DrawImage that it's uploaded to the graphics card, via TImage.Frame (). The example above only calls DrawImage in the main thread; using LoadImage in the child thread is fine as long as you don't try to draw. |
| ||
Thanks for the replies. Seems like I'll go with the threaded option. I was aware that graphics could only be drawn on the main thread, but it is nice to know that it is safe to load timages on the secondary one! |