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:
Mahlon E. Smith 2025-08-20 10:40:16 -07:00
parent b891520ff9
commit 0d70fefc8b
Signed by: mahlon
SSH key fingerprint: SHA256:dP84sRGKZRpOOiPD/+GuOq+SHSxEw9qi5BWLQobaHm0
4 changed files with 29 additions and 10 deletions

View file

@ -2,9 +2,23 @@
import
std/os,
std/strformat
std/parsecfg,
std/strformat,
std/strutils
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
proc emscripten_set_main_loop( f: proc() {.cdecl.}, a: cint, b: bool ) {.importc.}
proc emscripten_sleep( a: cuint ) {.importc.}
@ -48,15 +62,13 @@ proc mainLoop() {.cdecl.} =
count = count + 1
if defined( emscripten ):
emscripten_sleep 10
echo "wasm: hi"
when defined( emscripten ):
emscripten_sleep( tick )
else:
sleep 10
echo "native: hi"
sleep( tick )
if defined( emscripten ):
when defined( emscripten ):
emscripten_set_main_loop( mainLoop, 0, true );
else:
mainLoop()