Best practice for Loading/Unloading hugh amount of images

Started by
3 comments, last by vlj 8 years ago

Hey Guys,

currently I struggle a little bit around with the question about some kind of best practice for loading / caching / unloading a hugh amount of assets for my game.

Imagine you have 10 different areas with 300 assets each. You can switch to each eary via a simple mouseclick. For example I could load from Area 1 all assets, then switch to Area 2 and load all assets there and unload all assets from area 1 but this sounds not really performant for me because when I unload all assets of the previous area then I have to load them again maybe after some seconds. Keeping them in the memory is also not a good way.

How can I handle that problem in a good performant way?

I hope you understood my topic and I'm looking forward for some tips, tricks or some techniques :)

Cheers,

NoAim

Advertisement

You could do something like this, I suppose:

Only load assets when they're needed instead of loading all assets for an entire area, and keep track of when they were last used. Then, when you need to load in a new asset and there's no more room, unload the asset which haven't been used the longest..

.:vinterberg:.

If the footprint of your assets( whatever metric you want to consider, memory, cpu usage etc. ) is such that its greater than the available resource to use those assets, then there is no way around on demand loading. You are worried about something that will most likely be inevitable given the approach you mention. I would recommend looking at potential ways to optimize the said use case instead of worrying. Seeing that you have not collected any metrics to gauge the performance, all of this is speculative. However, you seem to have a couple ideas, in mind, so I would recommend doing a proof of concept for each approach that you are thinking of, and then measure how they stack up against each other and also against your goal.

Typically you pre-process the textures and level assets using a custom tool that fits your own requirements.

Opening large numbers of files carries a performance overhead that is substantial when you start to get into the 100's of files range, so packaging them into a single file is a good option.

Then you can also start doing other tricks to reduce loading time and help memory management,

For example set a maximum size for a texture in the main package. So if you have a 4K texture, only load in the mipmaps below 128 by 128. Then stream in the other mipmaps in the background after the level has launched on a priority basis.

This is fairly easy to do once you get your head around it. You can see this in a lot of engine when an object will look blurred for a second when you first see it.

But it all depends on your own application.

Give us more details and we may be able to give you more pointers

Is there a "natural" order in the area? For instance if you are in area 0 is it possible to access any area or only area 1?

In the later case you may store several area, the one you're in and the ones immediately accessible from it. When you change the area in focus you can load and unload areas while still being able to render something in the meantime (since the area in focus was already loaded in memory)

This topic is closed to new replies.

Advertisement