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/Makefile.am b/test/Makefile.am index 264bdba1..8ea3c441 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -61,7 +61,7 @@ meshviewer_SOURCES = meshviewer.cpp \ shinymvtexture.lolfx shinyfur.lolfx meshviewer_CPPFLAGS = $(AM_CPPFLAGS) meshviewer_DEPENDENCIES = @LOL_DEPS@ -meshviewer_LDFLAGS = $(AM_LDFLAGS) +meshviewer_LDFLAGS = $(AM_LDFLAGS) -s if USE_EMSCRIPTEN meshviewer_LDFLAGS += -s EXPORTED_FUNCTIONS="['_main', '_C_Send']" endif diff --git a/test/meshviewer.cpp b/test/meshviewer.cpp index b935f37f..f06d1aeb 100644 --- a/test/meshviewer.cpp +++ b/test/meshviewer.cpp @@ -231,7 +231,7 @@ public: vec2 rot = (!is_pos && !is_fov)?(tmp):(vec2(.0f)); rot = vec2(rot.x, rot.y); vec2 pos = (is_pos && !is_fov)?(tmp):(vec2(.0f)); pos = -vec2(pos.y, pos.x); vec2 fov = (!is_pos && is_fov)?(tmp):(vec2(.0f)); fov = vec2(-fov.x, fov.y); - vec2 hsc = vec2(0.f); + vec2 hsc = (is_hsc)?(vec2(0.f)):(vec2(0.f)); //speed m_rot_speed = damp(m_rot_speed, rot * ROT_SPEED, .2f, seconds); diff --git a/test/meshviewer_index.html b/test/meshviewer_index.html index 54a0467a..b5fb86b9 100644 --- a/test/meshviewer_index.html +++ b/test/meshviewer_index.html @@ -102,9 +102,9 @@ progress::-webkit-progress-value g_var_progress_bar = -1; g_frame_embed = null; //This is the module pointer : can be either the NaCl or Em one depending on the context. - g_embed_module = null; - + g_embed_module = null; +function machinchose() { return 'test machin '; } function GetTextAreaCodeSrc() { return g_txtarea_code_src; } function GetDivProgress() { return g_div_progress; } function GetProgressBar() { return g_progress_bar; } @@ -112,10 +112,11 @@ progress::-webkit-progress-value function GetDivEmbedData() { return g_div_frame_embed; } function GetDivEmbedDataSave() { return g_div_frame_embed_save; } function GetFrameData() { return g_frame_embed; } - function GetiFrameDivEmbed() { return g_frame_embed.contentDocument.getElementById('id_div_embed_data'); } - //NaCl Specific - function GetiFrameModuleVar() { return g_frame_embed.contentDocument.getElementById('id_embed_nacl_module'); } + //Communication with iframe content. + function InitModuleVar() { g_embed_module = GetiFrameModuleVar(); } + function GetiFrameDivEmbed() { return (!g_frame_embed) ? (null) : (g_frame_embed.contentWindow.GetDivEmbed()); } + function GetiFrameModuleVar() { return (!g_frame_embed) ? (null) : (g_frame_embed.contentWindow.GetEmbedModule()); } function IsUsingNaCl() { return window.chrome; } @@ -203,6 +204,21 @@ progress::-webkit-progress-value var div_vars = g_div_helper_vars; CmdLookup(div_cmds, div_args, div_cmnt, div_vars, text_src); } + + //Handle message from the NaCl module + function ModuleSentMessage(message) + { + alert('Module sent message: ' + message.data); + } + + //Called by the "Send Mesh Command !" button + function SendMessageToModule() + { + if (g_embed_module) + g_embed_module.SendMessage(GetTextAreaCodeSrc().value); + else + alert("Module not loaded !"); + } 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 !"); -}