4
\$\begingroup\$

I'm currently working on moving some Android-ndk code to the iPhone.

From looking at some samples it seems that the main loop is handled for you and all you've got to do is override the render method on the view to handle the rendering. Then add a selector to handle the update methods. The render method itself looks like it's attached to the windows refresh.

But in android I've got my own game loop that controls the rendering and updates using C++ time.h. Is it possible to implement the same here bypassing Apple's loop? I'd really like the keep the structures of the code similar.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Short answer is no, although you are allowed to use pthreads for all your dirty work I discourage you from doing it just because of multithreading issues that can occur.

Unfortunately all mobile platforms have constraints related to the fact that all the things must be correctly paused and resumed in any moment so it's better to rely on GCD of iOS without wanting to go too much beyond edges (I personally had big troubles with similar issues).

In any case I don't see why you should have to change so much code, you should be able to encapsulate your update functions easily so that your custom scheduler manages them in Android while on iOS you let the OS call them through callbacks. You shouldn't need to change almost anything.

\$\endgroup\$
1
  • \$\begingroup\$ Hi Jack, yes the changes I'll have to make aren't exactly big, but I was hoping to keep the code as similar as possible. But if it's going to be that much more complex, then I think it's better to use the structure provided and modify my code to work on both. thanks! \$\endgroup\$
    – kkan
    Apr 2, 2012 at 6:07
1
\$\begingroup\$

I don't have any serious iOS experience, but this article looks like it might be useful to you. It's basic around using CADisplayLink's ability to help you synchronize your code with the screen's refresh rate.

Like Jack said, the answer seems to be no. Write the system once for both systems and recycle it.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the link! I'm going to modify the code so that it can sit in a happy place for both. \$\endgroup\$
    – kkan
    Apr 2, 2012 at 6:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .