Spaces:
Running
on
A10G
Running
on
A10G
GitLab CI
commited on
Commit
·
c8cf522
1
Parent(s):
95b8b96
Update game build from GitLab CI
Browse files- server/static/godot/index.apple-touch-icon.png +0 -0
- server/static/godot/index.audio.worklet.js +2 -2
- server/static/godot/index.html +102 -151
- server/static/godot/index.icon.png +0 -0
- server/static/godot/index.js +0 -0
- server/static/godot/index.pck +0 -0
- server/static/godot/index.wasm +2 -2
- server/static/godot/index.worker.js +0 -161
server/static/godot/index.apple-touch-icon.png
CHANGED
![]() |
![]() |
server/static/godot/index.audio.worklet.js
CHANGED
@@ -167,7 +167,7 @@ class GodotProcessor extends AudioWorkletProcessor {
|
|
167 |
GodotProcessor.write_input(this.input_buffer, input);
|
168 |
this.input.write(this.input_buffer);
|
169 |
} else {
|
170 |
-
this.port.postMessage('Input buffer is full! Skipping input frame.');
|
171 |
}
|
172 |
}
|
173 |
const process_output = GodotProcessor.array_has_data(outputs);
|
@@ -184,7 +184,7 @@ class GodotProcessor extends AudioWorkletProcessor {
|
|
184 |
this.port.postMessage({ 'cmd': 'read', 'data': chunk });
|
185 |
}
|
186 |
} else {
|
187 |
-
this.port.postMessage('Output buffer has not enough frames! Skipping output frame.');
|
188 |
}
|
189 |
}
|
190 |
this.process_notify();
|
|
|
167 |
GodotProcessor.write_input(this.input_buffer, input);
|
168 |
this.input.write(this.input_buffer);
|
169 |
} else {
|
170 |
+
// this.port.postMessage('Input buffer is full! Skipping input frame.'); // Uncomment this line to debug input buffer.
|
171 |
}
|
172 |
}
|
173 |
const process_output = GodotProcessor.array_has_data(outputs);
|
|
|
184 |
this.port.postMessage({ 'cmd': 'read', 'data': chunk });
|
185 |
}
|
186 |
} else {
|
187 |
+
// this.port.postMessage('Output buffer has not enough frames! Skipping output frame.'); // Uncomment this line to debug output buffer.
|
188 |
}
|
189 |
}
|
190 |
this.process_notify();
|
server/static/godot/index.html
CHANGED
@@ -2,197 +2,125 @@
|
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<meta charset="utf-8">
|
5 |
-
<meta name="viewport" content="width=device-width, user-scalable=no">
|
6 |
<title>Magame</title>
|
7 |
<style>
|
8 |
-
body {
|
9 |
-
touch-action: none;
|
10 |
margin: 0;
|
11 |
-
border: 0 none;
|
12 |
padding: 0;
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
background-color: black;
|
|
|
|
|
15 |
}
|
16 |
|
17 |
#canvas {
|
18 |
display: block;
|
19 |
-
margin: 0;
|
20 |
-
color: white;
|
21 |
}
|
22 |
|
23 |
#canvas:focus {
|
24 |
outline: none;
|
25 |
}
|
26 |
|
27 |
-
|
28 |
-
font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
|
29 |
-
color: #e0e0e0;
|
30 |
-
background-color: #3b3943;
|
31 |
-
background-image: linear-gradient(to bottom, #403e48, #35333c);
|
32 |
-
border: 1px solid #45434e;
|
33 |
-
box-shadow: 0 0 1px 1px #2f2d35;
|
34 |
-
}
|
35 |
-
|
36 |
-
/* Status display */
|
37 |
-
|
38 |
-
#status {
|
39 |
position: absolute;
|
40 |
left: 0;
|
41 |
-
top: 0;
|
42 |
right: 0;
|
|
|
|
|
|
|
|
|
43 |
bottom: 0;
|
|
|
|
|
|
|
|
|
44 |
display: flex;
|
|
|
45 |
justify-content: center;
|
46 |
align-items: center;
|
47 |
-
/* don't consume click events - make children visible explicitly */
|
48 |
visibility: hidden;
|
49 |
}
|
50 |
|
51 |
-
#status-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
border: 1px solid #444246;
|
56 |
-
padding: 1px;
|
57 |
-
box-shadow: 0 0 2px 1px #1B1C22;
|
58 |
-
border-radius: 2px;
|
59 |
-
visibility: visible;
|
60 |
-
}
|
61 |
-
|
62 |
-
@media only screen and (orientation:portrait) {
|
63 |
-
#status-progress {
|
64 |
-
width: 61.8%;
|
65 |
-
}
|
66 |
-
}
|
67 |
-
|
68 |
-
#status-progress-inner {
|
69 |
-
height: 100%;
|
70 |
-
width: 0;
|
71 |
-
box-sizing: border-box;
|
72 |
-
transition: width 0.5s linear;
|
73 |
-
background-color: #202020;
|
74 |
-
border: 1px solid #222223;
|
75 |
-
box-shadow: 0 0 1px 1px #27282E;
|
76 |
-
border-radius: 3px;
|
77 |
}
|
78 |
|
79 |
-
#status-
|
80 |
-
|
81 |
-
visibility: visible;
|
82 |
-
position: relative;
|
83 |
}
|
84 |
|
85 |
-
#status-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
border-width: 9px 3px 0 3px;
|
90 |
-
border-color: #2b2b2b transparent transparent transparent;
|
91 |
-
transform-origin: center 21px;
|
92 |
-
position: absolute;
|
93 |
}
|
94 |
|
95 |
-
#status-indeterminate > div:nth-child(1) { transform: rotate( 22.5deg); }
|
96 |
-
#status-indeterminate > div:nth-child(2) { transform: rotate( 67.5deg); }
|
97 |
-
#status-indeterminate > div:nth-child(3) { transform: rotate(112.5deg); }
|
98 |
-
#status-indeterminate > div:nth-child(4) { transform: rotate(157.5deg); }
|
99 |
-
#status-indeterminate > div:nth-child(5) { transform: rotate(202.5deg); }
|
100 |
-
#status-indeterminate > div:nth-child(6) { transform: rotate(247.5deg); }
|
101 |
-
#status-indeterminate > div:nth-child(7) { transform: rotate(292.5deg); }
|
102 |
-
#status-indeterminate > div:nth-child(8) { transform: rotate(337.5deg); }
|
103 |
-
|
104 |
#status-notice {
|
105 |
-
|
|
|
|
|
|
|
|
|
106 |
line-height: 1.3;
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
110 |
}
|
111 |
</style>
|
112 |
-
<link id=
|
113 |
-
<link rel=
|
114 |
|
115 |
</head>
|
116 |
<body>
|
117 |
<canvas id="canvas">
|
118 |
-
|
119 |
-
Please try updating or use a different browser.
|
120 |
</canvas>
|
|
|
|
|
|
|
|
|
|
|
121 |
<div id="status">
|
122 |
-
<
|
123 |
-
|
124 |
-
|
125 |
-
<div id="status-indeterminate" style="display: none;" oncontextmenu="event.preventDefault();">
|
126 |
-
<div></div>
|
127 |
-
<div></div>
|
128 |
-
<div></div>
|
129 |
-
<div></div>
|
130 |
-
<div></div>
|
131 |
-
<div></div>
|
132 |
-
<div></div>
|
133 |
-
<div></div>
|
134 |
-
</div>
|
135 |
-
<div id="status-notice" class="godot" style="display: none;"></div>
|
136 |
</div>
|
137 |
|
138 |
<script src="index.js"></script>
|
139 |
<script>
|
140 |
-
const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":
|
|
|
141 |
const engine = new Engine(GODOT_CONFIG);
|
142 |
|
143 |
(function () {
|
144 |
-
const
|
145 |
const statusProgress = document.getElementById('status-progress');
|
146 |
-
const statusProgressInner = document.getElementById('status-progress-inner');
|
147 |
-
const statusIndeterminate = document.getElementById('status-indeterminate');
|
148 |
const statusNotice = document.getElementById('status-notice');
|
149 |
|
150 |
let initializing = true;
|
151 |
-
let statusMode = '
|
152 |
-
|
153 |
-
let animationCallbacks = [];
|
154 |
-
function animate(time) {
|
155 |
-
animationCallbacks.forEach((callback) => callback(time));
|
156 |
-
requestAnimationFrame(animate);
|
157 |
-
}
|
158 |
-
requestAnimationFrame(animate);
|
159 |
-
|
160 |
-
function animateStatusIndeterminate(ms) {
|
161 |
-
const i = Math.floor((ms / INDETERMINATE_STATUS_STEP_MS) % 8);
|
162 |
-
if (statusIndeterminate.children[i].style.borderTopColor === '') {
|
163 |
-
Array.prototype.slice.call(statusIndeterminate.children).forEach((child) => {
|
164 |
-
child.style.borderTopColor = '';
|
165 |
-
});
|
166 |
-
statusIndeterminate.children[i].style.borderTopColor = '#dfdfdf';
|
167 |
-
}
|
168 |
-
}
|
169 |
|
170 |
function setStatusMode(mode) {
|
171 |
if (statusMode === mode || !initializing) {
|
172 |
return;
|
173 |
}
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
return (value !== animateStatusIndeterminate);
|
179 |
-
});
|
180 |
-
switch (mode) {
|
181 |
-
case 'progress':
|
182 |
-
statusProgress.style.display = 'block';
|
183 |
-
break;
|
184 |
-
case 'indeterminate':
|
185 |
-
statusIndeterminate.style.display = 'block';
|
186 |
-
animationCallbacks.push(animateStatusIndeterminate);
|
187 |
-
break;
|
188 |
-
case 'notice':
|
189 |
-
statusNotice.style.display = 'block';
|
190 |
-
break;
|
191 |
-
case 'hidden':
|
192 |
-
break;
|
193 |
-
default:
|
194 |
-
throw new Error('Invalid status mode');
|
195 |
}
|
|
|
|
|
|
|
196 |
statusMode = mode;
|
197 |
}
|
198 |
|
@@ -208,37 +136,60 @@ const engine = new Engine(GODOT_CONFIG);
|
|
208 |
}
|
209 |
|
210 |
function displayFailureNotice(err) {
|
211 |
-
|
212 |
-
|
213 |
-
|
|
|
|
|
|
|
|
|
|
|
214 |
setStatusMode('notice');
|
215 |
initializing = false;
|
216 |
}
|
217 |
|
218 |
-
const missing = Engine.getMissingFeatures(
|
|
|
|
|
|
|
219 |
if (missing.length !== 0) {
|
220 |
-
|
221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
} else {
|
223 |
-
setStatusMode('
|
224 |
engine.startGame({
|
225 |
'onProgress': function (current, total) {
|
226 |
-
if (total > 0) {
|
227 |
-
|
228 |
-
|
229 |
-
if (current === total) {
|
230 |
-
// wait for progress bar animation
|
231 |
-
setTimeout(() => {
|
232 |
-
setStatusMode('indeterminate');
|
233 |
-
}, 500);
|
234 |
-
}
|
235 |
} else {
|
236 |
-
|
|
|
237 |
}
|
238 |
},
|
239 |
}).then(() => {
|
240 |
setStatusMode('hidden');
|
241 |
-
initializing = false;
|
242 |
}, displayFailureNotice);
|
243 |
}
|
244 |
}());
|
|
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
<meta charset="utf-8">
|
5 |
+
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
|
6 |
<title>Magame</title>
|
7 |
<style>
|
8 |
+
html, body, #canvas {
|
|
|
9 |
margin: 0;
|
|
|
10 |
padding: 0;
|
11 |
+
border: 0;
|
12 |
+
}
|
13 |
+
|
14 |
+
body {
|
15 |
+
color: white;
|
16 |
background-color: black;
|
17 |
+
overflow: hidden;
|
18 |
+
touch-action: none;
|
19 |
}
|
20 |
|
21 |
#canvas {
|
22 |
display: block;
|
|
|
|
|
23 |
}
|
24 |
|
25 |
#canvas:focus {
|
26 |
outline: none;
|
27 |
}
|
28 |
|
29 |
+
#status, #status-splash, #status-progress {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
position: absolute;
|
31 |
left: 0;
|
|
|
32 |
right: 0;
|
33 |
+
}
|
34 |
+
|
35 |
+
#status, #status-splash {
|
36 |
+
top: 0;
|
37 |
bottom: 0;
|
38 |
+
}
|
39 |
+
|
40 |
+
#status {
|
41 |
+
background-color: #242424;
|
42 |
display: flex;
|
43 |
+
flex-direction: column;
|
44 |
justify-content: center;
|
45 |
align-items: center;
|
|
|
46 |
visibility: hidden;
|
47 |
}
|
48 |
|
49 |
+
#status-splash {
|
50 |
+
max-height: 100%;
|
51 |
+
max-width: 100%;
|
52 |
+
margin: auto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
54 |
|
55 |
+
#status-progress, #status-notice {
|
56 |
+
display: none;
|
|
|
|
|
57 |
}
|
58 |
|
59 |
+
#status-progress {
|
60 |
+
bottom: 10%;
|
61 |
+
width: 50%;
|
62 |
+
margin: 0 auto;
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
#status-notice {
|
66 |
+
background-color: #5b3943;
|
67 |
+
border-radius: 0.5rem;
|
68 |
+
border: 1px solid #9b3943;
|
69 |
+
color: #e0e0e0;
|
70 |
+
font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
|
71 |
line-height: 1.3;
|
72 |
+
margin: 0 2rem;
|
73 |
+
overflow: hidden;
|
74 |
+
padding: 1rem;
|
75 |
+
text-align: center;
|
76 |
+
z-index: 1;
|
77 |
}
|
78 |
</style>
|
79 |
+
<link id="-gd-engine-icon" rel="icon" type="image/png" href="index.icon.png" />
|
80 |
+
<link rel="apple-touch-icon" href="index.apple-touch-icon.png"/>
|
81 |
|
82 |
</head>
|
83 |
<body>
|
84 |
<canvas id="canvas">
|
85 |
+
Your browser does not support the canvas tag.
|
|
|
86 |
</canvas>
|
87 |
+
|
88 |
+
<noscript>
|
89 |
+
Your browser does not support JavaScript.
|
90 |
+
</noscript>
|
91 |
+
|
92 |
<div id="status">
|
93 |
+
<img id="status-splash" src="index.png" alt="">
|
94 |
+
<progress id="status-progress"></progress>
|
95 |
+
<div id="status-notice"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
</div>
|
97 |
|
98 |
<script src="index.js"></script>
|
99 |
<script>
|
100 |
+
const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"ensureCrossOriginIsolationHeaders":false,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":210672,"index.wasm":35376909},"focusCanvas":true,"gdextensionLibs":[]};
|
101 |
+
const GODOT_THREADS_ENABLED = false;
|
102 |
const engine = new Engine(GODOT_CONFIG);
|
103 |
|
104 |
(function () {
|
105 |
+
const statusOverlay = document.getElementById('status');
|
106 |
const statusProgress = document.getElementById('status-progress');
|
|
|
|
|
107 |
const statusNotice = document.getElementById('status-notice');
|
108 |
|
109 |
let initializing = true;
|
110 |
+
let statusMode = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
function setStatusMode(mode) {
|
113 |
if (statusMode === mode || !initializing) {
|
114 |
return;
|
115 |
}
|
116 |
+
if (mode === 'hidden') {
|
117 |
+
statusOverlay.remove();
|
118 |
+
initializing = false;
|
119 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
}
|
121 |
+
statusOverlay.style.visibility = 'visible';
|
122 |
+
statusProgress.style.display = mode === 'progress' ? 'block' : 'none';
|
123 |
+
statusNotice.style.display = mode === 'notice' ? 'block' : 'none';
|
124 |
statusMode = mode;
|
125 |
}
|
126 |
|
|
|
136 |
}
|
137 |
|
138 |
function displayFailureNotice(err) {
|
139 |
+
console.error(err);
|
140 |
+
if (err instanceof Error) {
|
141 |
+
setStatusNotice(err.message);
|
142 |
+
} else if (typeof err === 'string') {
|
143 |
+
setStatusNotice(err);
|
144 |
+
} else {
|
145 |
+
setStatusNotice('An unknown error occured');
|
146 |
+
}
|
147 |
setStatusMode('notice');
|
148 |
initializing = false;
|
149 |
}
|
150 |
|
151 |
+
const missing = Engine.getMissingFeatures({
|
152 |
+
threads: GODOT_THREADS_ENABLED,
|
153 |
+
});
|
154 |
+
|
155 |
if (missing.length !== 0) {
|
156 |
+
if (GODOT_CONFIG['serviceWorker'] && GODOT_CONFIG['ensureCrossOriginIsolationHeaders'] && 'serviceWorker' in navigator) {
|
157 |
+
// There's a chance that installing the service worker would fix the issue
|
158 |
+
Promise.race([
|
159 |
+
navigator.serviceWorker.getRegistration().then((registration) => {
|
160 |
+
if (registration != null) {
|
161 |
+
return Promise.reject(new Error('Service worker already exists.'));
|
162 |
+
}
|
163 |
+
return registration;
|
164 |
+
}).then(() => engine.installServiceWorker()),
|
165 |
+
// For some reason, `getRegistration()` can stall
|
166 |
+
new Promise((resolve) => {
|
167 |
+
setTimeout(() => resolve(), 2000);
|
168 |
+
}),
|
169 |
+
]).catch((err) => {
|
170 |
+
console.error('Error while registering service worker:', err);
|
171 |
+
}).then(() => {
|
172 |
+
window.location.reload();
|
173 |
+
});
|
174 |
+
} else {
|
175 |
+
// Display the message as usual
|
176 |
+
const missingMsg = 'Error\nThe following features required to run Godot projects on the Web are missing:\n';
|
177 |
+
displayFailureNotice(missingMsg + missing.join('\n'));
|
178 |
+
}
|
179 |
} else {
|
180 |
+
setStatusMode('progress');
|
181 |
engine.startGame({
|
182 |
'onProgress': function (current, total) {
|
183 |
+
if (current > 0 && total > 0) {
|
184 |
+
statusProgress.value = current;
|
185 |
+
statusProgress.max = total;
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
} else {
|
187 |
+
statusProgress.removeAttribute('value');
|
188 |
+
statusProgress.removeAttribute('max');
|
189 |
}
|
190 |
},
|
191 |
}).then(() => {
|
192 |
setStatusMode('hidden');
|
|
|
193 |
}, displayFailureNotice);
|
194 |
}
|
195 |
}());
|
server/static/godot/index.icon.png
CHANGED
![]() |
![]() |
server/static/godot/index.js
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
server/static/godot/index.pck
CHANGED
Binary files a/server/static/godot/index.pck and b/server/static/godot/index.pck differ
|
|
server/static/godot/index.wasm
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fe5cebc590758c10bc4469be5a591e28edbde5ec8f458f21baeb83db50d028b9
|
3 |
+
size 35376909
|
server/static/godot/index.worker.js
DELETED
@@ -1,161 +0,0 @@
|
|
1 |
-
/**
|
2 |
-
* @license
|
3 |
-
* Copyright 2015 The Emscripten Authors
|
4 |
-
* SPDX-License-Identifier: MIT
|
5 |
-
*/
|
6 |
-
|
7 |
-
// Pthread Web Worker startup routine:
|
8 |
-
// This is the entry point file that is loaded first by each Web Worker
|
9 |
-
// that executes pthreads on the Emscripten application.
|
10 |
-
|
11 |
-
'use strict';
|
12 |
-
|
13 |
-
var Module = {};
|
14 |
-
|
15 |
-
// Thread-local guard variable for one-time init of the JS state
|
16 |
-
var initializedJS = false;
|
17 |
-
|
18 |
-
function assert(condition, text) {
|
19 |
-
if (!condition) abort('Assertion failed: ' + text);
|
20 |
-
}
|
21 |
-
|
22 |
-
function threadPrintErr() {
|
23 |
-
var text = Array.prototype.slice.call(arguments).join(' ');
|
24 |
-
console.error(text);
|
25 |
-
}
|
26 |
-
function threadAlert() {
|
27 |
-
var text = Array.prototype.slice.call(arguments).join(' ');
|
28 |
-
postMessage({cmd: 'alert', text: text, threadId: Module['_pthread_self']()});
|
29 |
-
}
|
30 |
-
// We don't need out() for now, but may need to add it if we want to use it
|
31 |
-
// here. Or, if this code all moves into the main JS, that problem will go
|
32 |
-
// away. (For now, adding it here increases code size for no benefit.)
|
33 |
-
var out = () => { throw 'out() is not defined in worker.js.'; }
|
34 |
-
var err = threadPrintErr;
|
35 |
-
self.alert = threadAlert;
|
36 |
-
|
37 |
-
Module['instantiateWasm'] = (info, receiveInstance) => {
|
38 |
-
// Instantiate from the module posted from the main thread.
|
39 |
-
// We can just use sync instantiation in the worker.
|
40 |
-
var module = Module['wasmModule'];
|
41 |
-
// We don't need the module anymore; new threads will be spawned from the main thread.
|
42 |
-
Module['wasmModule'] = null;
|
43 |
-
var instance = new WebAssembly.Instance(module, info);
|
44 |
-
// TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193,
|
45 |
-
// the above line no longer optimizes out down to the following line.
|
46 |
-
// When the regression is fixed, we can remove this if/else.
|
47 |
-
return receiveInstance(instance);
|
48 |
-
}
|
49 |
-
|
50 |
-
// Turn unhandled rejected promises into errors so that the main thread will be
|
51 |
-
// notified about them.
|
52 |
-
self.onunhandledrejection = (e) => {
|
53 |
-
throw e.reason ?? e;
|
54 |
-
};
|
55 |
-
|
56 |
-
function handleMessage(e) {
|
57 |
-
try {
|
58 |
-
if (e.data.cmd === 'load') { // Preload command that is called once per worker to parse and load the Emscripten code.
|
59 |
-
|
60 |
-
// Until we initialize the runtime, queue up any further incoming messages.
|
61 |
-
let messageQueue = [];
|
62 |
-
self.onmessage = (e) => messageQueue.push(e);
|
63 |
-
|
64 |
-
// And add a callback for when the runtime is initialized.
|
65 |
-
self.startWorker = (instance) => {
|
66 |
-
Module = instance;
|
67 |
-
// Notify the main thread that this thread has loaded.
|
68 |
-
postMessage({ 'cmd': 'loaded' });
|
69 |
-
// Process any messages that were queued before the thread was ready.
|
70 |
-
for (let msg of messageQueue) {
|
71 |
-
handleMessage(msg);
|
72 |
-
}
|
73 |
-
// Restore the real message handler.
|
74 |
-
self.onmessage = handleMessage;
|
75 |
-
};
|
76 |
-
|
77 |
-
// Module and memory were sent from main thread
|
78 |
-
Module['wasmModule'] = e.data.wasmModule;
|
79 |
-
|
80 |
-
// Use `const` here to ensure that the variable is scoped only to
|
81 |
-
// that iteration, allowing safe reference from a closure.
|
82 |
-
for (const handler of e.data.handlers) {
|
83 |
-
Module[handler] = function() {
|
84 |
-
postMessage({ cmd: 'callHandler', handler, args: [...arguments] });
|
85 |
-
}
|
86 |
-
}
|
87 |
-
|
88 |
-
Module['wasmMemory'] = e.data.wasmMemory;
|
89 |
-
|
90 |
-
Module['buffer'] = Module['wasmMemory'].buffer;
|
91 |
-
|
92 |
-
Module['workerID'] = e.data.workerID;
|
93 |
-
|
94 |
-
Module['ENVIRONMENT_IS_PTHREAD'] = true;
|
95 |
-
|
96 |
-
if (typeof e.data.urlOrBlob == 'string') {
|
97 |
-
importScripts(e.data.urlOrBlob);
|
98 |
-
} else {
|
99 |
-
var objectUrl = URL.createObjectURL(e.data.urlOrBlob);
|
100 |
-
importScripts(objectUrl);
|
101 |
-
URL.revokeObjectURL(objectUrl);
|
102 |
-
}
|
103 |
-
Godot(Module);
|
104 |
-
} else if (e.data.cmd === 'run') {
|
105 |
-
// Pass the thread address to wasm to store it for fast access.
|
106 |
-
Module['__emscripten_thread_init'](e.data.pthread_ptr, /*isMainBrowserThread=*/0, /*isMainRuntimeThread=*/0, /*canBlock=*/1);
|
107 |
-
|
108 |
-
// Await mailbox notifications with `Atomics.waitAsync` so we can start
|
109 |
-
// using the fast `Atomics.notify` notification path.
|
110 |
-
Module['__emscripten_thread_mailbox_await'](e.data.pthread_ptr);
|
111 |
-
|
112 |
-
assert(e.data.pthread_ptr);
|
113 |
-
// Also call inside JS module to set up the stack frame for this pthread in JS module scope
|
114 |
-
Module['establishStackSpace']();
|
115 |
-
Module['PThread'].receiveObjectTransfer(e.data);
|
116 |
-
Module['PThread'].threadInitTLS();
|
117 |
-
|
118 |
-
if (!initializedJS) {
|
119 |
-
initializedJS = true;
|
120 |
-
}
|
121 |
-
|
122 |
-
try {
|
123 |
-
Module['invokeEntryPoint'](e.data.start_routine, e.data.arg);
|
124 |
-
} catch(ex) {
|
125 |
-
if (ex != 'unwind') {
|
126 |
-
// The pthread "crashed". Do not call `_emscripten_thread_exit` (which
|
127 |
-
// would make this thread joinable). Instead, re-throw the exception
|
128 |
-
// and let the top level handler propagate it back to the main thread.
|
129 |
-
throw ex;
|
130 |
-
}
|
131 |
-
}
|
132 |
-
} else if (e.data.cmd === 'cancel') { // Main thread is asking for a pthread_cancel() on this thread.
|
133 |
-
if (Module['_pthread_self']()) {
|
134 |
-
Module['__emscripten_thread_exit'](-1);
|
135 |
-
}
|
136 |
-
} else if (e.data.target === 'setimmediate') {
|
137 |
-
// no-op
|
138 |
-
} else if (e.data.cmd === 'checkMailbox') {
|
139 |
-
if (initializedJS) {
|
140 |
-
Module['checkMailbox']();
|
141 |
-
}
|
142 |
-
} else if (e.data.cmd) {
|
143 |
-
// The received message looks like something that should be handled by this message
|
144 |
-
// handler, (since there is a e.data.cmd field present), but is not one of the
|
145 |
-
// recognized commands:
|
146 |
-
err('worker.js received unknown command ' + e.data.cmd);
|
147 |
-
err(e.data);
|
148 |
-
}
|
149 |
-
} catch(ex) {
|
150 |
-
err('worker.js onmessage() captured an uncaught exception: ' + ex);
|
151 |
-
if (ex && ex.stack) err(ex.stack);
|
152 |
-
if (Module['__emscripten_thread_crashed']) {
|
153 |
-
Module['__emscripten_thread_crashed']();
|
154 |
-
}
|
155 |
-
throw ex;
|
156 |
-
}
|
157 |
-
};
|
158 |
-
|
159 |
-
self.onmessage = handleMessage;
|
160 |
-
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|