Experiment with resource loading (in the form of a config file).
Change compile time checks from "if" to "when", for proper type definitions.
This commit is contained in:
parent
b891520ff9
commit
0d70fefc8b
4 changed files with 29 additions and 10 deletions
|
|
@ -7,5 +7,6 @@ References:
|
||||||
- https://github.com/planetis-m/naylib
|
- https://github.com/planetis-m/naylib
|
||||||
|
|
||||||
|
|
||||||
May need to add `/usr/lib/emscripten` to your path, and hard link `emar.py` to
|
If on arch, may need to add `/usr/lib/emscripten` to your path, and hard link
|
||||||
`emar`.
|
`emar.py` to `emar`, along with `tools/file_packager.py` to
|
||||||
|
`tools/file_packager` for some reason.
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ when defined( emscripten ):
|
||||||
--panics:on
|
--panics:on
|
||||||
--exceptions:goto
|
--exceptions:goto
|
||||||
--define:noSignalHandler
|
--define:noSignalHandler
|
||||||
--passL:"-Oz" # Production bu ld
|
# --passL:"-Oz" # Production bu ld
|
||||||
# --passL:"-O0 -gDebug -gsource-map" # Debug build
|
# --passL:"-O0 -gDebug -gsource-map" # Debug build
|
||||||
--passL:"-s EXPORT_ES6"
|
--passL:"-s EXPORT_ES6"
|
||||||
--passL:"-s EXPORT_NAME=NimTest"
|
--passL:"-s EXPORT_NAME=NimTest"
|
||||||
|
|
@ -31,5 +31,6 @@ when defined( emscripten ):
|
||||||
# --passL:"-s EXPORT_ALL=1" # make all public methods available to JS
|
# --passL:"-s EXPORT_ALL=1" # make all public methods available to JS
|
||||||
# --passL:"-s JSPI" # async support (new)
|
# --passL:"-s JSPI" # async support (new)
|
||||||
# --passL:"-s ALLOW_MEMORY_GROWTH=1"
|
# --passL:"-s ALLOW_MEMORY_GROWTH=1"
|
||||||
|
--passL:"--preload-file resources"
|
||||||
--passL:"-o build/nimtest.js"
|
--passL:"-o build/nimtest.js"
|
||||||
|
|
||||||
|
|
|
||||||
5
resources/config.ini
Normal file
5
resources/config.ini
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
[Performance]
|
||||||
|
# In milliseconds
|
||||||
|
tick = 1000
|
||||||
|
|
||||||
|
|
@ -2,9 +2,23 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
std/os,
|
std/os,
|
||||||
std/strformat
|
std/parsecfg,
|
||||||
|
std/strformat,
|
||||||
|
std/strutils
|
||||||
import raylib
|
import raylib
|
||||||
|
|
||||||
|
var conf: Config
|
||||||
|
try:
|
||||||
|
conf = loadConfig( "resources/config.ini" )
|
||||||
|
except IOError as err:
|
||||||
|
echo "No config file, using defaults."
|
||||||
|
conf = newConfig()
|
||||||
|
|
||||||
|
when defined( emscripten ):
|
||||||
|
var tick = conf.getSectionValue( "Performance", "tick", defaultVal = "10").parseInt.cuint
|
||||||
|
else:
|
||||||
|
var tick = conf.getSectionValue( "Performance", "tick", defaultVal = "10").parseInt
|
||||||
|
|
||||||
# Emscripten specific imports
|
# Emscripten specific imports
|
||||||
proc emscripten_set_main_loop( f: proc() {.cdecl.}, a: cint, b: bool ) {.importc.}
|
proc emscripten_set_main_loop( f: proc() {.cdecl.}, a: cint, b: bool ) {.importc.}
|
||||||
proc emscripten_sleep( a: cuint ) {.importc.}
|
proc emscripten_sleep( a: cuint ) {.importc.}
|
||||||
|
|
@ -48,15 +62,13 @@ proc mainLoop() {.cdecl.} =
|
||||||
|
|
||||||
count = count + 1
|
count = count + 1
|
||||||
|
|
||||||
if defined( emscripten ):
|
when defined( emscripten ):
|
||||||
emscripten_sleep 10
|
emscripten_sleep( tick )
|
||||||
echo "wasm: hi"
|
|
||||||
else:
|
else:
|
||||||
sleep 10
|
sleep( tick )
|
||||||
echo "native: hi"
|
|
||||||
|
|
||||||
|
|
||||||
if defined( emscripten ):
|
when defined( emscripten ):
|
||||||
emscripten_set_main_loop( mainLoop, 0, true );
|
emscripten_set_main_loop( mainLoop, 0, true );
|
||||||
else:
|
else:
|
||||||
mainLoop()
|
mainLoop()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue