Josh Engebretson 11 years ago
parent
commit
cca1f992c6

File diff suppressed because it is too large
+ 188 - 0
Data/AtomicEditor/Deployment/Web/AtomicPlayer.html


+ 161 - 0
Data/AtomicEditor/Deployment/Web/AtomicResources_js.template

@@ -0,0 +1,161 @@
+
+var Module;
+if (typeof Module === 'undefined') Module = eval('(function() { try { return Module || {} } catch(e) { return {} } })()');
+if (!Module.expectedDataFileDownloads) {
+  Module.expectedDataFileDownloads = 0;
+  Module.finishedDataFileDownloads = 0;
+}
+Module.expectedDataFileDownloads++;
+(function() {
+
+    var PACKAGE_PATH;
+    if (typeof window === 'object') {
+      PACKAGE_PATH = window['encodeURIComponent'](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf('/')) + '/');
+    } else {
+      // worker
+      PACKAGE_PATH = encodeURIComponent(location.pathname.toString().substring(0, location.pathname.toString().lastIndexOf('/')) + '/');
+    }
+    var PACKAGE_NAME = 'AtomicResources.data';
+    var REMOTE_PACKAGE_BASE = 'AtomicResources.data';
+    if (typeof Module['locateFilePackage'] === 'function' && !Module['locateFile']) {
+      Module['locateFile'] = Module['locateFilePackage'];
+      Module.printErr('warning: you defined Module.locateFilePackage, that has been renamed to Module.locateFile (using your locateFilePackage for now)');
+    }
+    var REMOTE_PACKAGE_NAME = typeof Module['locateFile'] === 'function' ?
+                              Module['locateFile'](REMOTE_PACKAGE_BASE) :
+                              ((Module['filePackagePrefixURL'] || '') + REMOTE_PACKAGE_BASE);
+    var REMOTE_PACKAGE_SIZE = 1265134;
+    var PACKAGE_UUID = 'd832f5b3-9296-453e-be32-e9a18cf5c8c7';
+  
+    function fetchRemotePackage(packageName, packageSize, callback, errback) {
+      var xhr = new XMLHttpRequest();
+      xhr.open('GET', packageName, true);
+      xhr.responseType = 'arraybuffer';
+      xhr.onprogress = function(event) {
+        var url = packageName;
+        var size = packageSize;
+        if (event.total) size = event.total;
+        if (event.loaded) {
+          if (!xhr.addedTotal) {
+            xhr.addedTotal = true;
+            if (!Module.dataFileDownloads) Module.dataFileDownloads = {};
+            Module.dataFileDownloads[url] = {
+              loaded: event.loaded,
+              total: size
+            };
+          } else {
+            Module.dataFileDownloads[url].loaded = event.loaded;
+          }
+          var total = 0;
+          var loaded = 0;
+          var num = 0;
+          for (var download in Module.dataFileDownloads) {
+          var data = Module.dataFileDownloads[download];
+            total += data.total;
+            loaded += data.loaded;
+            num++;
+          }
+          total = Math.ceil(total * Module.expectedDataFileDownloads/num);
+          if (Module['setStatus']) Module['setStatus']('Downloading data... (' + loaded + '/' + total + ')');
+        } else if (!Module.dataFileDownloads) {
+          if (Module['setStatus']) Module['setStatus']('Downloading data...');
+        }
+      };
+      xhr.onload = function(event) {
+        var packageData = xhr.response;
+        callback(packageData);
+      };
+      xhr.send(null);
+    };
+
+    function handleError(error) {
+      console.error('package error:', error);
+    };
+  
+      var fetched = null, fetchedCallback = null;
+      fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, function(data) {
+        if (fetchedCallback) {
+          fetchedCallback(data);
+          fetchedCallback = null;
+        } else {
+          fetched = data;
+        }
+      }, handleError);
+    
+  function runWithFS() {
+
+function assert(check, msg) {
+  if (!check) throw msg + new Error().stack;
+}
+
+    function DataRequest(start, end, crunched, audio) {
+      this.start = start;
+      this.end = end;
+      this.crunched = crunched;
+      this.audio = audio;
+    }
+    DataRequest.prototype = {
+      requests: {},
+      open: function(mode, name) {
+        this.name = name;
+        this.requests[name] = this;
+        Module['addRunDependency']('fp ' + this.name);
+      },
+      send: function() {},
+      onload: function() {
+        var byteArray = this.byteArray.subarray(this.start, this.end);
+
+          this.finish(byteArray);
+
+      },
+      finish: function(byteArray) {
+        var that = this;
+        Module['FS_createPreloadedFile'](this.name, null, byteArray, true, true, function() {
+          Module['removeRunDependency']('fp ' + that.name);
+        }, function() {
+          if (that.audio) {
+            Module['removeRunDependency']('fp ' + that.name); // workaround for chromium bug 124926 (still no audio with this, but at least we don't hang)
+          } else {
+            Module.printErr('Preloading file ' + that.name + ' failed');
+          }
+        }, false, true); // canOwn this data in the filesystem, it is a slide into the heap that will never change
+        this.requests[this.name] = null;
+      },
+    };
+      $$ATOMIC_RESOURCES_DATA_REQUEST$$
+
+    function processPackageData(arrayBuffer) {
+      Module.finishedDataFileDownloads++;
+      assert(arrayBuffer, 'Loading data file failed.');
+      var byteArray = new Uint8Array(arrayBuffer);
+      var curr;
+      
+      // copy the entire loaded file into a spot in the heap. Files will refer to slices in that. They cannot be freed though.
+      var ptr = Module['_malloc'](byteArray.length);
+      Module['HEAPU8'].set(byteArray, ptr);
+      DataRequest.prototype.byteArray = Module['HEAPU8'].subarray(ptr, ptr+byteArray.length);
+          DataRequest.prototype.requests["/AtomicResources.pak"].onload();
+          Module['removeRunDependency']('datafile_AtomicResources.data');
+
+    };
+    Module['addRunDependency']('datafile_AtomicResources.data');
+  
+    if (!Module.preloadResults) Module.preloadResults = {};
+  
+      Module.preloadResults[PACKAGE_NAME] = {fromCache: false};
+      if (fetched) {
+        processPackageData(fetched);
+        fetched = null;
+      } else {
+        fetchedCallback = processPackageData;
+      }
+    
+  }
+  if (Module['calledRun']) {
+    runWithFS();
+  } else {
+    if (!Module['preRun']) Module['preRun'] = [];
+    Module["preRun"].push(runWithFS); // FS is not initialized yet, wait for it
+  }
+
+})();

