Browse Source

Various emscripten compilation fixes.

legacy
Sam Hocevar 7 years ago
parent
commit
7d42c3d58e
10 changed files with 34 additions and 25 deletions
  1. +1
    -0
      build/autotools/m4/lol-conf.m4
  2. +3
    -3
      src/application/application.cpp
  3. +3
    -3
      src/base/assert.cpp
  4. +1
    -1
      src/engine/ticker.cpp
  5. +5
    -5
      src/gpu/framebuffer.cpp
  6. +2
    -2
      src/gpu/shader.cpp
  7. +3
    -2
      src/lolgl.h
  8. +2
    -2
      src/messageservice.cpp
  9. +12
    -5
      src/platform/sdl/sdlinput.cpp
  10. +2
    -2
      src/sys/init.cpp

+ 1
- 0
build/autotools/m4/lol-conf.m4 View File

@@ -175,6 +175,7 @@ dnl Are we building using Emscripten?
ac_cv_my_have_emscripten="no" ac_cv_my_have_emscripten="no"
AC_CHECK_HEADERS(emscripten.h, AC_CHECK_HEADERS(emscripten.h,
[ac_cv_my_have_emscripten="yes" [ac_cv_my_have_emscripten="yes"
AC_CHECK_HEADERS(html5/emscripten.h)
dnl XXX: activate this if memory heap is too small dnl XXX: activate this if memory heap is too small
#AM_CXXFLAGS="${AM_CXXFLAGS} -s ALLOW_MEMORY_GROWTH=1" #AM_CXXFLAGS="${AM_CXXFLAGS} -s ALLOW_MEMORY_GROWTH=1"
dnl HACK: until emcc properly adds these to EMSDK_OPTS dnl HACK: until emcc properly adds these to EMSDK_OPTS


+ 3
- 3
src/application/application.cpp View File

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -147,7 +147,7 @@ class ApplicationData
#endif #endif
}; };


#if EMSCRIPTEN
#if __EMSCRIPTEN__
static Application *g_app; static Application *g_app;


static void AppCallback() static void AppCallback()
@@ -179,7 +179,7 @@ void Application::Tick()


void Application::Run() void Application::Run()
{ {
#if EMSCRIPTEN
#if __EMSCRIPTEN__
g_app = this; g_app = this;
emscripten_set_main_loop(AppCallback, 0, 1); emscripten_set_main_loop(AppCallback, 0, 1);
#else #else


+ 3
- 3
src/base/assert.cpp View File

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -19,7 +19,7 @@
# include <execinfo.h> # include <execinfo.h>
#endif #endif


#if EMSCRIPTEN
#if HAVE_EMSCRIPTEN_H
# include <emscripten.h> # include <emscripten.h>
#endif #endif


@@ -31,7 +31,7 @@ namespace debug


void dump_stack() void dump_stack()
{ {
#if EMSCRIPTEN
#if __EMSCRIPTEN__
/* This would require demangling but we don't care yet. */ /* This would require demangling but we don't care yet. */
msg::debug("%s\n", emscripten_run_script_string("(new Error).stack")); msg::debug("%s\n", emscripten_run_script_string("(new Error).stack"));
#elif HAVE_CXA_DEMANGLE && HAVE_BACKTRACE_SYMBOLS #elif HAVE_CXA_DEMANGLE && HAVE_BACKTRACE_SYMBOLS


+ 1
- 1
src/engine/ticker.cpp View File

@@ -532,7 +532,7 @@ void Ticker::tick_draw()
/* Clamp FPS */ /* Clamp FPS */
Profiler::Stop(Profiler::STAT_TICK_BLIT); Profiler::Stop(Profiler::STAT_TICK_BLIT);


#if !EMSCRIPTEN
#if !__EMSCRIPTEN__
/* If framerate is fixed, force wait time to 1/FPS. Otherwise, set wait /* If framerate is fixed, force wait time to 1/FPS. Otherwise, set wait
* time to 0. */ * time to 0. */
float frametime = data->fps ? 1.f / data->fps : 0.f; float frametime = data->fps ? 1.f / data->fps : 0.f;


+ 5
- 5
src/gpu/framebuffer.cpp View File

@@ -248,15 +248,15 @@ Framebuffer::Framebuffer(ivec2 size, FramebufferFormat fbo_format)
{ {
m_data->m_size = size; m_data->m_size = size;
m_data->m_bound = false; 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. */ /* In OpenGL ES, internal format and format must match. */
GLenum internal_format = fbo_format.GetFormat(); GLenum internal_format = fbo_format.GetFormat();
GLenum format = fbo_format.GetFormat(); GLenum format = fbo_format.GetFormat();
GLenum depth = GL_DEPTH_COMPONENT16; /* for WebGL */ 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 #else
/* In OpenGL ES, internal format and format must match. */ /* In OpenGL ES, internal format and format must match. */
GLenum internal_format = fbo_format.GetFormat(); GLenum internal_format = fbo_format.GetFormat();


+ 2
- 2
src/gpu/shader.cpp View File

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -312,7 +312,7 @@ Shader::Shader(std::string const &name,
GLint num_attribs; GLint num_attribs;
glGetProgramiv(data->prog_id, GL_ACTIVE_ATTRIBUTES, &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; GLint max_len = 256;
#else #else
GLint max_len; GLint max_len;


+ 3
- 2
src/lolgl.h View File

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -20,8 +20,9 @@
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES


/* Prefer GLES on browsers */ /* Prefer GLES on browsers */
#if defined EMSCRIPTEN
#if defined __EMSCRIPTEN__
# undef HAVE_GL_2X # undef HAVE_GL_2X
# undef LOL_USE_GLEW
#endif #endif


/* Only define one GL platform */ /* Only define one GL platform */


+ 2
- 2
src/messageservice.cpp View File

@@ -22,14 +22,14 @@ namespace lol
{ {


// This is needed to map MessageService::Send() to the JS when building the HTML. // This is needed to map MessageService::Send() to the JS when building the HTML.
#if EMSCRIPTEN
#if __EMSCRIPTEN__
extern "C" extern "C"
{ {
int C_Send(const char* message) { return (int)MessageService::Send(MessageBucket::AppIn, message); } int C_Send(const char* message) { return (int)MessageService::Send(MessageBucket::AppIn, message); }
//NOT IMPLEMENTED //NOT IMPLEMENTED
//bool C_FetchFirst(std::string& message); //bool C_FetchFirst(std::string& message);
} }
#endif //EMSCRIPTEN
#endif // __EMSCRIPTEN__


/* /*
* The global g_messageservice object, initialised by MessageService::Setup() * The global g_messageservice object, initialised by MessageService::Setup()


+ 12
- 5
src/platform/sdl/sdlinput.cpp View File

@@ -19,6 +19,9 @@
# include <SDL.h> # include <SDL.h>
# endif # endif
#endif #endif
#if HAVE_EMSCRIPTEN_HTML5_H
# include <emscripten/html5.h>
#endif


#include "sdlinput.h" #include "sdlinput.h"


@@ -28,7 +31,7 @@
* there is no SDL display (eg. on the Raspberry Pi). */ * there is no SDL display (eg. on the Raspberry Pi). */
#define SDL_FORCE_POLL_JOYSTICK 1 #define SDL_FORCE_POLL_JOYSTICK 1


#if EMSCRIPTEN
#if __EMSCRIPTEN__
# define MOUSE_SPEED_MOD 10.f # define MOUSE_SPEED_MOD 10.f
#else #else
# define MOUSE_SPEED_MOD 100.f # 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; m_data->m_tick_in_draw_thread = true;
#endif #endif


#if __EMSCRIPTEN__
emscripten_sample_gamepad_data();
#endif
#if LOL_USE_SDL #if LOL_USE_SDL
SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK); SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK);
#endif #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(); m_data->m_mouse = InputDeviceInternal::CreateStandardMouse();


#if LOL_USE_SDL #if LOL_USE_SDL
# if !EMSCRIPTEN
// XXX: another option is to properly handle gamepad support
# if !__EMSCRIPTEN__
# if SDL_FORCE_POLL_JOYSTICK # if SDL_FORCE_POLL_JOYSTICK
SDL_JoystickEventState(SDL_QUERY); SDL_JoystickEventState(SDL_QUERY);
# else # 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); m_data->m_joysticks.push(sdlstick, stick);
} }
# endif //EMSCRIPTEN
# endif // __EMSCRIPTEN__
#endif #endif


m_gamegroup = GAMEGROUP_INPUT; m_gamegroup = GAMEGROUP_INPUT;
@@ -188,7 +195,7 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h)


SdlInput::~SdlInput() SdlInput::~SdlInput()
{ {
#if LOL_USE_SDL && !EMSCRIPTEN
#if LOL_USE_SDL && !__EMSCRIPTEN__
/* Unregister all the joysticks we added */ /* Unregister all the joysticks we added */
while (m_data->m_joysticks.count()) while (m_data->m_joysticks.count())
{ {
@@ -223,7 +230,7 @@ void SdlInputData::Tick(float seconds)
UNUSED(seconds); UNUSED(seconds);


/* Pump all joystick events because no event is coming to us. */ /* 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(); SDL_JoystickUpdate();
for (int j = 0; j < m_joysticks.count(); j++) for (int j = 0; j < m_joysticks.count(); j++)
{ {


+ 2
- 2
src/sys/init.cpp View File

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // 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. * and emscripten, and the current directory on other platforms.
*/ */


#if __ANDROID__ || EMSCRIPTEN
#if __ANDROID__ || __EMSCRIPTEN__
std::string binarydir = ""; std::string binarydir = "";
#else #else
std::string binarydir = "."; std::string binarydir = ".";


Loading…
Cancel
Save