Animation while doing computations - any multithreading?

In my simulation game, I need to perform a function that may take several seconds. However, this function interrupts my loading animation and the UI freezes up. Obviously, this is not a desired result, so is there anyway to relegate the computations to a background process to allow the UI to run also? I looked up threading in LUA but all I get is coroutines, which still doesn’t solve my frozen loading animation.

The best you can really do is make a simple classic loading bar. Load your graphics from a table, in a for loop, pause for a few milliseconds inbetween each load to update your loading bar.

Not ideal, but hope this helps

Not really the answer I was hoping for, but I guess it has to do right now. Do you by any chance know if and when Corona will implement multi-threading capabilities? I heard that they were really making a push toward business-oriented apps, and I have to say, mutithreading is necessary for a lot of things

I know it’s not, sorry :frowning:

You would need to ask someone at Corona regarding their multi-threading plans.

AFAIK (may be wrong) Corona won’t actually refresh until you yield. So anything like 

for i = 1, 1000000000000 do next i 

will block all updates (assuming it isn’t optimised out !)  and there is no mechanism for yielding directly. Lua does have coroutines which apparently work in Corona, this may be worth a bit of experimentation.

http://lua-users.org/wiki/CoroutinesTutorial

Finally, the most obvious way is to break your calculation up into chunks and call these sequentially using a timer or something similar. It really depends what you are doing and why ; if you are doing a smaller computation on lots of things it is relatively trivial, but one computation on a huge thing is a bit more challenging :wink:

Coroutines are probably better than multi-tasking which can be an XXXX at the best of times …

The best you can really do is make a simple classic loading bar. Load your graphics from a table, in a for loop, pause for a few milliseconds inbetween each load to update your loading bar.

Not ideal, but hope this helps

Not really the answer I was hoping for, but I guess it has to do right now. Do you by any chance know if and when Corona will implement multi-threading capabilities? I heard that they were really making a push toward business-oriented apps, and I have to say, mutithreading is necessary for a lot of things

I know it’s not, sorry :frowning:

You would need to ask someone at Corona regarding their multi-threading plans.

AFAIK (may be wrong) Corona won’t actually refresh until you yield. So anything like 

for i = 1, 1000000000000 do next i 

will block all updates (assuming it isn’t optimised out !)  and there is no mechanism for yielding directly. Lua does have coroutines which apparently work in Corona, this may be worth a bit of experimentation.

http://lua-users.org/wiki/CoroutinesTutorial

Finally, the most obvious way is to break your calculation up into chunks and call these sequentially using a timer or something similar. It really depends what you are doing and why ; if you are doing a smaller computation on lots of things it is relatively trivial, but one computation on a huge thing is a bit more challenging :wink:

Coroutines are probably better than multi-tasking which can be an XXXX at the best of times …