Here’s a prototype of the background loader algorithm:
int N = number of image;
int cur = pointer to current image;
bool going_forward = current direction
int max_memory = maximum memory for luce
int cur_memory = current used memory
bool async_load = do async/sync load
flag_loadable_neighbours(cur_memory, max_memory);
next=cur;
prev=cur;
for(i=0;i<N/2;i++)
{
async_load=!i;
if(!ThumbIsLoaded(next) && ThumbIsLoadable(next) && !ThumbIsLoading(next))
LoadThumb(next,async_load);
if(!ScreenIsLoaded(next) && ScreenIsLoadable(next) && !ScreenIsLoading(next))
LoadScreen(next,async_load);
if(!ThumbIsLoaded(prev) && ThumbIsLoadable(prev) && !ThumbIsLoading(prev))
LoadThumb(next,async_load);
if(NeedToBreak())
break; //usually triggered by a keypress
if(going_forward())
next=cur->next; prev=cur->prev;
else
next=cur->prev; prev=cur->next;
}