Browse Source

Fix an issue with SDL2 initialization when running under Emscripten, further guard protect 3D when building 2D only binaries

Josh Engebretson 10 years ago
parent
commit
9e9bc6fc72

+ 2 - 2
CMakeLists.txt

@@ -5,7 +5,7 @@ cmake_minimum_required (VERSION 3.0.2)
 
 set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
 
-add_definitions( -DATOMIC_API= -DATOMIC_STATIC_DEFINE -DATOMIC_ATOMIC2D )
+add_definitions( -DATOMIC_API= -DATOMIC_STATIC_DEFINE -DATOMIC_ATOMIC2D -DATOMIC_LOGGING)
 
 # this is here as QtCreator is having trouble picking up #include <Atomic/*> without it
 include_directories(${CMAKE_SOURCE_DIR}/Source ${CMAKE_SOURCE_DIR}/Source/AtomicEditor/Source)
@@ -18,7 +18,7 @@ if (NOT ATOMIC_BUILD_2D)
 endif()
 
 if (NOT EMSCRIPTEN)
-    add_definitions( -DATOMIC_NETWORK -DATOMIC_LOGGING)
+    add_definitions( -DATOMIC_NETWORK)
     set (ATOMIC_LINK_LIBRARIES ${ATOMIC_LINK_LIBRARIES} SDL Civetweb Recast Detour kNet )
 endif()
 

+ 14 - 0
Source/Atomic/Engine/Application.cpp

@@ -43,6 +43,13 @@ namespace Atomic
 #if defined(EMSCRIPTEN)
 #include <emscripten.h>
 #endif
+// SDL2 needs a main loop to be running during initialization
+// otherwise EGL will error, so this is the main loop used during init
+// and is canceled once everything is initialized
+void InitializationMainLoop()
+{
+
+}
 void RunFrame(void* data)
 {
     static_cast<Engine*>(data)->RunFrame();
@@ -69,6 +76,10 @@ int Application::Run()
     // Thus, the try-catch block below should be optimised out except in Debug build configuration
     try
     {
+  #if defined(EMSCRIPTEN)
+        emscripten_set_main_loop(InitializationMainLoop, 0, 0);
+  #endif
+
         Setup();
         if (exitCode_)
             return exitCode_;
@@ -95,6 +106,9 @@ int Application::Run()
         #if defined(IOS)
         SDL_iPhoneSetAnimationCallback(GetSubsystem<Graphics>()->GetImpl()->GetWindow(), 1, &RunFrame, engine_);
         #elif defined(EMSCRIPTEN)
+        // cancel the initialization loop
+        emscripten_cancel_main_loop();
+        // and run the engine loop
         emscripten_set_main_loop_arg(RunFrame, engine_, 0, 1);
         #endif
         #endif

+ 9 - 0
Source/AtomicJS/JSBind/JSBClass.cpp

@@ -7,6 +7,7 @@
 #include <Atomic/Core/ProcessUtils.h>
 #include "JSBClass.h"
 #include "JSBFunction.h"
+#include "JSBModule.h"
 
 Vector<JSBClass*> JSBClass::allClasses_;
 
@@ -166,9 +167,17 @@ void JSBClass::WriteProtoTypeRecursive(String &source, JSBClass* klass,  Vector<
     JSBClass* base = klass->baseClasses_.Size() ? klass->baseClasses_[0] : NULL;
 
     if (!klass->isNumberArray())
+    {
+        JSBModule* module = klass->GetModule();
+
+        if (module->Requires("3D"))
+            source += "\n#ifdef ATOMIC_3D\n";
         source.AppendWithFormat("   js_setup_prototype(vm, \"%s\", \"%s\", %s);\n",
                                 klass->GetName().CString(), base ? base->GetName().CString() : "",
                                 klass->hasProperties() ? "true" : "false");
+        if (module->Requires("3D"))
+            source += "#endif\n\n";
+    }
 
     written.Push(klass);
 

+ 1 - 1
Source/AtomicJS/JSBind/JSBindings.cpp

@@ -195,7 +195,7 @@ void JSBindings::Initialize()
 
     if (JSBind::PLATFORM == "WEB")
     {
-        JSONValue jmodulesExclude = json.GetChild("modulePlatformExclude");
+        JSONValue jmodulesExclude = json.GetChild("moduleExclude");
         JSONValue jexcludes = jmodulesExclude.GetChild("WEB");
 
         for (unsigned i = 0; i < jexcludes.GetSize(); i++)