Thank you everyone for helping me understand how this stuff works. I think 
that a large source of the confusion is the fact that most C++ examples 
aren't intended for event driven platforms that don't let programs control 
the main loop. I still have a lot to learn about this since it's 
fundamental to every program I'll ever make.

On Tuesday, April 8, 2014 1:20:52 AM UTC-5, jj wrote:
>
> Oh hmm, I did not know there actually was some logic implemented behind 
> SDL_Quit - I always though it was ignored, but apparently is not.
>
>
> 2014-04-08 8:48 GMT+03:00 <[email protected] <javascript:>>:
>  
>
>> Also, I'm curious if anyone has found a way to make C++ infinite main 
>> loops asynchronous that work across all even driven platforms? (eg. 
>> Emscripten, Flash, pNaCl, iOS, Android)
>>
>
> Sure, it should not be very hard, but it will naturally look different on 
> each platform, since the platform provides a platform-specific way to hook 
> into a render loop. A decent way to entrypoint into your own code is to 
> make your own tick() function that runs a single iteration of the 
> update+render loop. Then use whatever platform-specific way there is to 
> connect that tick() function to the system main loop. On Emscripten that is 
> emscripten_set_main_loop. On Flash it would be calling tick() from Stage3D 
> Context ENTER_FRAME event, something like 
> stageContext->addEventListener(flash::events::Event::ENTER_FRAME, 
> Function::_new(enterFrameHandler, NULL));
> On iOS, you'll create a CADisplayLink object and call tick() from its 
> update function, see listing 4-1 "Creating and starting a display link" in 
>   
> http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/WorkingwithEAGLContexts/WorkingwithEAGLContexts.html
> On Android, if you're using NDK, you can create your own main thread that 
> spins the render loop (see e.g. the native_app_glue example in NDK) and 
> periodically calls tick().
>
> In my setup, I do something slightly more complex, but effectively the 
> same. I further break down the tick() function:
>
> void tick()
> {
>    float deltaTime = tick() - lastStoredTick;
>    update(deltaTime);
>    render();
> }
>
> and the basic functions that the application implements are those two: 
> update() advances the app simulation by the given amount of time, and 
> render() renders the current state of the simulation. The decoupling of 
> these two is because occasionally they don't go in lockstep. For example, 
> if the application is minimized and the screen is not visible, I may want 
> to update() but never render(), and on some platforms, I might want to 
> render() multiple times between a single update(), e.g. on Windows when you 
> have a windowed mode screen and drag from the corner of a window, you might 
> want to pause simulation for that duration and only repaint so that window 
> dragging is responsive and updates smoothly. Ymmv for these though.
>
>    Jukka
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to