+ 9 - 4
Rakefile

@@ -55,11 +55,11 @@ namespace :web do
     end
 
     Dir.chdir(CMAKE_WEB_BUILD_FOLDER) do
-      sh "cmake -DCMAKE_TOOLCHAIN_FILE=#{$RAKE_ROOT}/CMake/Toolchains/emscripten.toolchain.cmake -DCMAKE_BUILD_TYPE=Release ../../"
+      sh "cmake -DEMSCRIPTEN=1 -DCMAKE_TOOLCHAIN_FILE=#{$RAKE_ROOT}/CMake/Toolchains/emscripten.toolchain.cmake -DCMAKE_BUILD_TYPE=Release ../../"
       sh "make -j8"
     end 
 
-    Dir.chdir("#{CMAKE_WEB_BUILD_FOLDER}/Source/Tools/AtomicPlayer") do
+    Dir.chdir("#{CMAKE_WEB_BUILD_FOLDER}/Source/AtomicPlayer") do
       sh "mv AtomicPlayer AtomicPlayer.bc"
       sh "emcc -O3 --llvm-lto 1 --memory-init-file 0 -s VERBOSE=0 -s USE_SDL=2 -s ASM_JS=1 -s ASSERTIONS=1 -s OUTLINING_LIMIT=20000 -s TOTAL_MEMORY=520093696 --closure 0 ./AtomicPlayer.bc -o  ./AtomicPlayer.html"
     end
