non-blocking functions

Hi, I'm developing a game which requires a one of piece of precalculation. This means I will need to execute a function once (per level) which contains a good deal of processing that will block the cpu for a few seconds. I would rather have a loading bar here than block the phone.

Is there anyway of setting a function to run in the background, so frame updates still take place? I don't think Lua coroutines can help here, as there still won't be frame updates if my function blocks for a while.

The only other method would be to divide the precalculation into small blocks, and call them over a period of time. This is obviously less elegant code-wise and I was just wondering if there is any other solution?

Thanks!

You need to modularise it for faster response. Just curious what are you trying to do?

you will have to do your calculations as a function and call it with parameters and update the frames, then call it again and so on.

cheers,

?:)

Coroutines might actually help solve your problem depending if your blocking call is actually not a single function call (like audio.loadSound()), but comprised of many smaller function calls. In that case, you just sprinkle yields throughout your function, and call resume in a callback like from timer.performWithDelay or enterFrame.

views:1308 update:2011/10/17 21:25:02
corona forums © 2003-2011