diff --git a/src/sdl/main.c b/src/sdl/main.c
index db74674a752b8fd421099ba56644469937c1ad5f..b3627fc2f92ef66cb54a83e39e228d16380aaac9 100644 (file)
--- a/src/sdl/main.c
+++ b/src/sdl/main.c
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "SDL.h"
+#ifdef __EMSCRIPTEN__
+# include <emscripten.h>
+#endif
+
+#include <SDL/SDL.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h> // srand exit
#define MODE_OPENGL 1
#define MODE_SOFTWARE 2
+static Uint32 ticks;
static int quit = 0;
static SDL_Surface *surf = NULL;
static int mode = MODE_NONE;
if (s != NULL) {
mode = MODE_OPENGL;
surf = s;
+ } else {
+ logo("Y_set_videomode_opengl: error: %s\n", SDL_GetError());
}
}
return s != NULL;
void Y_unset_videomode (void) {
surf = NULL;
mode = MODE_NONE;
+#ifndef __EMSCRIPTEN__
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
+#endif
}
void Y_set_fullscreen (int fullscreen) {
}
}
+static void step (void) {
+ poll_events(&G_keyf);
+ S_updatemusic();
+ Uint32 t = SDL_GetTicks();
+ if (t - ticks > DELAY) {
+ ticks = t;
+ G_act();
+ }
+ R_draw();
+}
+
int main (int argc, char *argv[]) {
char *pw;
- Uint32 t, ticks;
logo("main: initialize SDL\n");
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
logo("main: failed to init SDL: %s\n", SDL_GetError());
R_init();
G_init();
ticks = SDL_GetTicks();
+#ifdef __EMSCRIPTEN__
+ emscripten_set_main_loop(step, 0, 1);
+#else
while (!quit) {
- poll_events(&G_keyf);
- S_updatemusic();
- t = SDL_GetTicks();
- if (t - ticks > DELAY) {
- ticks = t;
- G_act();
- }
- R_draw();
+ step();
}
+#endif
CFG_save();
R_done();
S_donemusic();