diff --git a/config.nims b/config.nims index 8b6d784..33fdd22 100644 --- a/config.nims +++ b/config.nims @@ -23,12 +23,13 @@ when defined( emscripten ): --panics:on --exceptions:goto --define:noSignalHandler - --passL:"-Oz" # Production build + --passL:"-Oz" # Production bu ld # --passL:"-O0 -gDebug -gsource-map" # Debug build - # --passL:"-s EXPORT_NAME=Test1Module" - # --passL:"-s MODULARIZE=1" + --passL:"-s EXPORT_ES6" + --passL:"-s EXPORT_NAME=NimTest" --passL:"-s ASYNCIFY" # async support - # --passL:"-s JSPI" # async support - --passL:"-o build/index.html" - --passL:"--shell-file minshell.html" + # --passL:"-s EXPORT_ALL=1" # make all public methods available to JS + # --passL:"-s JSPI" # async support (new) + # --passL:"-s ALLOW_MEMORY_GROWTH=1" + --passL:"-o build/nimtest.js" diff --git a/index.html b/index.html new file mode 100644 index 0000000..4237d19 --- /dev/null +++ b/index.html @@ -0,0 +1,41 @@ + + + + + + + raylib web game + + + + + + + + + + + + + diff --git a/minshell.html b/minshell.html deleted file mode 100644 index ec71588..0000000 --- a/minshell.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - raylib web game - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - {{{ SCRIPT }}} - - diff --git a/nim_wasm_test.nimble b/nim_wasm_test.nimble index a4a3739..989c1a2 100644 --- a/nim_wasm_test.nimble +++ b/nim_wasm_test.nimble @@ -14,7 +14,10 @@ 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 -d:emscripten -d:release src/nim_wasm_test.nim" + exec """ + mkdir -p build && cp index.html build/ + nim c -d:emscripten -d:release 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' build/" diff --git a/src/nim_wasm_test.nim b/src/nim_wasm_test.nim index 0122203..4d2834c 100644 --- a/src/nim_wasm_test.nim +++ b/src/nim_wasm_test.nim @@ -1,6 +1,8 @@ # vim: set et sta sw=4 ts=4 : -import std/os +import + std/os, + std/strformat import raylib # Emscripten specific imports @@ -15,23 +17,37 @@ var camera = Camera( projection: Perspective # Defines projection type, see CameraProjection ) +# This only works with: +# --passL:"-s EXPORT_FUNCTIONS=_nativeGreet", but it breaks raylib loading. +# hmmmmm. EXPORT_ALL=1 is also a no go. +# Maybe it won't be necessary with raylib/opengl input +# +#[ proc nativeGreet*(): int {.exportc.} = + echo "Oh jeez, hello from native nim!" + return 0 ]# + + proc mainLoop() {.cdecl.} = defer: closeWindow() initWindow( 800, 600, "raylib nim playground" ) + var count = 0 + while not windowShouldClose(): beginDrawing(); - clearBackground( RAYWHITE ); + clearBackground( WHITE ); beginMode3D( camera ); drawGrid( 10, 1.0f ); endMode3D(); var col = if isCursorOnScreen(): BLUE else: GRAY - drawText( "OH SNAP IT'S WORKING", 10, 10, 20, col ); + drawText( "OH SNAP IT'S WORKING\n{count}".fmt, 10, 10, 20, col ); endDrawing(); + count = count + 1 + if defined( emscripten ): emscripten_sleep 10 echo "wasm: hi"