sigonasr2 3 months ago
commit 2638271cb5
  1. 17
      CMakeLists.txt
  2. 148
      emscripten_shell.html
  3. 5
      src/olcPixelGameEngine.h

@ -169,7 +169,7 @@ if(WIN32 AND MSVC)
# set working directory for Visual Studio Debugger # set working directory for Visual Studio Debugger
set_target_properties( set_target_properties(
${OutputExecutable} PROPERTIES ${OutputExecutable} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin" VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
) )
# set subsytem, console if HAS_TERMINAL is true. windows if not # set subsytem, console if HAS_TERMINAL is true. windows if not
@ -259,6 +259,21 @@ if (EMSCRIPTEN)
-sLLD_REPORT_UNDEFINED) -sLLD_REPORT_UNDEFINED)
endif() endif()
set_target_properties(${OutputExecutable} PROPERTIES LINK_FLAGS "--shell-file ${CMAKE_CURRENT_SOURCE_DIR}/emscripten_shell.html")
add_custom_command(
TARGET ${OutputExecutable}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E remove -f ${CMAKE_BINARY_DIR}/bin/index.html
)
add_custom_command(
TARGET ${OutputExecutable}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E rename ${CMAKE_BINARY_DIR}/bin/${OutputExecutable}.html ${CMAKE_BINARY_DIR}/bin/index.html
)
endif() # Emscripten endif() # Emscripten
###################################################################### ######################################################################

@ -0,0 +1,148 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hamster</title>
<style>
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
body {
font-family: arial;
background: #222;
color: #ded;
overflow: hidden;
display: flex;
align-items: center;
justify-items: center;
justify-content: center;
}
.light {
background: #fff;
color: #000;
}
#container {
position: fixed;
display: flex;
justify-content: center;
align-items: center;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#output {
position: fixed;
display: none;
font-family: 'Courier New', Courier, monospace;
width: 100%;
height: 15vh;
top:85vh;
bottom: 0;
margin-left: 1rem;
padding-left: 1rem;
background: #000;
color: #fff;
outline: none;
border: none;
}
#container.show-console {
bottom: 15vh;
}
#output.show-console {
display: block;
}
#canvas {
display: block;
border: 0px none;
background-color: black;
margin: 0 auto;
}
#canvas:focus {
outline: none;
}
#toggle-console {
display: none;
position: fixed;
top: 1rem;
left: 1rem;
}
</style>
</head>
<body>
<div id="container">
<canvas id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
</div>
<button id="toggle-console">Toggle Console</button>
<script type='text/javascript'>
var Module = {
print: (function () {
return (...args) => {
var text = args.join(' ');
window.parent.postMessage({
message: "console-output",
data: text + "\n",
}, "*");
};
})(),
canvas: (() => {
var canvas = document.getElementById('canvas');
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
// application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvas.addEventListener("webglcontextlost", (e) => { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
return canvas;
})(),
setStatus: (text) => {
},
totalDependencies: 0,
monitorRunDependencies: (left) => {
}
};
window.onerror = (event) =>
{
window.parent.postMessage({
message: "player-runtime-error",
}, "*");
};
window.parent.postMessage({
message: "player-ready",
}, "*");
window.addEventListener("message", (event) =>
{
if (typeof event.data !== "object")
return;
if (typeof event.data.message !== "string")
return;
if (event.data.message === "set-theme") {
document.querySelector("body").className = event.data.theme;
return;
}
});
</script>
{{{ SCRIPT }}}
</body>
</html>

@ -6568,7 +6568,10 @@ namespace olc
virtual olc::rcode SetWindowTitle(const std::string& s) override virtual olc::rcode SetWindowTitle(const std::string& s) override
{ emscripten_set_window_title(s.c_str()); return olc::OK; } {
// emscripten_set_window_title(s.c_str());
return olc::OK;
}
virtual olc::rcode StartSystemEventLoop() override virtual olc::rcode StartSystemEventLoop() override
{ return olc::OK; } { return olc::OK; }

Loading…
Cancel
Save