-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.html
182 lines (161 loc) · 5.06 KB
/
game.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Emscripten-Generated Code</title>
<style>
.emscripten {
padding-right: 0;
margin-left: auto;
margin-right: auto;
display: block;
}
textarea.emscripten {
font-family: monospace;
width: 80%;
}
div.emscripten {
text-align: center;
}
div.emscripten_border {
border: 1px solid black;
}
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten {
border: 0px none;
background-color: black;
}
.spinner {
height: 50px;
width: 50px;
margin: 0px auto;
-webkit-animation: rotation .8s linear infinite;
-moz-animation: rotation .8s linear infinite;
-o-animation: rotation .8s linear infinite;
animation: rotation 0.8s linear infinite;
border-left: 10px solid rgb(0, 150, 240);
border-right: 10px solid rgb(0, 150, 240);
border-bottom: 10px solid rgb(0, 150, 240);
border-top: 10px solid rgb(100, 0, 200);
border-radius: 100%;
background-color: rgb(200, 100, 250);
}
@-webkit-keyframes rotation {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
@-moz-keyframes rotation {
from {
-moz-transform: rotate(0deg);
}
to {
-moz-transform: rotate(360deg);
}
}
@-o-keyframes rotation {
from {
-o-transform: rotate(0deg);
}
to {
-o-transform: rotate(360deg);
}
}
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<hr/>
<figure style="overflow:visible;" id="spinner">
<div class="spinner"></div>
<center style="margin-top:0.5em"><strong>emscripten</strong></center>
</figure>
<div class="emscripten" id="status">Downloading...</div>
<div class="emscripten">
<progress value="0" max="100" id="progress" hidden=1></progress>
</div>
<div class="emscripten_border">
<canvas class="emscripten" id="canvas" width=1000 height=800 oncontextmenu="event.preventDefault()"
tabindex=-1></canvas>
</div>
<hr/>
<div class="emscripten">
<input type="checkbox" id="resize">Resize canvas
<input type="checkbox" id="pointerLock" checked>Lock/hide mouse pointer
<input type="button" value="Fullscreen" onclick="Module.requestFullscreen(document.getElementById('pointerLock').checked,
document.getElementById('resize').checked)">
</div>
<hr/>
<textarea class="emscripten" id="output" rows="8"></textarea>
<hr>
<script type="text/javascript">
</script>
<script type='text/javascript'>
var Module = {}
var addr = 0x2c84f90;
var imagedata1 = null, u8, start = performance.now();
function getaddr() {
return Module.ccall('image_data_loc', 'number', [null], [null]);
}
function meas() {
var ret = performance.now() - start;
start = performance.now();
console.debug(ret);
}
function render() {
start = performance.now();
Module._do_render();
meas();
addr = Module._image_data_loc();
const t = Module.HEAPU8.slice(addr, addr + 3200000);
meas();
u8 = new Uint8ClampedArray(t);
imagedata1 = new ImageData(u8, 1000, 800);
meas();
const ctx = document.getElementById('canvas').getContext('2d');
ctx.putImageData(imagedata1, 0, 0);
meas();
}
function render_light_view() {
for (const i of intervals) clearInterval(i);
Module._render_light_view();
addr = Module._image_data_loc();
const t = Module.HEAPU8.slice(addr, addr + 3200000);
meas();
u8 = new Uint8ClampedArray(t);
imagedata1 = new ImageData(u8, 1000, 800);
meas();
const ctx = document.getElementById('canvas').getContext('2d');
ctx.putImageData(imagedata1, 0, 0);
meas();
}
var intervals = [];
Module.onRuntimeInitialized = () => {
intervals[0] = setInterval(() => {
Module.ccall('input', 'null', [null], [null]);
}, 50);
intervals[1] = setInterval(() => {
render();
}, 300)
}
document.addEventListener('keydown', (e) => {
if(e.key==="Q") {
for (const i of intervals) clearInterval(i);
}
})
</script>
<script async type="text/javascript" src="game.js"></script>
</body>
</html>