From 16872731ebc7124798f18422b10041b79a5480ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Benjamin=20=E2=80=98Touky=E2=80=99=20Huet?=
Date: Mon, 30 Sep 2013 15:40:59 +0000
Subject: [PATCH] Fixed MViewer emscripten version and also simplified some
interaction stuff.
---
src/platform/emscripten/lol_shell.html | 31 +++++++++------
test/Makefile.am | 2 +-
test/meshviewer.cpp | 2 +-
test/meshviewer_index.html | 26 +++++++++---
test/meshviewer_nacl.html | 6 +++
test/nacl_loading.js | 55 ++++++++++++--------------
6 files changed, 73 insertions(+), 49 deletions(-)
diff --git a/src/platform/emscripten/lol_shell.html b/src/platform/emscripten/lol_shell.html
index a9d6a053..e6aabacd 100644
--- a/src/platform/emscripten/lol_shell.html
+++ b/src/platform/emscripten/lol_shell.html
@@ -73,10 +73,12 @@ canvas.emscripten
{
this.text = Array.prototype.slice.call(arguments).join(' ');
// These replacements are necessary if you render to raw HTML
- //text = text.replace(/&/g, "&");
- //text = text.replace(//g, ">");
- //text = text.replace('\n', '
', 'g');
+ /*
+ text = text.replace(/&/g, "&");
+ text = text.replace(//g, ">");
+ text = text.replace('\n', '
', 'g');
+ */
this.output.value += text + "\n";
this.output.scrollTop = 99999; // focus on bottom
};
@@ -153,26 +155,31 @@ canvas.emscripten
this.wrapup_list[i].args);
}
},
+ //Module <-> Page communication setup
SendMessage:function(message)
{
this.DoSendMessage(0, message);
+ },
+ ModuleSendMessage:function(message)
+ {
+ alert(message);
}
};
- Module.setStatus('Please wait, calculating load balance ...', 0, 1);
- //Module <-> Page communication setup
- var cur_obj = (parent) ? (parent) : (this);
- cur_obj.g_embed_module = Module;
- cur_obj.SendMessageToModule = function() { this.g_embed_module.SendMessage(this.GetTextAreaCodeSrc().value); };
- cur_obj.ModuleSentMessage = function(message) { /* */ };
-
diff --git a/test/meshviewer_nacl.html b/test/meshviewer_nacl.html
index 8e952935..a9b73960 100644
--- a/test/meshviewer_nacl.html
+++ b/test/meshviewer_nacl.html
@@ -1,6 +1,12 @@
+
diff --git a/test/nacl_loading.js b/test/nacl_loading.js
index 8e1f8a7c..2acfb5c0 100644
--- a/test/nacl_loading.js
+++ b/test/nacl_loading.js
@@ -1,25 +1,28 @@
-if (IsUsingNaCl()) NaClLoadingInit();
-
-function InitNaClModuleVar() { g_embed_module = GetiFrameModuleVar(); }
-
function RegisterListener()
{
//Register all the correct functions to the listener
var div_listener = GetiFrameDivEmbed();
if (div_listener)
{
- div_listener.addEventListener('loadstart', ModuleStartedLoad, true);
- div_listener.addEventListener('load', ModuleDidLoad, true);
- div_listener.addEventListener('error', ModuleError, true);
- div_listener.addEventListener('progress', ModuleLoadUpdate, true);
- div_listener.addEventListener('message', ModuleSentMessage, true);
- div_listener.addEventListener('crash', ModuleCrash, true);
+ div_listener.addEventListener('loadstart', NaClModuleStartedLoad, true);
+ div_listener.addEventListener('load', NaClModuleDidLoad, true);
+ div_listener.addEventListener('error', NaClModuleError, true);
+ div_listener.addEventListener('progress', NaClModuleLoadUpdate, true);
+ div_listener.addEventListener('message', NaClModuleSentMessage, true);
+ div_listener.addEventListener('crash', NaClModuleCrash, true);
window.setTimeout("UpdateTextStatus(0.1)", 100);
}
else if (IsUsingNaCl())
window.setTimeout("RegisterListener()", 200);
}
+function NaClInitModuleVar()
+{
+ InitModuleVar();
+ if (g_embed_module)
+ g_embed_module['SendMessage'] = function(message) { g_embed_module.postMessage(message); }
+}
+
//-------------------------------------------------------------------------
// MODULE LOADING FUNCTIONS
//-------------------------------------------------------------------------
@@ -34,14 +37,14 @@ function NaClLoadingInit()
}
//Module starts load
-function ModuleStartedLoad()
+function NaClModuleStartedLoad()
{
AddTextStatus('Module Started Loading');
- InitNaClModuleVar();
+ NaClInitModuleVar();
}
//Module progress event
-function ModuleLoadUpdate(event)
+function NaClModuleLoadUpdate(event)
{
if (event.lengthComputable)
UpdateProgressBarValue('Please wait, loading', event.loaded, event.total);
@@ -50,10 +53,10 @@ function ModuleLoadUpdate(event)
}
//Indicate module load success.
-function ModuleDidLoad()
+function NaClModuleDidLoad()
{
if (!g_embed_module)
- InitNaClModuleVar();
+ NaClInitModuleVar();
//Hide the progress div
AddTextStatus('Module is live, thank you for your patience.');
@@ -61,21 +64,21 @@ function ModuleDidLoad()
}
//Module did crash
-function ModuleCrash(event)
+function NaClModuleCrash(event)
{
- RestartModule();
+ NaClRestartModule();
AddTextStatus("Module has crashed ! Restarting ...");
}
//Module had an error
-function ModuleError(event)
+function NaClModuleError(event)
{
- RestartModule();
+ NaClRestartModule();
AddTextStatus("Module Load/start Error ! Restarting ...");
}
//Used to restart module on crash/error/load fail ....
-function RestartModule()
+function NaClRestartModule()
{
var id_frame_embed = GetFrameData();
if (id_frame_embed)
@@ -90,16 +93,8 @@ function RestartModule()
//-------------------------------------------------------------------------
//Handle message from the NaCl module
-function ModuleSentMessage(message)
+function NaClModuleSentMessage(message)
{
- alert('Module sent message: ' + message.data);
+ ModuleSentMessage(message);
}
-//Called by the "Send Mesh Command !" button
-function SendMessageToModule()
-{
- if (g_embed_module)
- g_embed_module.postMessage(GetTextAreaCodeSrc().value);
- else
- alert("Module not loaded !");
-}