From 7d42c3d58e51c157d8d6234b1a76bed5f9912580 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 21 Jan 2019 02:14:57 +0100 Subject: [PATCH] Various emscripten compilation fixes. --- build/autotools/m4/lol-conf.m4 | 1 + src/application/application.cpp | 6 +++--- src/base/assert.cpp | 6 +++--- src/engine/ticker.cpp | 2 +- src/gpu/framebuffer.cpp | 10 +++++----- src/gpu/shader.cpp | 4 ++-- src/lolgl.h | 5 +++-- src/messageservice.cpp | 4 ++-- src/platform/sdl/sdlinput.cpp | 17 ++++++++++++----- src/sys/init.cpp | 4 ++-- 10 files changed, 34 insertions(+), 25 deletions(-) diff --git a/build/autotools/m4/lol-conf.m4 b/build/autotools/m4/lol-conf.m4 index 3b99b92d..9b1f2533 100644 --- a/build/autotools/m4/lol-conf.m4 +++ b/build/autotools/m4/lol-conf.m4 @@ -175,6 +175,7 @@ dnl Are we building using Emscripten? ac_cv_my_have_emscripten="no" AC_CHECK_HEADERS(emscripten.h, [ac_cv_my_have_emscripten="yes" + AC_CHECK_HEADERS(html5/emscripten.h) dnl XXX: activate this if memory heap is too small #AM_CXXFLAGS="${AM_CXXFLAGS} -s ALLOW_MEMORY_GROWTH=1" dnl HACK: until emcc properly adds these to EMSDK_OPTS diff --git a/src/application/application.cpp b/src/application/application.cpp index 738540d9..e59165c4 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2016 Sam Hocevar +// Copyright © 2010—2019 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -147,7 +147,7 @@ class ApplicationData #endif }; -#if EMSCRIPTEN +#if __EMSCRIPTEN__ static Application *g_app; static void AppCallback() @@ -179,7 +179,7 @@ void Application::Tick() void Application::Run() { -#if EMSCRIPTEN +#if __EMSCRIPTEN__ g_app = this; emscripten_set_main_loop(AppCallback, 0, 1); #else diff --git a/src/base/assert.cpp b/src/base/assert.cpp index 8acdaab0..14650425 100644 --- a/src/base/assert.cpp +++ b/src/base/assert.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2019 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -19,7 +19,7 @@ # include #endif -#if EMSCRIPTEN +#if HAVE_EMSCRIPTEN_H # include #endif @@ -31,7 +31,7 @@ namespace debug void dump_stack() { -#if EMSCRIPTEN +#if __EMSCRIPTEN__ /* This would require demangling but we don't care yet. */ msg::debug("%s\n", emscripten_run_script_string("(new Error).stack")); #elif HAVE_CXA_DEMANGLE && HAVE_BACKTRACE_SYMBOLS diff --git a/src/engine/ticker.cpp b/src/engine/ticker.cpp index 55186371..052bbd4c 100644 --- a/src/engine/ticker.cpp +++ b/src/engine/ticker.cpp @@ -532,7 +532,7 @@ void Ticker::tick_draw() /* Clamp FPS */ Profiler::Stop(Profiler::STAT_TICK_BLIT); -#if !EMSCRIPTEN +#if !__EMSCRIPTEN__ /* If framerate is fixed, force wait time to 1/FPS. Otherwise, set wait * time to 0. */ float frametime = data->fps ? 1.f / data->fps : 0.f; diff --git a/src/gpu/framebuffer.cpp b/src/gpu/framebuffer.cpp index 50ef3811..bed35d08 100644 --- a/src/gpu/framebuffer.cpp +++ b/src/gpu/framebuffer.cpp @@ -248,15 +248,15 @@ Framebuffer::Framebuffer(ivec2 size, FramebufferFormat fbo_format) { m_data->m_size = size; m_data->m_bound = false; -#if GL_VERSION_1_1 - GLenum internal_format = fbo_format.GetFormat(); - GLenum format = fbo_format.GetFormatOrder(); - GLenum depth = GL_DEPTH_COMPONENT; -#elif GL_ES_VERSION_2_0 +#if GL_ES_VERSION_2_0 /* In OpenGL ES, internal format and format must match. */ GLenum internal_format = fbo_format.GetFormat(); GLenum format = fbo_format.GetFormat(); GLenum depth = GL_DEPTH_COMPONENT16; /* for WebGL */ +#elif GL_VERSION_1_1 + GLenum internal_format = fbo_format.GetFormat(); + GLenum format = fbo_format.GetFormatOrder(); + GLenum depth = GL_DEPTH_COMPONENT; #else /* In OpenGL ES, internal format and format must match. */ GLenum internal_format = fbo_format.GetFormat(); diff --git a/src/gpu/shader.cpp b/src/gpu/shader.cpp index 483b2557..14fb5d9d 100644 --- a/src/gpu/shader.cpp +++ b/src/gpu/shader.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2018 Sam Hocevar +// Copyright © 2010—2019 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -312,7 +312,7 @@ Shader::Shader(std::string const &name, GLint num_attribs; glGetProgramiv(data->prog_id, GL_ACTIVE_ATTRIBUTES, &num_attribs); -#if EMSCRIPTEN //WebGL doesn't support GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, so chose a default size value. +#if __EMSCRIPTEN__ // WebGL doesn't support GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, so chose a default size value. GLint max_len = 256; #else GLint max_len; diff --git a/src/lolgl.h b/src/lolgl.h index ac301f84..3643706b 100644 --- a/src/lolgl.h +++ b/src/lolgl.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2016 Sam Hocevar +// Copyright © 2010—2019 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -20,8 +20,9 @@ #define GL_GLEXT_PROTOTYPES /* Prefer GLES on browsers */ -#if defined EMSCRIPTEN +#if defined __EMSCRIPTEN__ # undef HAVE_GL_2X +# undef LOL_USE_GLEW #endif /* Only define one GL platform */ diff --git a/src/messageservice.cpp b/src/messageservice.cpp index a28a35b5..a2a10629 100644 --- a/src/messageservice.cpp +++ b/src/messageservice.cpp @@ -22,14 +22,14 @@ namespace lol { // This is needed to map MessageService::Send() to the JS when building the HTML. -#if EMSCRIPTEN +#if __EMSCRIPTEN__ extern "C" { int C_Send(const char* message) { return (int)MessageService::Send(MessageBucket::AppIn, message); } //NOT IMPLEMENTED //bool C_FetchFirst(std::string& message); } -#endif //EMSCRIPTEN +#endif // __EMSCRIPTEN__ /* * The global g_messageservice object, initialised by MessageService::Setup() diff --git a/src/platform/sdl/sdlinput.cpp b/src/platform/sdl/sdlinput.cpp index afe58b78..283bdb4b 100644 --- a/src/platform/sdl/sdlinput.cpp +++ b/src/platform/sdl/sdlinput.cpp @@ -19,6 +19,9 @@ # include # endif #endif +#if HAVE_EMSCRIPTEN_HTML5_H +# include +#endif #include "sdlinput.h" @@ -28,7 +31,7 @@ * there is no SDL display (eg. on the Raspberry Pi). */ #define SDL_FORCE_POLL_JOYSTICK 1 -#if EMSCRIPTEN +#if __EMSCRIPTEN__ # define MOUSE_SPEED_MOD 10.f #else # define MOUSE_SPEED_MOD 100.f @@ -133,6 +136,9 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) m_data->m_tick_in_draw_thread = true; #endif +#if __EMSCRIPTEN__ + emscripten_sample_gamepad_data(); +#endif #if LOL_USE_SDL SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK); #endif @@ -141,7 +147,8 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) m_data->m_mouse = InputDeviceInternal::CreateStandardMouse(); #if LOL_USE_SDL -# if !EMSCRIPTEN + // XXX: another option is to properly handle gamepad support +# if !__EMSCRIPTEN__ # if SDL_FORCE_POLL_JOYSTICK SDL_JoystickEventState(SDL_QUERY); # else @@ -180,7 +187,7 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) m_data->m_joysticks.push(sdlstick, stick); } -# endif //EMSCRIPTEN +# endif // __EMSCRIPTEN__ #endif m_gamegroup = GAMEGROUP_INPUT; @@ -188,7 +195,7 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) SdlInput::~SdlInput() { -#if LOL_USE_SDL && !EMSCRIPTEN +#if LOL_USE_SDL && !__EMSCRIPTEN__ /* Unregister all the joysticks we added */ while (m_data->m_joysticks.count()) { @@ -223,7 +230,7 @@ void SdlInputData::Tick(float seconds) UNUSED(seconds); /* Pump all joystick events because no event is coming to us. */ -# if SDL_FORCE_POLL_JOYSTICK && !EMSCRIPTEN +# if SDL_FORCE_POLL_JOYSTICK && !__EMSCRIPTEN__ SDL_JoystickUpdate(); for (int j = 0; j < m_joysticks.count(); j++) { diff --git a/src/sys/init.cpp b/src/sys/init.cpp index 9848da20..855b5506 100644 --- a/src/sys/init.cpp +++ b/src/sys/init.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2018 Sam Hocevar +// Copyright © 2010—2019 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -54,7 +54,7 @@ void init(int argc, char *argv[], * and emscripten, and the current directory on other platforms. */ -#if __ANDROID__ || EMSCRIPTEN +#if __ANDROID__ || __EMSCRIPTEN__ std::string binarydir = ""; #else std::string binarydir = ".";