Emscripten flavor now compiles correctly

This commit is contained in:
xawotihs
2015-11-02 23:00:57 +01:00
parent e272925f3d
commit 87f5e7f3a6
3 changed files with 36 additions and 20 deletions

View File

@@ -99,7 +99,7 @@ WAGIC_OPTION(BUILD_PNG "build png from source" (WIN32 OR APPLE OR PSP OR
WAGIC_OPTION(BUILD_UNZIP "build unzip from source" ON)
WAGIC_OPTION(BUILD_TINYXML "build tinyxml from source" (WIN32 OR APPLE OR PSP OR ANDROID OR EMSCRIPTEN))
WAGIC_OPTION(BUILD_ZIPFS "build zipfs from source" ON)
WAGIC_OPTION(BUILD_SDL2 "build SDL2 from source" (backend_sdl AND (UNIX OR WIN32 OR ANDROID OR EMSCRIPTEN)))
WAGIC_OPTION(BUILD_SDL2 "build SDL2 from source" (backend_sdl AND (UNIX OR WIN32 OR ANDROID) AND (NOT EMSCRIPTEN)))
#project options
if(ANDROID)
@@ -138,6 +138,8 @@ include(FindOrBuild)
if(PSP)
FindOrBuildPSPSDK()
include(platforms/psp/configure.cmake)
elseif(EMSCRIPTEN)
include(platforms/emscripten/configure.cmake)
elseif(WIN32)
include(platforms/win/configure.cmake)
elseif(APPLE)
@@ -146,8 +148,6 @@ elseif(UNIX)
include(platforms/unix/configure.cmake)
elseif(ANDROID)
include(platforms/android/configure.cmake)
elseif(EMSCRIPTEN)
include(platforms/emscripten/configure.cmake)
endif()
#set backend dependend configurations

View File

@@ -1,3 +1,5 @@
set_target_properties(wagic PROPERTIES LINK_FLAGS "-s USE_SDL=2")
set(CMAKE_CXX_FLAGS "-s USE_SDL=2")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
set(CMAKE_CXX_FLAGS "-s USE_SDL=2 -std=c++11")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
add_definitions(-DLINUX)
add_definitions(-DUSERDIR=".wagic")
add_definitions(-DRESDIR="Res")

View File

@@ -19,6 +19,10 @@
#include <iostream>
#include <math.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#if (defined FORCE_GLES)
#undef GL_ES_VERSION_2_0
#undef GL_VERSION_2_0
@@ -101,7 +105,7 @@ class SdlApp
public: /* For easy interfacing with JGE static functions */
bool Running;
SDL_Window* window;
SDL_GLContext gl_context;
SDL_GLContext gl_context;
SDL_Rect viewPort;
Uint32 lastMouseUpTime;
Uint32 lastFingerDownTime;
@@ -112,10 +116,27 @@ public: /* For easy interfacing with JGE static functions */
int mMouseDownX;
int mMouseDownY;
static SdlApp* sInstance;
public:
SdlApp() : Running(true), window(NULL), gl_context(NULL), lastMouseUpTime(0), lastFingerDownTime(0), mMouseDownX(0), mMouseDownY(0)
{
sInstance = this;
}
static void OneIter()
{
SDL_Event Event;
if (g_engine)
{
for (int x = 0; x < 5 && SDL_WaitEventTimeout(&Event, 10); ++x)
{
if(!g_engine->IsPaused())
sInstance->OnEvent(&Event);
}
if(!g_engine->IsPaused())
sInstance->OnUpdate();
}
}
int OnExecute()
@@ -125,22 +146,14 @@ public:
return -1;
}
SDL_Event Event;
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(OneIter, 60, 1);
#else
while(Running)
{
if (g_engine)
{
for (int x = 0; x < 5 && SDL_WaitEventTimeout(&Event, 10); ++x)
{
if(!g_engine->IsPaused())
OnEvent(&Event);
}
if(!g_engine->IsPaused())
OnUpdate();
}
OneIter();
}
#endif
OnCleanup();
return 0;
@@ -280,6 +293,7 @@ public:
SDL_Quit();
}
};
SdlApp* SdlApp::sInstance = 0;
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
{