-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Dose pixi.js can provide a async parallel loader ? #4653
Comments
PixiJS uses one of our core contributor pet project https://github.com/englercj/resource-loader/ Lets look in the sources: https://github.com/englercj/resource-loader/blob/master/src/Loader.js#L20 https://github.com/englercj/resource-loader/blob/master/src/Loader.js#L446 Ok, lets look in docs, may be pixi didnt include docs for that thing because its in another module: http://pixijs.download/dev/docs/PIXI.loaders.Loader.html , here it is, concurrency. Anyway, there are many parts of pixi that can be done better for specific project and I encourage people to use their own implementations when its possible, that suit their project. I bless you for using custom loader, please make it into a plugin and we'll reference it in plugins list. |
Not sure where you learned this, it absolutely can (and does) load resources in parallel. Your wrapper around resource loader just adds a second async queue on top of the one already used inside resource loader. It even has a constructor param to configure how many resources to load concurrently at a time.
You can catch the error, but you don't need to. The point of that error is to tell you are using the loader incorrectly. What you should do for caching is store resources somewhere outside the loader and use a If you plan to use a loader instance multiple times you must call |
but if you use follow code to load resources : pixi.loader.add("/api/static/1.png")
.load(() => {
console.log("/api/static/1.png");
});
pixi.loader.add("/api/static/2.png")
.load(() => {
console.log("/api/static/2.png");
});
pixi.loader.add("/api/static/3.png")
.load(() => {
console.log("/api/static/3.png");
}); it will case :
and i get the reason from where #4100 , the loader cannot parallel load it on root resources. anyway, thanks your contribute. |
@ivanpopelyshev thank you~ |
There are docs about renderer plugins, but for everything else the rule is "do whatever you want, give users JS file that to be included after vanilla pixi.js file". Pixi is built with classes, there are no hidden variables in hidden contexts. |
@ivanpopelyshev thank you~ |
@Lyoko-Jeremie you are using the loader incorrectly. The correct usage is to add all of the resources you want to load, then you call the load() function. Currently, you are calling load after every add. |
@themoonrat but in my case, which resources need load cannot know before it need to load. |
@Lyoko-Jeremie You can abuse dependant resource mechanism. Make a resource that never actually loads (middleware runs forever), add children to it. Spine loader waits for two extra child resources to load: https://github.com/pixijs/pixi-spine/blob/master/src/loaders.ts#L7 , you can make a middleware that waits forever. |
As another option, you can take resource and queue from resource-loader, but make your own Loader class that stores resources differently. |
@ivanpopelyshev how to make a resource that never acutally loads ? |
If you need a custom loader for your game - you have to code it yourself. Its better if you salvage parts that are ok or hack existing code to save the time, but for that you have to learn all the code from 1) resource-loader repo 2) all pixi middlewares 3) advanced middlewares (Spine). I can answer your questions after you spend some hours on studying all that code. Alternatively, you can look how |
@ivanpopelyshev I like to do that, but maybe no time give me to do it. |
As an idea for others having this issue, one option could be to have a pool of resource loaders. If you need a resource loading, but existing loaders are already busy, create a new loader and load the resource that way. If an existing loader had finished, reset it and reuse. Then build your own wrapper class to have a single 'load this asset' function, and it manages the resource loaders in the background |
@themoonrat Good idea !!! |
Yeps
Loaders are very lightweight, so don't worry about having multiple of them. The only thing I'd be aware of, is that the loaders let you set how many assets it can concurrently download, which has a default of 10. If you had 3 loaders, you could be effectively trying to load up to 30 resources at once (tho I'm sure browser would limit lower than that). So maybe you'd create each loader with a lower limit? Or maybe your primary loader has a large limit to get the initial assets down, but your 'in-game-streaming- asset loaders have a lower limit to focus on getting each individual asset down faster. |
@themoonrat thank you for your explain~~ I love you~ |
This seems answered, thank you all for your response. |
I think on the first, I will change my resources loader to pool version, and each loader load one request. This don't need many times. But I still have a question, how to catch the error of Resource with name "…" already exists ? |
Check that resource with name "..." already exists in the same Again, with the nature of your project (BIG MAP), I advice you to change the attitude, meditate for some time and prepare for hundreds of questions like that. It might be that in a few days time you'll start forum search about "how to show big map" and stumble across my countless posts about pixi-tilemap, graphics, meshes, e.t.c. UPD. we are ready to share experience and answer on very difficult questions |
oh~ good forum. thank you~ |
i think my case maybe have some different from a game. so, will have some different question on this, but i will try to find solutions with very hard work. (not knowing whether to cry or to laugh..) |
Yes! That's the spirit!
Is the target mobile or PC? For PC you may use compressed textures (dds + static gzip on server + pixi-compressed-textures). On mobile you'll have serious lag when pixi uploads that into gpu, we dont have progressive uploader, yet. There are issues about it. |
Basically, you need a view 2x of the camera, and when camera touches the edge of "prepared" rectangle you add more objects, and put the old ones into some kind of queue. Right now pixi gc unloads from videomemory any texture that doesnt get rendered in 4 minutes or so. ( |
thanks for your notice~ now it's not on mobile , but who know the Unpredictable future ? in other side. By some reason, many future's user maybe use the older broswer that dont support WebGL. (this reason you may not know if you never develop a program for Chinses people.) |
and I have a Unfragmented Zoom feature, this means Unlimited Zoom. (Doge Face~) |
If you are sure about your target audience , do it for canvas and test it for canvas. If its possible to actually measure audience, if you know your traffic source, you can estimate how many people have webgl enabled in their browser. If its 99.5%, use webgl-only. IF its win-xp and IE10 then.. well... good luck :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi~ everyone.
I'm a new user on pixijs.
I learned that the
pixi.loaders.Loader
cannot load resources when the other are loading. and if one resources are loaded, load twice will throw a exception that cannot be catched.So, Is it able to provide a async parallel loader that can cache the parallel load task then serialize execute it?
follow is my simple and ugly implement on a demo project.
###the resourcesLoader class implement###
follow is the usage:
parallel create load request and serialize load it then async call the promise "then" callback at the resource loaded immediately.
and if a resource be loaded, the "resourcesLoader" will fast resolve that request with not wait.
and if a resource are loading or waiting, the new same request will merge to the loading or waiting task.
check and fast read/load resources
this simple implement on above only can load url now. but i think it can be upgrade to similar to the original loader API.
So, Can pixi.js offical be provide a async parallel loader like this?
The text was updated successfully, but these errors were encountered: