Skip to content

Commit

Permalink
[HTML] Added HelloGame to HTML examples and updated Fonts HTML example.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBanana committed Oct 18, 2024
1 parent 0f8acca commit 88e1414
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 2 deletions.
Binary file modified docu/WebPage/Example_Fonts/Example_Fonts.data
Binary file not shown.
2 changes: 1 addition & 1 deletion docu/WebPage/Example_Fonts/Example_Fonts.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,6 @@ Module['FS_createPath']("/", "assets", true, true);
}

}
loadPackage({"files": [{"filename": "/assets/Example.450core.frag", "start": 0, "end": 397}, {"filename": "/assets/Example.450core.vert", "start": 397, "end": 1132}, {"filename": "/assets/Example.frag", "start": 1132, "end": 1410}, {"filename": "/assets/Example.vert", "start": 1410, "end": 2023}, {"filename": "/assets/FontAtlas_CourierNew_Bold_16.png", "start": 2023, "end": 6743}, {"filename": "/assets/FontAtlas_LucidaConsole_Bold_32.png", "start": 6743, "end": 19031}], "remote_package_size": 19031});
loadPackage({"files": [{"filename": "/assets/Black.atlas-23.map", "start": 0, "end": 2370}, {"filename": "/assets/Black.atlas-23.png", "start": 2370, "end": 26674}, {"filename": "/assets/Black.atlas-50.map", "start": 26674, "end": 29201}, {"filename": "/assets/Black.atlas-50.png", "start": 29201, "end": 89868}, {"filename": "/assets/Example.450core.frag", "start": 89868, "end": 90265}, {"filename": "/assets/Example.450core.vert", "start": 90265, "end": 90989}, {"filename": "/assets/Example.frag", "start": 90989, "end": 91267}, {"filename": "/assets/Example.vert", "start": 91267, "end": 91849}, {"filename": "/assets/FontAtlas_CourierNew_Bold_16.png", "start": 91849, "end": 96569}, {"filename": "/assets/FontAtlas_LucidaConsole_Bold_32.png", "start": 96569, "end": 108857}, {"filename": "/assets/Tuffy.atlas-12.map", "start": 108857, "end": 111080}, {"filename": "/assets/Tuffy.atlas-12.png", "start": 111080, "end": 121663}, {"filename": "/assets/Tuffy.atlas-23.map", "start": 121663, "end": 123992}, {"filename": "/assets/Tuffy.atlas-23.png", "start": 123992, "end": 143898}], "remote_package_size": 143898});

})();
2 changes: 1 addition & 1 deletion docu/WebPage/Example_Fonts/Example_Fonts.js

Large diffs are not rendered by default.

Binary file modified docu/WebPage/Example_Fonts/Example_Fonts.wasm
Binary file not shown.
Binary file not shown.
179 changes: 179 additions & 0 deletions docu/WebPage/Example_HelloGame/Example_HelloGame.data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@

var Module = typeof Module !== 'undefined' ? Module : {};

if (!Module.expectedDataFileDownloads) {
Module.expectedDataFileDownloads = 0;
}

Module.expectedDataFileDownloads++;
(function() {
// Do not attempt to redownload the virtual filesystem data when in a pthread or a Wasm Worker context.
if (Module['ENVIRONMENT_IS_PTHREAD'] || Module['$ww']) return;
var loadPackage = function(metadata) {

var PACKAGE_PATH = '';
if (typeof window === 'object') {
PACKAGE_PATH = window['encodeURIComponent'](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf('/')) + '/');
} else if (typeof process === 'undefined' && typeof location !== 'undefined') {
// web worker
PACKAGE_PATH = encodeURIComponent(location.pathname.toString().substring(0, location.pathname.toString().lastIndexOf('/')) + '/');
}
var PACKAGE_NAME = 'Example_HelloGame.data';
var REMOTE_PACKAGE_BASE = 'Example_HelloGame.data';
if (typeof Module['locateFilePackage'] === 'function' && !Module['locateFile']) {
Module['locateFile'] = Module['locateFilePackage'];
err('warning: you defined Module.locateFilePackage, that has been renamed to Module.locateFile (using your locateFilePackage for now)');
}
var REMOTE_PACKAGE_NAME = Module['locateFile'] ? Module['locateFile'](REMOTE_PACKAGE_BASE, '') : REMOTE_PACKAGE_BASE;
var REMOTE_PACKAGE_SIZE = metadata['remote_package_size'];

function fetchRemotePackage(packageName, packageSize, callback, errback) {
if (typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string') {
require('fs').readFile(packageName, function(err, contents) {
if (err) {
errback(err);
} else {
callback(contents.buffer);
}
});
return;
}
var xhr = new XMLHttpRequest();
xhr.open('GET', packageName, true);
xhr.responseType = 'arraybuffer';
xhr.onprogress = function(event) {
var url = packageName;
var size = packageSize;
if (event.total) size = event.total;
if (event.loaded) {
if (!xhr.addedTotal) {
xhr.addedTotal = true;
if (!Module.dataFileDownloads) Module.dataFileDownloads = {};
Module.dataFileDownloads[url] = {
loaded: event.loaded,
total: size
};
} else {
Module.dataFileDownloads[url].loaded = event.loaded;
}
var total = 0;
var loaded = 0;
var num = 0;
for (var download in Module.dataFileDownloads) {
var data = Module.dataFileDownloads[download];
total += data.total;
loaded += data.loaded;
num++;
}
total = Math.ceil(total * Module.expectedDataFileDownloads/num);
if (Module['setStatus']) Module['setStatus'](`Downloading data... (${loaded}/${total})`);
} else if (!Module.dataFileDownloads) {
if (Module['setStatus']) Module['setStatus']('Downloading data...');
}
};
xhr.onerror = function(event) {
throw new Error("NetworkError for: " + packageName);
}
xhr.onload = function(event) {
if (xhr.status == 200 || xhr.status == 304 || xhr.status == 206 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
var packageData = xhr.response;
callback(packageData);
} else {
throw new Error(xhr.statusText + " : " + xhr.responseURL);
}
};
xhr.send(null);
};

function handleError(error) {
console.error('package error:', error);
};

var fetchedCallback = null;
var fetched = Module['getPreloadedPackage'] ? Module['getPreloadedPackage'](REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE) : null;

if (!fetched) fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, function(data) {
if (fetchedCallback) {
fetchedCallback(data);
fetchedCallback = null;
} else {
fetched = data;
}
}, handleError);

function runWithFS() {

function assert(check, msg) {
if (!check) throw msg + new Error().stack;
}
Module['FS_createPath']("/", "assets", true, true);

/** @constructor */
function DataRequest(start, end, audio) {
this.start = start;
this.end = end;
this.audio = audio;
}
DataRequest.prototype = {
requests: {},
open: function(mode, name) {
this.name = name;
this.requests[name] = this;
Module['addRunDependency'](`fp ${this.name}`);
},
send: function() {},
onload: function() {
var byteArray = this.byteArray.subarray(this.start, this.end);
this.finish(byteArray);
},
finish: function(byteArray) {
var that = this;
// canOwn this data in the filesystem, it is a slide into the heap that will never change
Module['FS_createDataFile'](this.name, null, byteArray, true, true, true);
Module['removeRunDependency'](`fp ${that.name}`);
this.requests[this.name] = null;
}
};

var files = metadata['files'];
for (var i = 0; i < files.length; ++i) {
new DataRequest(files[i]['start'], files[i]['end'], files[i]['audio'] || 0).open('GET', files[i]['filename']);
}

function processPackageData(arrayBuffer) {
assert(arrayBuffer, 'Loading data file failed.');
assert(arrayBuffer.constructor.name === ArrayBuffer.name, 'bad input to processPackageData');
var byteArray = new Uint8Array(arrayBuffer);
var curr;
// Reuse the bytearray from the XHR as the source for file reads.
DataRequest.prototype.byteArray = byteArray;
var files = metadata['files'];
for (var i = 0; i < files.length; ++i) {
DataRequest.prototype.requests[files[i].filename].onload();
} Module['removeRunDependency']('datafile_Example_HelloGame.data');

};
Module['addRunDependency']('datafile_Example_HelloGame.data');

if (!Module.preloadResults) Module.preloadResults = {};

Module.preloadResults[PACKAGE_NAME] = {fromCache: false};
if (fetched) {
processPackageData(fetched);
fetched = null;
} else {
fetchedCallback = processPackageData;
}

}
if (Module['calledRun']) {
runWithFS();
} else {
if (!Module['preRun']) Module['preRun'] = [];
Module["preRun"].push(runWithFS); // FS is not initialized yet, wait for it
}

}
loadPackage({"files": [{"filename": "/assets/Grass.jpg", "start": 0, "end": 152754}, {"filename": "/assets/HelloGame.PSGround.300es.frag", "start": 152754, "end": 154951}, {"filename": "/assets/HelloGame.PSGround.450core.frag", "start": 154951, "end": 157783}, {"filename": "/assets/HelloGame.PSInstance.300es.frag", "start": 157783, "end": 160472}, {"filename": "/assets/HelloGame.PSInstance.450core.frag", "start": 160472, "end": 163564}, {"filename": "/assets/HelloGame.VSGround.300es.vert", "start": 163564, "end": 164331}, {"filename": "/assets/HelloGame.VSGround.450core.vert", "start": 164331, "end": 165198}, {"filename": "/assets/HelloGame.VSInstance.300es.vert", "start": 165198, "end": 167436}, {"filename": "/assets/HelloGame.VSInstance.450core.vert", "start": 167436, "end": 170061}, {"filename": "/assets/HelloGame.levels.txt", "start": 170061, "end": 171332}, {"filename": "/assets/HelloGame_Block.obj", "start": 171332, "end": 225208}, {"filename": "/assets/HelloGame_Ground.obj", "start": 225208, "end": 225544}, {"filename": "/assets/HelloGame_Player.obj", "start": 225544, "end": 251419}, {"filename": "/assets/HelloGame_Tree.obj", "start": 251419, "end": 258441}], "remote_package_size": 258441});

})();
1 change: 1 addition & 0 deletions docu/WebPage/Example_HelloGame/Example_HelloGame.js

Large diffs are not rendered by default.

Binary file not shown.
48 changes: 48 additions & 0 deletions docu/WebPage/Example_HelloGame/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>LLGL - HelloGame</title>
<style>
canvas {
display: block;
padding-left: 0;
padding-right: 0;
margin-left: auto;
margin-right: auto;
width: min(100%, 98vh * 4 / 3);
aspect-ratio: 4 / 3;
}
</style>
</head>
<body>
<!-- Create canvas that C++ code will draw into -->
<div style="text-align: center;">
<canvas id="canvas" oncontextmenu="event.preventDefault()" width="800" height="600"></canvas>
</div>

<!-- Define module to allow C++ code to access the canvas element -->
<script type="text/javascript">
var Module = {
print: function() {
var e = document.getElementById("output");
return e && (e.value = ""), (...t) => {
var n = t.join(" ");
console.log(n), e && (e.value += n + "\n", e.scrollTop = e.scrollHeight)
}
}(),
canvas: (() => {
var e = document.getElementById("canvas");
return e.addEventListener("webglcontextlost", (e => {
alert("WebGL context lost. You will need to reload the page."), e.preventDefault()
}), !1), e
})()
};
</script>

<!-- Add JavaScript glue code generated by Emscripten -->
<script src=Example_HelloGame.data.js></script>
<script src=Example_HelloGame.js></script>
</body>
</html>
4 changes: 4 additions & 0 deletions docu/WebPage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ <h2>Examples:</h2>
<li><a href="Example_StencilBuffer/index.html">StencilBuffer</a></li>
<li><a href="Example_Texturing/index.html">Texturing</a></li>
</ul>
<h2>Games:</h2>
<ul>
<li><a href="Example_HelloGame/index.html">HelloGame</a> - a "Hello World" style puzzle game</li>
</ul>
</body>
</html>

0 comments on commit 88e1414

Please sign in to comment.