bartbes wrote:kikito wrote:Is that really a blocking call that benefits from loading in another thread?
Not really. I mean it blocks, but it really only allocates some memory, and therefore takes barely any time.
I already figured that much on my
cry for help in the support forum. I just have been a bit busy this week to post much or do any work on love-loader. But thanks for confirming.
bartbes wrote:As for the send/receive => set/get change, in the code I've written that's supposed to be portable I define local functions that either call send or set depending on the love version, and then use that. (Same goes for receive and get, of course.)
Makes sense. I don't like having to test for the concrete love version though. Seems a bit brittle. How about testing whether the thread has a method or not?
Code: Select all
local function set(thread, key, value)
local f = thread.send or thread.set
return f(thread, key, value)
end
And same with receive/get. Does it look right to you?
bartbes wrote:EDIT: Something I thought of while looking at the code, perhaps you could implement a function that waits for the thread to finish, if it is not? It's something I've implemented in the past, where if someone was to skip the intro, it would just start loading all (remaining) resources in a blocking way.
That goes pretty much against what I wanted to accomplish. The whole idea is not blocking the main thread while loading resources. But there is an alternative. The command that "starts the loading thread" is loader.start(finishCallback, loadedResourceCallback). They are both optional. But finishcallback is very recommended (in fact, in the initial version of love-loader it was mandatory).
One can check that everything has been loaded by setting a boolean, or changing the game state from "loading" to "finishedLoading" in the finishCallback. While it is loading, you can play an animation of a dancing fish, or what have you, and it will play without hiccups.
A much worse alternative, but one that also works, would be comparing love.loadedCount with love.resourceCount on each update cycle. When love.loadedCount == love.resourceCount, all files have been loaded. But your code will be much cleaner if you just use finishCallback to perform the action of that if.
My point is - if you want to block the main thread while loading, it's better not using love-loader at all. Its core idea is avoiding blocking on the main thread.
The second loader.start parameter is a callback called every time an individual resource is finished loading. It receives some parameters, like what kind of resource was it, what was its name, and where it is stored. If you open the demo in the console, you will see that loadedResourceCallback prints lots of stuff on it.
Regarding the loading of imageData/soundData: I'm pretty sure that if I'm to support those, soundDatas will only be "supported" while being created from a path or a decoder. I'm also investigating whether it would be possible to get a soundData or imageData from a source or image
in an issue. Will update this when I know more.