From f4ff5f3ea3d11452f0b9c5a28665fcf3687ef4d2 Mon Sep 17 00:00:00 2001 From: ToadKing Date: Sun, 18 Aug 2013 02:50:10 -0400 Subject: [PATCH] [EMSCRIPTEN] less workarounds due to fixes in emscripten, enable more optimizations --- Makefile.emscripten | 22 ++++++++++++++++------ frontend/frontend_emscripten.c | 27 ++++++++++++++++++++++++--- gfx/context/emscriptenegl_ctx.c | 11 +++++------ input/sdl_input.c | 7 +------ 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/Makefile.emscripten b/Makefile.emscripten index f4ba2700a7..52f9711060 100644 --- a/Makefile.emscripten +++ b/Makefile.emscripten @@ -47,16 +47,19 @@ HAVE_FREETYPE = 1 HAVE_ZLIB = 1 HAVE_FBO = 1 WANT_MINIZ = 1 +MEMORY = 67108864 +LTO = 0 +FAST_DOUBLES = 1 ifneq ($(NATIVE_ZLIB),) WANT_MINIZ = 0 endif -libretro ?= -lretro_emscripten +libretro = libretro_emscripten.bc LIBS = -lm DEFINES = -DHAVE_SCREENSHOTS -DHAVE_NULLAUDIO -DHAVE_BSV_MOVIE -DPACKAGE_VERSION=\"0.9.9.3\" -LDFLAGS = -L. -static-libgcc -s TOTAL_MEMORY=268435456 +LDFLAGS = -L. -s TOTAL_MEMORY=$(MEMORY) ifeq ($(SCALER_NO_SIMD), 1) DEFINES += -DSCALER_NO_SIMD @@ -105,8 +108,6 @@ ifeq ($(HAVE_ZLIB), 1) endif endif -LIBS += $(libretro) - ifeq ($(HAVE_FBO), 1) DEFINES += -DHAVE_FBO endif @@ -117,8 +118,17 @@ endif ifeq ($(DEBUG), 1) LDFLAGS += -O0 -g + CFLAGS += -O0 -g else - LDFLAGS += -O2 -ffast-math + LDFLAGS += -O2 + # WARNING: some optimizations can break some cores (ex: LTO breaks tyrquake) + ifeq ($(FAST_DOUBLES), 1) + LDFLAGS += -s DOUBLE_MODE=0 + endif + ifeq ($(LTO), 1) + LDFLAGS += --llvm-lto 3 + endif + CFLAGS += -O2 endif CFLAGS += -Wall -Wno-unused-result -Wno-unused-variable -I. -std=gnu99 @@ -127,7 +137,7 @@ all: $(TARGET) $(TARGET): $(OBJ) @$(if $(Q), $(shell echo echo LD $@),) - $(Q)$(LD) -o $@ $(OBJ) $(LIBS) $(LDFLAGS) + $(Q)$(LD) -o $@ $(OBJ) $(libretro) $(LIBS) $(LDFLAGS) %.o: %.c @$(if $(Q), $(shell echo echo CC $<),) diff --git a/frontend/frontend_emscripten.c b/frontend/frontend_emscripten.c index 745096e0b4..cfa762ae1f 100644 --- a/frontend/frontend_emscripten.c +++ b/frontend/frontend_emscripten.c @@ -31,12 +31,33 @@ static bool menuloop; -void mainloop(void) +static void endloop(void) +{ + g_extern.system.shutdown = false; + menu_free(); + + if (g_extern.config_save_on_exit && *g_extern.config_path) + config_save_file(g_extern.config_path); + + if (g_extern.main_is_init) + rarch_main_deinit(); + + rarch_deinit_msg_queue(); + +#ifdef PERF_TEST + rarch_perf_log(); +#endif + + rarch_main_clear_state(); + + exit(0); +} + +static void mainloop(void) { if (g_extern.system.shutdown) { - RARCH_ERR("Exit...\n"); - exit(0); + endloop(); } else if (menuloop) { diff --git a/gfx/context/emscriptenegl_ctx.c b/gfx/context/emscriptenegl_ctx.c index e0778fe973..9c5f2516bd 100644 --- a/gfx/context/emscriptenegl_ctx.c +++ b/gfx/context/emscriptenegl_ctx.c @@ -30,14 +30,12 @@ #include #include -#include #include static EGLContext g_egl_ctx; static EGLSurface g_egl_surf; static EGLDisplay g_egl_dpy; static EGLConfig g_config; -static bool g_quit; static bool g_inited; @@ -58,12 +56,13 @@ static void gfx_ctx_check_window(bool *quit, (void)height; *resize = false; - *quit = g_quit; + *quit = false; } static void gfx_ctx_swap_buffers(void) { - eglSwapBuffers(g_egl_dpy, g_egl_surf); + // no-op in emscripten, no way to force swap/wait for vsync in browsers + //eglSwapBuffers(g_egl_dpy, g_egl_surf); } static void gfx_ctx_set_resize(unsigned width, unsigned height) @@ -209,7 +208,7 @@ static void gfx_ctx_input_driver(const input_driver_t **input, void **input_data { *input = NULL; - if (SDL_Init(SDL_INIT_VIDEO) != 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) != 0) return; void *sdlinput = input_sdl.init(); @@ -228,7 +227,7 @@ static bool gfx_ctx_has_focus(void) static gfx_ctx_proc_t gfx_ctx_get_proc_address(const char *symbol) { - return SDL_GL_GetProcAddress(symbol); + return eglGetProcAddress(symbol); } static float gfx_ctx_translate_aspect(unsigned width, unsigned height) diff --git a/input/sdl_input.c b/input/sdl_input.c index a5dd282c85..57c9a32b91 100644 --- a/input/sdl_input.c +++ b/input/sdl_input.c @@ -24,7 +24,7 @@ #include "../libretro.h" #include "input_common.h" -#if !(SDL_MAJOR_VERSION <= 1 && SDL_MINOR_VERSION <= 2) +#ifdef EMSCRIPTEN #define SDL_GetKeyState SDL_GetKeyboardState #endif @@ -232,12 +232,7 @@ static void sdl_poll_mouse(sdl_input_t *sdl) static void sdl_input_poll(void *data) { -#ifdef EMSCRIPTEN - SDL_Event event; - while (SDL_PollEvent(&event)); -#else SDL_PumpEvents(); -#endif sdl_input_t *sdl = (sdl_input_t*)data; input_joypad_poll(sdl->joypad);