web build scripts + qol fixes
parent
644fd23a0d
commit
f1ac78a461
|
@ -1,5 +1,9 @@
|
||||||
build
|
build
|
||||||
build_rel
|
build_rel
|
||||||
|
build_web
|
||||||
|
emsdk
|
||||||
|
deploy_web
|
||||||
|
butler
|
||||||
screenshots
|
screenshots
|
||||||
build.bat
|
build.bat
|
||||||
run.bat
|
run.bat
|
||||||
|
|
|
@ -14,7 +14,7 @@ if(MSVC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (EMSCRIPTEN)
|
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_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_COMPILE_WARNING_AS_ERROR OFF)
|
||||||
set(CMAKE_CXX_)
|
set(CMAKE_CXX_)
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
#include "debug_ui.h"
|
#include "debug_ui.h"
|
||||||
#include "utils/raylib_helpers.h"
|
#include "utils/raylib_helpers.h"
|
||||||
|
|
||||||
static uint16_t screenWidth = 1600;
|
static uint16_t screenWidth = 1024;
|
||||||
static uint16_t screenHeight = 900;
|
static uint16_t screenHeight = 768;
|
||||||
static float target_zoom = 1.5f;
|
static float target_zoom = 1.5f;
|
||||||
static bool request_shutdown;
|
static bool request_shutdown;
|
||||||
|
|
||||||
|
@ -29,9 +29,11 @@ void platform_init() {
|
||||||
SetTraceLogLevel(LOG_ERROR);
|
SetTraceLogLevel(LOG_ERROR);
|
||||||
InitWindow(screenWidth, screenHeight, "eco2d");
|
InitWindow(screenWidth, screenHeight, "eco2d");
|
||||||
SetWindowState(/*FLAG_WINDOW_UNDECORATED|*/FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE|FLAG_MSAA_4X_HINT);
|
SetWindowState(/*FLAG_WINDOW_UNDECORATED|*/FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE|FLAG_MSAA_4X_HINT);
|
||||||
|
|
||||||
|
#if !defined(PLATFORM_WEB)
|
||||||
screenWidth = (uint16_t)GetScreenWidth();
|
screenWidth = (uint16_t)GetScreenWidth();
|
||||||
screenHeight = (uint16_t)GetScreenHeight();
|
screenHeight = (uint16_t)GetScreenHeight();
|
||||||
|
#endif
|
||||||
// ToggleFullscreen();
|
// ToggleFullscreen();
|
||||||
// SetTargetFPS(60.0);
|
// SetTargetFPS(60.0);
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -xe
|
||||||
|
|
||||||
|
python -m http.server --directory build_web --bind 127.0.0.1
|
|
@ -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
|
|
@ -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>
|
Loading…
Reference in New Issue