parent
61d0e06766
commit
74ec5500f6
@ -0,0 +1,77 @@ |
||||
|
||||
<!doctype html> |
||||
<html lang="en-us"> |
||||
<head> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
<meta charset="utf-8"> |
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
||||
<title>Emscripten-Generated Code</title> |
||||
<style> |
||||
html,body { width: 100%; height: 100%; } |
||||
body { font-family: arial; margin: 0; padding: 0; background: #000; } |
||||
|
||||
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; } |
||||
div.emscripten_border { border: none; } |
||||
|
||||
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */ |
||||
canvas.emscripten { border: 0px none; background-color: black; } |
||||
</style> |
||||
</head> |
||||
<body> |
||||
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas> |
||||
<script type='text/javascript'> |
||||
var Module = { |
||||
preRun: [], |
||||
postRun: [], |
||||
canvas: (function() { |
||||
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", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false); |
||||
|
||||
return canvas; |
||||
})(), |
||||
}; |
||||
</script> |
||||
<script async type="text/javascript" src="./pge.js"></script> |
||||
<script type="text/javascript"> |
||||
Module.canvas.addEventListener("resize", (e) => { |
||||
|
||||
var viewWidth = e.detail.width; |
||||
var viewHeight = e.detail.width / Module._olc_WindowAspectRatio; |
||||
|
||||
if(viewHeight > e.detail.height) |
||||
{ |
||||
viewHeight = e.detail.height; |
||||
viewWidth = e.detail.height * Module._olc_WindowAspectRatio; |
||||
} |
||||
|
||||
// update dom attributes |
||||
Module.canvas.setAttribute("width", viewWidth); |
||||
Module.canvas.setAttribute("height", viewHeight); |
||||
|
||||
var top = (e.detail.height - viewHeight) / 2; |
||||
var left = (e.detail.width - viewWidth) / 2; |
||||
|
||||
// update styles |
||||
Module.canvas.style.position = "fixed"; |
||||
Module.canvas.style.top = top.toString() + "px"; |
||||
Module.canvas.style.left = left.toString() + "px"; |
||||
Module.canvas.style.width = ""; |
||||
Module.canvas.style.height = ""; |
||||
|
||||
// trigger PGE update |
||||
Module._olc_PGE_UpdateWindowSize(viewWidth, viewHeight); |
||||
|
||||
// ensure canvas has focus |
||||
Module.canvas.focus(); |
||||
e.preventDefault(); |
||||
}); |
||||
</script> |
||||
|
||||
</body> |
||||
</html> |
||||
|
||||
|
@ -0,0 +1,108 @@ |
||||
@echo off |
||||
:: Convenience Utility to build projects using olc::PixelGameEngine, using |
||||
:: Emscripten, producing WASM based output. |
||||
:: |
||||
:: OneLoneCoder.com 2021 - Released under OLC-3 license |
||||
:: |
||||
:: v1.00: Initial Release |
||||
|
||||
setlocal enabledelayedexpansion enableextensions |
||||
|
||||
:: Customize here =========================================== |
||||
|
||||
:: Location of Emscripten SDK |
||||
set EMSDK="e:\pge_ems\emsdk\" |
||||
|
||||
:: Location of olc::PixelGameEngine header file |
||||
set OLCPGE=".\" |
||||
set OLCPGE="e:\pge_dev\olcPixelGameEngine_dev\Deploy" |
||||
|
||||
:: ========================================================== |
||||
|
||||
set WORKINGDIR=%CD% |
||||
|
||||
if not exist %EMSDK% ( |
||||
echo Error: No Emscripten SDK folder found! |
||||
goto :fail |
||||
) |
||||
|
||||
if not exist %OLCPGE% ( |
||||
echo Error: Invalid PGE Location! |
||||
goto :fail |
||||
) |
||||
|
||||
if "%1"=="build" goto :build |
||||
if "%1"=="run" goto :run |
||||
if "%1"=="clean" goto :clean |
||||
goto :error |
||||
|
||||
:build |
||||
:: Configure path variables |
||||
cd %EMSDK% |
||||
call emsdk_env.bat |
||||
|
||||
:: Create working folder |
||||
cd %WORKINGDIR% |
||||
if not exist ".\WASM" ( |
||||
echo Creating .\WASM output folder |
||||
mkdir ".\WASM" |
||||
) |
||||
|
||||
:: Grab all cpp files if no specific file is given |
||||
if "%~2"=="" goto :graball |
||||
set CPP=%~2 |
||||
goto :embuild |
||||
|
||||
:graball |
||||
echo Gathering *.cpp files from |
||||
echo %CD% |
||||
set CPP= |
||||
for %%x in (%CD%\*.cpp) do set CPP=!CPP! %%x |
||||
set CPP=%CPP:~1% |
||||
|
||||
:embuild |
||||
|
||||
echo %CPP% |
||||
if exist "./assets" ( |
||||
echo Starting Build with assets... |
||||
call em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_LIBPNG=1 %CPP% -o .\WASM\pge.html -I %OLCPGE% --preload-file .\assets |
||||
) else ( |
||||
echo Starting Build without assets... |
||||
call em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_LIBPNG=1 %CPP% -o .\WASM\pge.html -I %OLCPGE% |
||||
) |
||||
|
||||
echo Build Completed |
||||
goto :success |
||||
|
||||
:run |
||||
:: Configure path variables |
||||
cd %EMSDK% |
||||
call emsdk_env.bat |
||||
cd %WORKINGDIR% |
||||
emrun .\WASM\pge.html |
||||
goto :success |
||||
|
||||
:clean |
||||
if exist ".\WASM" ( |
||||
rmdir /s /q .\WASM |
||||
) |
||||
goto :success |
||||
|
||||
:error |
||||
echo Error: Incorrect Input |
||||
goto :fail |
||||
|
||||
:success |
||||
echo Exit With Success |
||||
goto :leave |
||||
|
||||
:fail |
||||
echo Exit with Failure |
||||
goto :leave |
||||
|
||||
:leave |
||||
exit |
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
Loading…
Reference in new issue