@@ -111,7 +111,7 @@ namespace :macosx do
 
     Dir.chdir(CMAKE_MACOSX_BUILD_FOLDER) do
       sh "make -j8 JSBind"
-      sh "./Source/Tools/JSBind/JSBind #{$RAKE_ROOT}"
+      sh "./Source/Tools/JSBind/JSBind #{$RAKE_ROOT} WEB"
     end
 
 	end
@@ -179,7 +179,8 @@ end
 
 namespace :package do
 
-  task :macosx_preflight => ['macosx:clean', 
+  task :macosx_preflight => ['macosx:clean',
+                          'web:player',
                           'android:player',
                           "atomictiled:osx",
                           'macosx:editor',
@@ -235,6 +236,10 @@ namespace :package do
       FileUtils.mkdir_p("#{DEPLOYMENT_FOLDER_DST}/Android/libs/armeabi-v7a")
       sh "cp #{CMAKE_ANDROID_BUILD_FOLDER}/Source/AtomicPlayer/libAtomicPlayer.so #{DEPLOYMENT_FOLDER_DST}/Android/libs/armeabi-v7a/libAtomicPlayer.so"
 
+      # Web Deployment
+      sh "cp -r #{EDITORAPPLICATIONDATA_FOLDER_SRC}/Deployment/Web #{DEPLOYMENT_FOLDER_DST}/Web"
+      sh "cp #{CMAKE_WEB_BUILD_FOLDER}/Source/AtomicPlayer/AtomicPlayer.js #{DEPLOYMENT_FOLDER_DST}/Web/AtomicPlayer.js"
+
       sh "cp -r #{EXAMPLES_FOLDER_SRC} #{MAC_EDITOR_APP_RESOURCE_FOLDER_DST}/Examples"
       sh "cp -r #{DOCS_FOLDER_SRC} #{MAC_EDITOR_APP_RESOURCE_FOLDER_DST}/Docs"
 

+ 0 - 55
Source/AtomicPlayer/AtomicPlayer.cpp

@@ -40,63 +40,8 @@
 
 #include <Atomic/UI/TBUI.h>
 
-#ifdef EMSCRIPTEN
-
-#include "emscripten.h"
-
-class EmscriptenApp
-{
-public:
-    Atomic::SharedPtr<Atomic::Context> context_;
-    Atomic::SharedPtr<AtomicPlayer> application_;
-
-    static EmscriptenApp* sInstance_;
-
-    EmscriptenApp() : context_(new Atomic::Context()), application_(new AtomicPlayer(context_))
-    {
-        sInstance_ = this;
-    }
-
-};
-
-EmscriptenApp* EmscriptenApp::sInstance_ = NULL;
-
-static void RunFrame()
-{
-    Engine* engine = EmscriptenApp::sInstance_->application_->GetSubsystem<Engine>();
-    if (engine->IsInitialized())
-        engine->RunFrame();
-    else
-        printf("ENGINE NOT INITIALIZED\n");
-}
-
-int main(int argc, char** argv)
-{    
-    Atomic::ParseArguments(argc, argv);
-    // leak
-    new EmscriptenApp();
-
-    EmscriptenApp::sInstance_->application_->Run();
-
-    emscripten_set_main_loop(RunFrame, 0, 1);
-
-    /*
-    int firefox = EM_ASM_INT ( return ((navigator.userAgent.toLowerCase().indexOf('firefox') > -1) ? 1 : 0), 0);
-    if (firefox)
-        emscripten_set_main_loop(RunFrame, 0, 1);
-    else
-        emscripten_set_main_loop(RunFrame, 60, 1);
-*/        
-    return 0;
-}
-
-
-#else
-
 DEFINE_APPLICATION_MAIN(AtomicPlayer);
 
-#endif
-
 // fixme
 static JSVM* vm = NULL;
 static Javascript* javascript = NULL;

+ 9 - 1
Source/Tools/JSBind/JSBind.cpp

@@ -19,6 +19,7 @@ SharedPtr<Context> JSBind::context_;
 SharedPtr<FileSystem> JSBind::fileSystem_;
 SharedPtr<Engine> JSBind::engine_;
 String JSBind::ROOT_FOLDER;
+String JSBind::PLATFORM;
 
 void JSBind::Initialize()
 {
@@ -36,11 +37,18 @@ void Run(const Vector<String>& arguments)
 
     if (arguments.Size() < 1)
     {
-        ErrorExit("Usage: JSBind absolute_path_to_atomic_runtime_source_tree");
+        ErrorExit("Usage: JSBind absolute_path_to_atomic_runtime_source_tree [optional] platform");
     }
 
     JSBind::ROOT_FOLDER = arguments[0];
 
+    if (arguments.Size() > 1)
+        JSBind::PLATFORM = arguments[1];
+
+    if (JSBind::PLATFORM.Length() && JSBind::PLATFORM != "WEB")
+        ErrorExit("Platform argument only supports WEB at this time");
+
+
     if (!JSBind::fileSystem_->DirExists(JSBind::ROOT_FOLDER + "/Source/Tools/JSBind"))
     {
         ErrorExit("The given Atomic Runtime source tree is invalid");

+ 1 - 0
Source/Tools/JSBind/JSBind.h

@@ -21,5 +21,6 @@ public:
     static SharedPtr<Engine> engine_;
 
     static String ROOT_FOLDER;
+    static String PLATFORM;
 };
 

+ 24 - 4
Source/Tools/JSBind/JSBindings.cpp

@@ -42,11 +42,14 @@ void JSBindings::ParseHeaders()
 
     EmitJSModules(JSBind::ROOT_FOLDER + "/Source/Atomic/Javascript/Modules");
 
-    JSBTypeScript* ts = new JSBTypeScript();
-    ts->Emit(JSBind::ROOT_FOLDER + "/Bin/Atomic.d.ts");
+    if (JSBind::PLATFORM != "WEB")
+    {
+        JSBTypeScript* ts = new JSBTypeScript();
+        ts->Emit(JSBind::ROOT_FOLDER + "/Bin/Atomic.d.ts");
 
-    JSBDoc* jsdoc = new JSBDoc();
-    jsdoc->Emit(JSBind::ROOT_FOLDER + "/Bin/Atomic.js");
+        JSBDoc* jsdoc = new JSBDoc();
+        jsdoc->Emit(JSBind::ROOT_FOLDER + "/Bin/Atomic.js");
+    }
 }
 
 void JSBindings::EmitJSModules(const String& rootpath)
@@ -170,8 +173,25 @@ void JSBindings::Initialize()
     JSONValue json = jsonFile->GetRoot();
     JSONValue modules = json.GetChild("modules");
 
+    List<String> moduleExclusions;
+
+    if (JSBind::PLATFORM == "WEB")
+    {
+        JSONValue jmodulesExclude = json.GetChild("modulePlatformExclude");
+        JSONValue jexcludes = jmodulesExclude.GetChild("WEB");
+
+        for (unsigned i = 0; i < jexcludes.GetSize(); i++)
+        {
+            moduleExclusions.Push(jexcludes.GetString(i));
+        }
+
+    }
+
     for (unsigned i = 0; i < modules.GetSize(); i++)
     {
+        if (moduleExclusions.Contains(modules.GetString(i)))
+            continue;
+
         String moduleName = "modules/" + modules.GetString(i) + ".json";
 
         JSBModule* jsbModule = new JSBModule(this);

+ 5 - 1
Source/Tools/JSBind/modules/Modules.json

@@ -2,5 +2,9 @@
 {
 	"modules" : ["Container", "Math", "Core", "Scene", "Graphics", "Atomic2D", "Audio", 
 	"Physics", "Navigation", "Input", "UI", "Resource", "Network", "IO",
-	"Engine", "Javascript", "Environment"]
+	"Engine", "Javascript", "Environment"],
+
+	"modulePlatformExclude" : {
+		"WEB" : ["Network", "Navigation"]
+	}
 }

Some files were not shown because too many files changed in this diff