-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResourceLoader.add(...) does not operate like a queue #155
Comments
I believe the way it works right now, where you can only You can re-use a loader that has finished, by first calling In your case though, you want to add things on an ad-hoc basis. In this scenario, I'd recommend to create your own small 'getLoader' functionality that manages an internal pool of loaders. If you have a free loader, just grab it and use. If all loaders are busy, create a new one, add items to it, and start it. Once a loader has finished it's queue, call So I agree that a bit of the wording on the docs could make things a little clearer, but in terms of behaviour being changed, that's up to the project maintainer! :) |
@themoonrat thanks for the response. It does raise several other questions however - i.e
From my estimation, It kinda seems like the current implementation is trying to mash a different type of solution into the design language of another, like trying to fit a full Tree implementation into a Treenode, hence some of the issues encountered. Would it make sense to have 2 distinct different types of objects? I think this separation of concerns will serve far more use cases effortlessly. |
Hmmm, you say 'if the design sensibilities of the loader is to only load one thing and be reset or discarded' but you can Might just be the wording, or semantics, but you make it sound like it's 1 loader per 1 file! Whereas its one loader for a batch of files. You want to load a 2nd batch of files and the 1st hasn't finished yet? Create a 2nd loader! As well as the 'pool' of loaders, I'd recommend setting each loaders callback to check to see if there any other loaders with stuff in their queue, and if so, start that load going. Depends how many simultaneous queues you think might be going, I guess :) Whether you only want 1 loader going at once, or happy to have some in parallel. There definitely is a case for a new wrapper as you describe that handles these multiple loaders. Of course, then you may come across 'how do I handle loading percentage across multiple loaders' and some of the same edge cases that this library isn't trying to avoid in the first place.... but if it concentrated on a simple promise based API to keep chucking files in, and getting back when they've loaded, it'd definitely help. You're not the first person to ask about re-using of loaders :) |
Like @themoonrat mentioned, the purpose of not having a single loader object handle getting more loads while already in progress is to avoid the issues with progress that come from doing that. There is one exception to this rule which is child resources. Generally this comes from the post-processing of a resource that spawns a load for another resource. For example, downloading a JSON texture sheet file which references an image to go fetch. In these cases we can divide the progress values assigned to the parent resources amongst the children to maintain correct progress values. Adding child resources during loading is allowed, as long as the parent hasn't yet completed (finished all middleware).
This is basically how the loader works. You call The design philosophy here is that one loader is one load operation. That operation can be for 1 files, or it can be for 100 files. The idea is that when you hit a loading screen, you add all the files you want to load to the loader, kick it off, display the progress on your loading screen, and then when it completes move past the loading screen.
This project is a simple, lean, truly one-shot resource loader whereby all it does is take a path and returns a loaded resource. It just can do more than one at a time, because often you have a list of things to load not just one. Like it says in the readme:
The primary use-cases I've used this for in the past are:
In both these cases the loader is a low-level piece behind my resource system that managed data lifetime and streaming in the game. This project is not meant to be a replacement for that system. |
Hello,
According to the docs, the purpose of the loader.add(...) function is to enqueue something for loading.
What is the point of "enqueueing" something when doing so multiple times throws an error like
Error: Cannot add resources while the loader is running.
. Why should the loader being in an active processing state stop enqueuement?The word enqueue suggests Buffering the work items until the processor is ready, after which the processor pops (i.e array.unshift) the next work item off the list, and on it goes.
My use case is that I am using Pixi.js, which uses this library, to load textures somewhat adhoc as needed.
Could you shed more light on this "Error: Cannot add resources while the loader is running." error? I'd like to learn why it was implemented this way so I know whether to make a PR to improve on this behavior.
Thanks for the tool.
The text was updated successfully, but these errors were encountered: