I've not used SDL, but aren't you grabbing control of the event loop here
in your while(gameRunning) { } loop? Each main loop invocation is
happening in the browser's (single) UI thread. If you don't return control
to the browser (by exiting the one_iter() function) then the browser will
freeze.
Maybe try structuring your code like this:
void oneIter() {
// Stuff currently inside your while() { } block
if (!gameRunning) {
// Stuff currently after your while() { } block, like SDLQuit() and
friends
}
}
int main() {
// Setup code, stuff currently before your while() { } block
emscripten_set_main_loop();
}
Now the oneIter() function will be invoked by the browser in a loop,
yielding back to the browser each loop iteration.
-dave-
On Sunday, April 6, 2014 12:49:51 AM UTC-4, [email protected] wrote:
>
>
> <https://lh3.googleusercontent.com/-FrjglpaDPRs/U0DZZ1cTn9I/AAAAAAAAAAQ/29x4jM-0S_s/s1600/unresponsive%2Bscript3.JPG>
> I'm currently trying to get this tutorial I've found
> <http://www.aaroncox.net/tutorials/2dtutorials/sdlsprites.html>on SDL to
> work with Emscripten but I think I might be running into problems with the
> browser's event model:
>
> Here's the code:
>
> #include <SDL/SDL.h>
>> #include <emscripten.h>
>>
>> const int WINDOW_WIDTH = 640;
>> const int WINDOW_HEIGHT = 480;
>> const char* WINDOW_TITLE = "SDL Start";
>>
>> void one_iter() {
>> SDL_Init( SDL_INIT_VIDEO );
>>
>> SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH,
>> WINDOW_HEIGHT, 0,
>> SDL_HWSURFACE | SDL_DOUBLEBUF );
>> SDL_WM_SetCaption( WINDOW_TITLE, 0 );
>>
>> SDL_Surface* bitmap = SDL_LoadBMP("bat.bmp");
>>
>> // Part of the bitmap that we want to draw
>> SDL_Rect source;
>> source.x = 24;
>> source.y = 63;
>> source.w = 65;
>> source.h = 44;
>>
>> // Part of the screen we want to draw the sprite to
>> SDL_Rect destination;
>> destination.x = 100;
>> destination.y = 100;
>> destination.w = 65;
>> destination.h = 44;
>>
>> SDL_Event event;
>> bool gameRunning = true;
>>
>> while (gameRunning)
>> {
>> if (SDL_PollEvent(&event))
>> {
>> if (event.type == SDL_QUIT)
>> {
>> gameRunning = false;
>> }
>> }
>>
>> SDL_BlitSurface(bitmap, &source, screen, &destination);
>>
>> SDL_Flip(screen);
>> }
>>
>> SDL_FreeSurface(bitmap);
>>
>> SDL_Quit();
>> }
>>
>> int main(int argc, char **argv)
>> {
>> emscripten_set_main_loop(one_iter, 60, 1);
>>
>> return 0;
>> }
>>
>
>
> I've read the Wiki on emscripten browser
> environment<https://github.com/kripken/emscripten/wiki/Emscripten-browser-environment>so
> I figured I had to use *emscripten_set_main_loop
> *to make SDL_Quit() work and give control back to the browser and keep it
> from freaking out. But as you can see it didn't work. Can anyone point to
> me what I'm doing wrong? Any guidance here would be appreciated.
>
--
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.