Initial commit.
This commit is contained in:
commit
eb25270d34
6 changed files with 180 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
build/*
|
||||||
11
README.md
Normal file
11
README.md
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
Dinkin around.
|
||||||
|
|
||||||
|
References:
|
||||||
|
|
||||||
|
- https://github.com/bitnom/nim-to-wasm-guide
|
||||||
|
- https://github.com/planetis-m/naylib
|
||||||
|
|
||||||
|
|
||||||
|
May need to add `/usr/lib/emscripten` to your path, and hard link `emar.py` to
|
||||||
|
`emar`.
|
||||||
27
config.nims
Normal file
27
config.nims
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
when defined(emscripten):
|
||||||
|
--define:GraphicsApiOpenGlEs2
|
||||||
|
# --define:NaylibWebResources
|
||||||
|
# switch("define", "NaylibWebResourcesPath=resources")
|
||||||
|
# switch("define", "NaylibWebPthreadPoolSize=2")
|
||||||
|
# --define:NaylibWebAsyncify
|
||||||
|
--os:linux
|
||||||
|
--cpu:wasm32
|
||||||
|
--cc:clang
|
||||||
|
--clang.exe:emcc
|
||||||
|
--clang.linkerexe:emcc
|
||||||
|
--clang.cpp.exe:emcc
|
||||||
|
--clang.cpp.linkerexe:emcc
|
||||||
|
--mm:arc
|
||||||
|
--threads:on
|
||||||
|
--panics:on
|
||||||
|
--exceptions:goto
|
||||||
|
--define:noSignalHandler
|
||||||
|
--passL:"-03"
|
||||||
|
# --passL:"-s EXPORT_NAME=Test1Module"
|
||||||
|
# --passL:"-s MODULARIZE=1"
|
||||||
|
--passL:"-s ASYNCIFY" # async support
|
||||||
|
# --passL:"-s JSPI" # async support
|
||||||
|
--passL:"-o index.html"
|
||||||
|
# --passL:"--shell-file minshell.html"
|
||||||
|
|
||||||
85
minshell.html
Normal file
85
minshell.html
Normal 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>raylib web game</title>
|
||||||
|
|
||||||
|
<meta name="title" content="raylib web game">
|
||||||
|
<meta name="description" content="New raylib web videogame, developed using raylib videogames library">
|
||||||
|
<meta name="keywords" content="raylib, programming, examples, html5, C, C++, library, learn, games, videogames">
|
||||||
|
<meta name="viewport" content="width=device-width">
|
||||||
|
|
||||||
|
<!-- Open Graph metatags for sharing -->
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta property="og:title" content="raylib web game">
|
||||||
|
<meta property="og:image:type" content="image/png">
|
||||||
|
<meta property="og:image" content="https://www.raylib.com/common/raylib_logo.png">
|
||||||
|
<meta property="og:image:alt" content="New raylib web videogame, developed using raylib videogames library" />
|
||||||
|
<meta property="og:site_name" content="raylib - example">
|
||||||
|
<meta property="og:url" content="https://www.raylib.com/games.html">
|
||||||
|
<meta property="og:description" content="New raylib web videogame, developed using raylib videogames library">
|
||||||
|
|
||||||
|
<!-- Twitter metatags for sharing -->
|
||||||
|
<meta name="twitter:card" content="summary_large_image">
|
||||||
|
<meta name="twitter:site" content="@raysan5">
|
||||||
|
<meta name="twitter:title" content="raylib web game">
|
||||||
|
<meta name="twitter:image" content="https://www.raylib.com/common/raylib_logo.png">
|
||||||
|
<meta name="twitter:image:alt" content="New raylib web videogame, developed using raylib videogames library">
|
||||||
|
<meta name="twitter:url" content="https://www.raylib.com/games.html">
|
||||||
|
<meta name="twitter:description" content="New raylib web videogame, developed using raylib videogames library">
|
||||||
|
|
||||||
|
<!-- Favicon -->
|
||||||
|
<link rel="shortcut icon" href="https://www.raylib.com/favicon.ico">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body { margin: 0px; overflow: hidden; background-color: black; }
|
||||||
|
canvas.emscripten { border: 0px none; background-color: black; }
|
||||||
|
</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>
|
||||||
|
<canvas class=emscripten id=canvas oncontextmenu=event.preventDefault() tabindex=-1></canvas>
|
||||||
|
<p id="output" />
|
||||||
|
<script>
|
||||||
|
var Module = {
|
||||||
|
print: (function() {
|
||||||
|
var element = document.getElementById('output');
|
||||||
|
if (element) element.value = ''; // clear browser cache
|
||||||
|
return function(text) {
|
||||||
|
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
|
||||||
|
console.log(text);
|
||||||
|
if (element) {
|
||||||
|
element.value += text + "\n";
|
||||||
|
element.scrollTop = element.scrollHeight; // focus on bottom
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})(),
|
||||||
|
canvas: (function() {
|
||||||
|
var canvas = document.getElementById('canvas');
|
||||||
|
return canvas;
|
||||||
|
})()
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
{{{ SCRIPT }}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
22
nim_wasm_test.nimble
Normal file
22
nim_wasm_test.nimble
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Package
|
||||||
|
|
||||||
|
version = "0.1.0"
|
||||||
|
author = "Mahlon E. Smith"
|
||||||
|
description = "Dinking around with raylib and wasm target"
|
||||||
|
license = "MIT"
|
||||||
|
srcDir = "src"
|
||||||
|
|
||||||
|
requires "nim >= 2.2.4"
|
||||||
|
requires "naylib >= 25.33.0"
|
||||||
|
requires "nimhttpd >= 1.5.1"
|
||||||
|
|
||||||
|
task make, "Native build":
|
||||||
|
exec "mkdir -p build && nim c --outdir:build -d:release --opt:speed src/nim_wasm_test.nim"
|
||||||
|
|
||||||
|
task makeweb, "Emscripten build":
|
||||||
|
exec "mkdir -p build && nim c --outdir:build -d:emscripten src/nim_wasm_test.nim"
|
||||||
|
|
||||||
|
task runweb, "Run a local webserver for the wasm build":
|
||||||
|
exec "nimhttpd -H:'Cross-Origin-Opener-Policy: same-origin' -H:'Cross-Origin-Embedder-Policy: require-corp'"
|
||||||
|
|
||||||
|
|
||||||
34
src/nim_wasm_test.nim
Normal file
34
src/nim_wasm_test.nim
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
# vim: set et sta sw=4 ts=4 :
|
||||||
|
|
||||||
|
import std/os
|
||||||
|
import raylib
|
||||||
|
|
||||||
|
# Emscripten specific imports
|
||||||
|
proc emscripten_set_main_loop(f: proc() {.cdecl.}, a: cint, b: bool) {.importc.}
|
||||||
|
proc emscripten_sleep(a: cuint) {.importc.}
|
||||||
|
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
defer: closeWindow()
|
||||||
|
|
||||||
|
initWindow( 600, 400, "raylib nim playground" )
|
||||||
|
|
||||||
|
while not windowShouldClose():
|
||||||
|
if defined(emscripten):
|
||||||
|
emscripten_sleep 10
|
||||||
|
else:
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
# when defined(emscripten):
|
||||||
|
# # Emscripten can't block so it will call this callback instead.
|
||||||
|
# emscripten_set_main_loop(main_loop, 0, true);
|
||||||
|
# else:
|
||||||
|
# # When running native code we can block in an infinite loop.
|
||||||
|
# while windowShouldClose(window) == 0:
|
||||||
|
# mainLoop()
|
||||||
|
# # If you get ESC key quit.
|
||||||
|
# if window.getKey(KEY_ESCAPE) == 1:
|
||||||
|
# window.setWindowShouldClose(1)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue