X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fsdl%2Fmain.c;h=36b32798913dd64aa89f179ecec0dee2a9c80a8e;hb=7b2f2285593458477b8185e62099d61975faf7d4;hp=2cc83f6409b848e56fc3d92ee72ed87142dbc610;hpb=adac70590f44505dbc9e99a05e8c5bfde8649dd6;p=flatwaifu.git diff --git a/src/sdl/main.c b/src/sdl/main.c index 2cc83f6..36b3279 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -20,11 +20,16 @@ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "SDL.h" +#ifdef __EMSCRIPTEN__ +# include +#endif + +#include #include #include #include // srand exit #include // strcasecmp +#include #include #include "system.h" #include "input.h" @@ -46,9 +51,11 @@ #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; +static int text_input; /* --- error.h --- */ @@ -89,8 +96,6 @@ void ERR_fatal (char *s, ...) { } void ERR_quit (void) { - puts("Спасибо за то, что вы играли в Операцию \"Смятка\"!"); - //F_loadres(F_getresid("ENDOOM"),p,0,4000); quit = 1; } @@ -115,6 +120,8 @@ int Y_set_videomode_opengl (int w, int h, int fullscreen) { if (s != NULL) { mode = MODE_OPENGL; surf = s; + } else { + logo("Y_set_videomode_opengl: error: %s\n", SDL_GetError()); } } return s != NULL; @@ -161,8 +168,10 @@ int Y_videomode_setted (void) { 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) { @@ -225,6 +234,14 @@ void Y_repaint (void) { SDL_Flip(surf); } +void Y_enable_text_input (void) { + text_input = 1; +} + +void Y_disable_text_input (void) { + text_input = 0; +} + /* --- main --- */ static int sdl_to_key (int code) { @@ -337,8 +354,8 @@ static int sdl_to_key (int code) { } } -static void poll_events (void (*h)(int key, int down)) { - int key; +static void poll_events (void) { + int key, sym, down; SDL_Event ev; while (SDL_PollEvent(&ev)) { switch (ev.type) { @@ -350,25 +367,39 @@ static void poll_events (void (*h)(int key, int down)) { break; case SDL_KEYDOWN: case SDL_KEYUP: - key = sdl_to_key(ev.key.keysym.sym); - I_press(key, ev.type == SDL_KEYDOWN); - if (h != NULL) { - (*h)(key, ev.type == SDL_KEYDOWN); + sym = ev.key.keysym.sym; + down = ev.type == SDL_KEYDOWN; + key = sdl_to_key(sym); + I_press(key, down); + GM_key(key, down); + if (down && text_input && sym >= 0x20 && sym <= 0x7e) { + // TODO fix this + GM_input(sym); } break; } } } +static void step (void) { + poll_events(); + 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()); return 1; } - SDL_WM_SetCaption("Doom 2D v1.351", "Doom 2D"); + SDL_WM_SetCaption("Doom 2D (SDL)", "Doom 2D"); // Player 1 defaults pl1.ku = KEY_KP_8; pl1.kd = KEY_KP_5; @@ -411,16 +442,13 @@ int main (int argc, char *argv[]) { 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();