Let's think platform-agnostic: I want to load some graphical resources while the rest of the game is running.
In principle, I can load the actual files on a separate thread, or using async I/O. But with graphical objects, I will have to upload them to the GPU, and that can (usually) only be done on the main thread.
I can change my game loop to look something like this:
while true do update() for each pending resource do load resource to gpu end draw() end
while having a separate thread load resources from disk to RAM.
However, if there are many big resources to load, this could cause me to miss a frame deadline and eventually get dropped frames. So I can change the loop to this:
while true do update() if there are pending resources then load one resource to gpu remove that resource from the pending list end draw() end
Effectively loading only one resource per frame. However, if there are many small resources to load, loading all of them will take many frames, and there will be a lot of wasted time.
Optimally, I would like to time my loading in the following manner:
while true do time_start = get_time() update() while there are pending resources then current_time = get_time() if (current_time - time_start) + time_to_load(resource) >= 1/60 then break load one resource to gpu remove that resource from the pending list end draw() end
This way, I would only load a resource if I can do it within the time I have for that frame. Unfortunately, this requires a way to estimate the amount of time it takes to load a given resource, and as far as I know, there are usually no ways to do this.
What am I missing here? How do many games get to load all their stuff completely asynchronous and without dropped frames or extremely long loading times?