web build scripts + qol fixes

isolation_bkp/dynres
Dominik Madarász 2022-09-11 19:58:30 +00:00 committed by GitHub
parent 644fd23a0d
commit f1ac78a461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 164 additions and 4 deletions

4
.gitignore vendored
View File

@ -1,5 +1,9 @@
build
build_rel
build_web
emsdk
deploy_web
butler
screenshots
build.bat
run.bat

View File

@ -14,7 +14,7 @@ if(MSVC)
endif()
if (EMSCRIPTEN)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s INITIAL_MEMORY=268435456 -s FORCE_FILESYSTEM=1 --preload-file ${CMAKE_SOURCE_DIR}/art@art/")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s INITIAL_MEMORY=268435456 -s FORCE_FILESYSTEM=1 --preload-file ${CMAKE_SOURCE_DIR}/art@art/ --shell-file ${CMAKE_SOURCE_DIR}/web/eco2d.html")
set(CMAKE_EXECUTABLE_SUFFIX ".html") # This line is used to set your executable to build with the emscripten html template so that you can directly open it.
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
set(CMAKE_CXX_)

View File

@ -13,8 +13,8 @@
#include "debug_ui.h"
#include "utils/raylib_helpers.h"
static uint16_t screenWidth = 1600;
static uint16_t screenHeight = 900;
static uint16_t screenWidth = 1024;
static uint16_t screenHeight = 768;
static float target_zoom = 1.5f;
static bool request_shutdown;
@ -29,9 +29,11 @@ void platform_init() {
SetTraceLogLevel(LOG_ERROR);
InitWindow(screenWidth, screenHeight, "eco2d");
SetWindowState(/*FLAG_WINDOW_UNDECORATED|*/FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE|FLAG_MSAA_4X_HINT);
#if !defined(PLATFORM_WEB)
screenWidth = (uint16_t)GetScreenWidth();
screenHeight = (uint16_t)GetScreenHeight();
#endif
// ToggleFullscreen();
// SetTargetFPS(60.0);

44
deploy_web.sh 100755
View File

@ -0,0 +1,44 @@
#!/bin/bash
set -xe
if [ ! -d "build_web" ]; then
echo "Build directory not found. Run setup_web.sh first."
exit 1
fi
if [ ! -d "butler" ]; then
mkdir butler
wget https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default -O butler.zip
mv butler.zip butler/
pushd butler/
unzip butler.zip
rm -rf butler.zip
chmod +x ./butler
./butler -V
popd
fi
# Build web
if [ -f "build_web/eco2d.html" ]; then
rm -rf build_web/eco2d.html
fi
cmake --build build_web
# Package all assets
if [ ! -f "build_web/eco2d.html" ]; then
echo "Build data not found. Compilation errors?"
exit 1
fi
mkdir deploy_web
cp build_web/eco2d.* deploy_web/
pushd deploy_web/
mv eco2d.html index.html
popd
# Deploy to itch.io
./butler/butler push deploy_web/ zaklaus/eco2d:html-latest
# Teardown
rm -rf deploy_web

5
run_web.sh 100755
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -xe
python -m http.server --directory build_web --bind 127.0.0.1

20
setup_web.sh 100755
View File

@ -0,0 +1,20 @@
#!/bin/bash
set -xe
# Setup emsdk
if [ ! -d "emsdk" ]; then
wget https://github.com/emscripten-core/emsdk/archive/refs/heads/main.zip -O emscripten.zip
unzip emscripten.zip
mv emsdk-main emsdk
rm -rf emscripten.zip
fi
source ./emsdk/emsdk_env.sh
emsdk update
emsdk install latest
emsdk activate latest
source ./emsdk/emsdk_env.sh
# Setup web build
emcmake cmake -S . -B build_web -DCMAKE_BUILD_TYPE=Debug -DPLATFORM=Web

85
web/eco2d.html 100644
View File

@ -0,0 +1,85 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>eco2d web game</title>
<meta name="title" content="eco2d web game">
<meta name="description" content="Small C99 2D game engine with a focus on prototyping">
<meta name="keywords" content="eco2d, html5, ecs, C, librg, chunks">
<meta name="viewport" content="width=device-width">
<!-- Open Graph metatags for sharing -->
<meta property="og:title" content="eco2d web game">
<meta property="og:image:type" content="image/png">
<meta property="og:image" content="https://avatars.githubusercontent.com/u/31039603?s=400&u=371f601b81fd4c6843f910b4565a54704caaa374&v=4">
<meta property="og:site_name" content="zpl.pw">
<meta property="og:url" content="https://github.com/zpl-c/eco2d">
<meta property="og:description" content="Small C99 2D game engine with a focus on prototyping">
<!-- Twitter metatags for sharing -->
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@DMadarasz">
<meta name="twitter:title" content="eco2d web game">
<meta name="twitter:image" content="https://avatars.githubusercontent.com/u/31039603?s=400&u=371f601b81fd4c6843f910b4565a54704caaa374&v=4">
<meta name="twitter:url" content="https://github.com/zpl-c/eco2d">
<meta name="twitter:description" content="Small C99 2D game engine with a focus on prototyping">
<style>
body { margin: 0px; background-color: black;}
canvas.emscripten { border: 0px none; background-color: black; }
.overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
</style>
<script type='text/javascript' src="https://cdn.jsdelivr.net/gh/eligrey/FileSaver.js/dist/FileSaver.min.js"> </script>
<script type='text/javascript'>
function saveFileFromMEMFSToDisk(memoryFSname, localFSname) // This can be called by C/C++ code
{
var isSafari = false; // Not supported, navigator.userAgent access is being restricted
//var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
var data = FS.readFile(memoryFSname);
var blob;
if (isSafari) blob = new Blob([data.buffer], { type: "application/octet-stream" });
else blob = new Blob([data.buffer], { type: "application/octet-binary" });
// NOTE: SaveAsDialog is a browser setting. For example, in Google Chrome,
// in Settings/Advanced/Downloads section you have a setting:
// 'Ask where to save each file before downloading' - which you can set true/false.
// If you enable this setting it would always ask you and bring the SaveAsDialog
saveAs(blob, localFSname);
}
</script>
</head>
<body>
<div class="overlay">
<input type="button" value="Fullscreen" onclick="Module.requestFullscreen(false, true);">
</div>
<canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas>
<script>
var Module = {
print: (function() {
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
};
})(),
printErr: (function() {
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
};
})(),
canvas: (function() {
var canvas = document.getElementById('canvas');
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
return canvas;
})()
};
</script>
{{{ SCRIPT }}}
</body>
</html>