Skip to content

Commit 6bf43c5

Browse files
committed
Add online fdtd3dbench using wasm
1 parent 3ab8842 commit 6bf43c5

File tree

4 files changed

+3832
-0
lines changed

4 files changed

+3832
-0
lines changed

fdtd3dbench.html

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<!doctype html>
2+
<html lang="en-us">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6+
<title>fdtd3dbench online</title>
7+
<style>
8+
body {
9+
font-family: arial;
10+
margin: 0;
11+
padding: none;
12+
}
13+
14+
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
15+
div.emscripten { text-align: center; }
16+
17+
#status {
18+
display: inline-block;
19+
vertical-align: top;
20+
margin-top: 30px;
21+
margin-left: 20px;
22+
font-weight: bold;
23+
color: black;
24+
}
25+
26+
#progress {
27+
height: 20px;
28+
width: 300px;
29+
}
30+
31+
#output {
32+
width: 100%;
33+
height: 400px;
34+
margin: 0 auto;
35+
margin-top: 10px;
36+
border-left: 0px;
37+
border-right: 0px;
38+
padding-left: 0px;
39+
padding-right: 0px;
40+
display: block;
41+
background-color: black;
42+
color: white;
43+
font-family: 'Lucida Console', Monaco, monospace;
44+
outline: none;
45+
}
46+
</style>
47+
</head>
48+
<body>
49+
50+
<div class="emscripten" id="status">Downloading...</div>
51+
52+
<div class="emscripten">
53+
<progress value="0" max="100" id="progress" hidden=1></progress>
54+
</div>
55+
56+
<textarea id="output" rows="20"></textarea>
57+
58+
<script type='text/javascript'>
59+
var statusElement = document.getElementById('status');
60+
var progressElement = document.getElementById('progress');
61+
62+
var Module = {
63+
preRun: [],
64+
postRun: [],
65+
print: (function() {
66+
var element = document.getElementById('output');
67+
if (element) element.value = ''; // clear browser cache
68+
return function(text) {
69+
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
70+
// These replacements are necessary if you render to raw HTML
71+
//text = text.replace(/&/g, "&amp;");
72+
//text = text.replace(/</g, "&lt;");
73+
//text = text.replace(/>/g, "&gt;");
74+
//text = text.replace('\n', '<br>', 'g');
75+
console.log(text);
76+
if (element) {
77+
element.value += text + "\n";
78+
element.scrollTop = element.scrollHeight; // focus on bottom
79+
}
80+
};
81+
})(),
82+
setStatus: function(text) {
83+
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
84+
if (text === Module.setStatus.last.text) return;
85+
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
86+
var now = Date.now();
87+
if (m && now - Module.setStatus.last.time < 30) return; // if this is a progress update, skip it if too soon
88+
Module.setStatus.last.time = now;
89+
Module.setStatus.last.text = text;
90+
if (m) {
91+
text = m[1];
92+
progressElement.value = parseInt(m[2])*100;
93+
progressElement.max = parseInt(m[4])*100;
94+
progressElement.hidden = false;
95+
} else {
96+
progressElement.value = null;
97+
progressElement.max = null;
98+
progressElement.hidden = true;
99+
}
100+
statusElement.innerHTML = text;
101+
},
102+
totalDependencies: 0,
103+
monitorRunDependencies: function(left) {
104+
this.totalDependencies = Math.max(this.totalDependencies, left);
105+
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
106+
}
107+
};
108+
Module.setStatus('Downloading...');
109+
window.onerror = function(event) {
110+
// TODO: do not warn on ok events like simulating an infinite loop or exitStatus
111+
Module.setStatus('Exception thrown, see JavaScript console');
112+
Module.setStatus = function(text) {
113+
if (text) Module.printErr('[post-exception status] ' + text);
114+
};
115+
};
116+
</script>
117+
<script async type="text/javascript" src="fdtd3dbench.js"></script>
118+
</body>
119+
</html>
120+
121+

0 commit comments

Comments
 (0)