@@ -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(/>/g, ">"); | |||
//text = text.replace('\n', '<br>', 'g'); | |||
/* | |||
text = text.replace(/&/g, "&"); | |||
text = text.replace(/</g, "<"); | |||
text = text.replace(/ >/g, ">"); | |||
text = text.replace('\n', '<br>', '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) { /* */ }; | |||
</script> | |||
<!-- Copy this HTML in your site folder and put your built program script in the src. --> | |||
<!-- <script src="./my_program_script.js"></script> --> | |||
<!-- --> | |||
<script> | |||
//This call NEEDS TO BE after the .js include, because "cwrap" is set in it. | |||
<script type='text/javascript'> | |||
Module.do_wrapup(); | |||
//Parent communication datas | |||
function GetDivEmbed() { return document.getElementById('id_div_embed_data'); } | |||
function GetEmbedModule() { return Module; } | |||
parent.InitModuleVar(); | |||
Module.setStatus('Please wait, calculating load balance ...', 0, 1); | |||
</script> | |||
</body> | |||
@@ -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 | |||
@@ -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); | |||
@@ -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; } | |||
</script> | |||
@@ -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 !"); | |||
} | |||
</script> | |||
<body> | |||
@@ -1,6 +1,12 @@ | |||
<DOCTYPE html> | |||
<html> | |||
<body> | |||
<script type="text/javascript"> | |||
function GetDivEmbed() { return document.getElementById('id_div_embed_data'); } | |||
function GetEmbedModule() { return document.getElementById('id_embed_nacl_module'); } | |||
if (parent.IsUsingNaCl()) parent.NaClLoadingInit(); | |||
</script> | |||
<div id="id_div_embed_data" style="left:0px;top:0px;position:absolute;"> | |||
<embed name="name_embed_nacl_module" id="id_embed_nacl_module" width=770 height=200 src="meshviewer_nacl.nmf" type="application/x-nacl" /> | |||
</div> | |||
@@ -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 !"); | |||
} |