diff --git a/include.xml b/include.xml index d6562fbc0..4db9b5dbf 100644 --- a/include.xml +++ b/include.xml @@ -6,7 +6,7 @@ - + @@ -28,7 +28,7 @@ - + diff --git a/lime/_backend/native/NativeApplication.hx b/lime/_backend/native/NativeApplication.hx index dfc39ddca..58790bae3 100644 --- a/lime/_backend/native/NativeApplication.hx +++ b/lime/_backend/native/NativeApplication.hx @@ -67,12 +67,12 @@ class NativeApplication { lime_update_event_manager_register (handleUpdateEvent, updateEventInfo); lime_window_event_manager_register (handleWindowEvent, windowEventInfo); - lime_application_init (handle); - // TODO: add parent.init #if nodejs + lime_application_init (handle); + var prevTime = untyped __js__ ('Date.now ()'); var eventLoop = function () { @@ -106,12 +106,7 @@ class NativeApplication { #elseif (cpp || neko) - while (lime_application_update (handle)) {} - - var result = lime_application_quit (handle); - __cleanup (); - - return result; + return lime_application_exec (handle); #else @@ -303,6 +298,7 @@ class NativeApplication { private static var lime_application_create = System.load ("lime", "lime_application_create", 1); + private static var lime_application_exec = System.load ("lime", "lime_application_exec", 1); private static var lime_application_init = System.load ("lime", "lime_application_init", 1); private static var lime_application_update = System.load ("lime", "lime_application_update", 1); private static var lime_application_quit = System.load ("lime", "lime_application_quit", 1); diff --git a/lime/tools/platforms/EmscriptenPlatform.hx b/lime/tools/platforms/EmscriptenPlatform.hx index 0fc2d1db0..8e756fe26 100644 --- a/lime/tools/platforms/EmscriptenPlatform.hx +++ b/lime/tools/platforms/EmscriptenPlatform.hx @@ -60,8 +60,6 @@ class EmscriptenPlatform extends PlatformTarget { } - Sys.putEnv ("EMCC_LLVM_TARGET", "i386-pc-linux-gnu"); - ProcessHelper.runCommand ("", "emcc", [ targetDirectory + "/obj/Main.cpp", "-o", targetDirectory + "/obj/Main.o" ], true, false, true); var args = [ "Main.o" ]; @@ -78,19 +76,19 @@ class EmscriptenPlatform extends PlatformTarget { args = [ "ApplicationMain.o", "-s", "FULL_ES2=1" ]; - if (project.targetFlags.exists ("asm")) { + //if (project.targetFlags.exists ("asm")) { args.push ("-s"); args.push ("ASM_JS=1"); - } else { + /*} else { args.push ("-s"); args.push ("ASM_JS=0"); args.push ("-s"); args.push ("ALLOW_MEMORY_GROWTH=1"); - } + }*/ args.push ("-s"); args.push ("USE_SDL=2"); @@ -106,19 +104,21 @@ class EmscriptenPlatform extends PlatformTarget { args.push ("-s"); args.push ("DISABLE_EXCEPTION_CATCHING=2"); + args.push ("-s"); + args.push ("ASSERTIONS=1"); } - if (!project.debug || project.targetFlags.exists ("asm")) { + //if (!project.debug || project.targetFlags.exists ("asm")) { args.push ("-O2"); - } else { + //} else { //args.push ("--minify"); //args.push ("1"); - } + //} if (project.targetFlags.exists ("minify")) { diff --git a/project/Build.xml b/project/Build.xml index 384b6c993..9bb39d64f 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -151,6 +151,14 @@ +
+ + + + + +
+ diff --git a/project/src/backend/sdl/SDLApplication.cpp b/project/src/backend/sdl/SDLApplication.cpp index f9904cb71..81317754e 100644 --- a/project/src/backend/sdl/SDLApplication.cpp +++ b/project/src/backend/sdl/SDLApplication.cpp @@ -4,6 +4,10 @@ #include #endif +#ifdef EMSCRIPTEN +#include "emscripten.h" +#endif + namespace lime { @@ -22,6 +26,11 @@ namespace lime { SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER); + #ifdef EMSCRIPTEN + currentApplication = this; + emscripten_set_main_loop (EmscriptenUpdate, 0, 0); + #endif + currentUpdate = 0; lastUpdate = 0; nextUpdate = 0; @@ -60,6 +69,12 @@ namespace lime { Init (); + #ifdef EMSCRIPTEN + + return 0; + + #else + while (active) { Update (); @@ -68,6 +83,8 @@ namespace lime { return Quit (); + #endif + } @@ -309,6 +326,8 @@ namespace lime { SDL_Event event; event.type = -1; + #ifndef EMSCRIPTEN + if (active && (firstTime || SDL_WaitEvent (&event))) { firstTime = false; @@ -341,6 +360,21 @@ namespace lime { } + #else + + while (SDL_PollEvent (&event)) { + + HandleEvent (&event); + event.type = -1; + + } + + event.type = SDL_USEREVENT; + HandleEvent (&event); + event.type = -1; + + #endif + return active; } @@ -353,6 +387,17 @@ namespace lime { } + #ifdef EMSCRIPTEN + SDLApplication* SDLApplication::currentApplication = 0; + + void SDLApplication::EmscriptenUpdate () { + + currentApplication->Update (); + + } + #endif + + } diff --git a/project/src/backend/sdl/SDLApplication.h b/project/src/backend/sdl/SDLApplication.h index 30e19a9cb..8e2c69d4a 100644 --- a/project/src/backend/sdl/SDLApplication.h +++ b/project/src/backend/sdl/SDLApplication.h @@ -26,6 +26,11 @@ namespace lime { virtual void Init (); virtual int Quit (); virtual bool Update (); + + #ifdef EMSCRIPTEN + static SDLApplication *currentApplication; + static void EmscriptenUpdate (); + #endif private: diff --git a/templates/emscripten/cpp/Main.cpp b/templates/emscripten/cpp/Main.cpp index c6ab66805..84bf64177 100644 --- a/templates/emscripten/cpp/Main.cpp +++ b/templates/emscripten/cpp/Main.cpp @@ -9,33 +9,35 @@ extern "C" const char *hxRunLibrary(); extern "C" void hxcpp_set_top_of_stack(); - -::foreach ndlls:: - ::if (registerStatics):: - extern "C" int ::name::_register_prims(); - ::end:: -::end:: - -extern "C" int main(int argc, char *argv[]) -{ - //printf("Starting ...\n" ); - hxcpp_set_top_of_stack(); - ::foreach ndlls:: - ::if (registerStatics):: - ::name::_register_prims(); - ::end:: - ::end:: +extern "C" int zlib_register_prims(); +::foreach ndlls::::if (registerStatics)::extern "C" int ::name::_register_prims();::end:: +::end:: + + +extern "C" int main(int argc, char *argv[]) { + + //printf("Starting ...\n" ); + hxcpp_set_top_of_stack (); + + zlib_register_prims (); + + ::foreach ndlls::::if (registerStatics)::::name::_register_prims();::end:: + ::end:: //printf("Running\n"); - + const char *err = NULL; - err = hxRunLibrary(); + err = hxRunLibrary (); + if (err) { + printf(" Error %s\n", err ); return -1; + } - + //printf("Done!\n"); return 0; -} + +} \ No newline at end of file diff --git a/templates/emscripten/hxml/debug.hxml b/templates/emscripten/hxml/debug.hxml index 8a8077187..61fa3fad2 100644 --- a/templates/emscripten/hxml/debug.hxml +++ b/templates/emscripten/hxml/debug.hxml @@ -2,7 +2,6 @@ -cp ::BUILD_DIR::/emscripten/haxe -cpp ::CPP_DIR:: --macro keep("::APP_MAIN::") --lib openfl-native -D emscripten -D webgl -debug \ No newline at end of file diff --git a/templates/emscripten/template/index.html b/templates/emscripten/template/index.html index d678fb1ac..41aba1cf1 100644 --- a/templates/emscripten/template/index.html +++ b/templates/emscripten/template/index.html @@ -1,47 +1,66 @@ - + + - + + ::APP_TITLE:: + + + + + ::if linkedLibraries::::foreach (linkedLibraries):: + ::end::::end:: + + + + + - + + ::foreach assets::::if (type == "font"):: + ::end::::end:: - - - -
+
::end:: - diff --git a/templates/haxe/ApplicationMain.hx b/templates/haxe/ApplicationMain.hx index fcce2574d..da23de226 100644 --- a/templates/haxe/ApplicationMain.hx +++ b/templates/haxe/ApplicationMain.hx @@ -13,6 +13,11 @@ class ApplicationMain { public static function create ():Void { + #if !munit + app = new ::APP_MAIN:: (); + app.create (config); + #end + preloader = new ::if (PRELOADER_NAME != "")::::PRELOADER_NAME::::else::lime.app.Preloader::end:: (); preloader.onComplete = start; preloader.create (config); @@ -71,12 +76,9 @@ class ApplicationMain { #if !munit - app = new ::APP_MAIN:: (); - app.create (config); - var result = app.exec (); - #if (sys && !nodejs) + #if (sys && !nodejs && !emscripten) Sys.exit (result); #end