Skip to content

Commit 6693278

Browse files
authored
Load emscripten data via a ZIP file
1 parent d9ba40b commit 6693278

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

distribution/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
0.4.22 (in development)
22
------------------------------------------------------------------------
33
- Change: [#23803] Lightning strikes and thunder happen at the same frequency independently of the game speed.
4+
- Change: [#24135] Compress Emscripten js/wasm files.
45
- Fix: [#21919] Non-recolourable cars still show colour picker.
56
- Fix: [#23108] Missing pieces on Hypercoaster and Hyper-Twister, even with the ‘all drawable track pieces’ cheat enabled.
67
- Fix: [#24013] Failure to load a scenario preview image (minimap) could lead to an uncaught exception error message.

emscripten/static/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<head>
44
<title>OpenRCT2</title>
55
<script src="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js" crossorigin=anonymous></script>
6-
<script src="openrct2.js"></script>
76
<style>
87
* { padding: 0; margin: 0; }
98
canvas {

emscripten/static/index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,46 @@
1212
if (!window.SharedArrayBuffer)
1313
{
1414
document.getElementById("loadingWebassembly").innerText = "Error! SharedArrayBuffer is not defined. This page required the CORP and COEP response headers.";
15+
return;
1516
}
1617
if (!window.WebAssembly)
1718
{
1819
document.getElementById("loadingWebassembly").innerText = "Error! This page requires WebAssembly. Please upgrade your browser or enable WebAssembly support.";
20+
return;
1921
}
2022

23+
let assets;
24+
try
25+
{
26+
let req = await fetch("openrct2.zip");
27+
if (!req.ok) {
28+
throw new Error("Response is not ok!")
29+
}
30+
let data = await req.blob();
31+
let zip = new JSZip();
32+
let contents = await zip.loadAsync(data);
33+
assets = {
34+
js: URL.createObjectURL(new Blob([await zip.file("openrct2.js").async("uint8array")], {type: 'application/json'})),
35+
wasm: URL.createObjectURL(new Blob([await zip.file("openrct2.wasm").async("uint8array")], {type: 'application/wasm'}))
36+
}
37+
}
38+
catch(e)
39+
{
40+
assets = null;
41+
console.warn("Failed to fetch openrct2.zip. Will pull not-compressed files", e);
42+
}
43+
44+
await new Promise(resolve => {
45+
const script = document.createElement("script");
46+
script.src = assets === null ? "openrct2.js" : assets.js;
47+
script.addEventListener("load", resolve);
48+
script.addEventListener("error", (e) => {
49+
document.getElementById("loadingWebassembly").innerText = "Error loading openrct2.js!";
50+
console.error(e);
51+
});
52+
document.body.appendChild(script);
53+
})
54+
2155
window.Module = await window.OPENRCT2_WEB(
2256
{
2357
noInitialRun: true,
@@ -37,6 +71,10 @@
3771
monitorRunDependencies: () => {},
3872
locateFile: function(fileName)
3973
{
74+
if (assets !== null && fileName === "openrct2.wasm")
75+
{
76+
return assets.wasm;
77+
}
4078
console.log("loading", fileName);
4179
return fileName;
4280
}

scripts/build-emscripten

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ mkdir -p www/
3434
cd www/
3535
cp -r ../openrct2.* ./
3636
cp -r ../../emscripten/static/* ./
37+
zip -r openrct2.zip ../openrct2.*

0 commit comments

Comments
 (0)