Update to FPS target for inner loop, no more sleep().

... maybe enscripten indexdb storage next?
This commit is contained in:
Mahlon E. Smith 2025-08-20 12:10:32 -07:00
parent 0d70fefc8b
commit 1450302e06
Signed by: mahlon
SSH key fingerprint: SHA256:dP84sRGKZRpOOiPD/+GuOq+SHSxEw9qi5BWLQobaHm0
3 changed files with 6 additions and 15 deletions

View file

@ -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 build
# --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"

View file

@ -1,5 +1,4 @@
[Performance] [Performance]
# In milliseconds fps = 60
tick = 1000

View file

@ -1,7 +1,6 @@
# vim: set et sta sw=4 ts=4 : # vim: set et sta sw=4 ts=4 :
import import
std/os,
std/parsecfg, std/parsecfg,
std/strformat, std/strformat,
std/strutils std/strutils
@ -10,18 +9,15 @@ import raylib
var conf: Config var conf: Config
try: try:
conf = loadConfig( "resources/config.ini" ) conf = loadConfig( "resources/config.ini" )
except IOError as err: except IOError:
echo "No config file, using defaults." echo "No config file, using defaults."
conf = newConfig() conf = newConfig()
when defined( emscripten ): var fps = conf.getSectionValue( "Performance", "fps", defaultVal = "60").parseInt
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.}
var camera = Camera( var camera = Camera(
position: Vector3(x: 5, y: 5, z: 10), # Camera position position: Vector3(x: 5, y: 5, z: 10), # Camera position
@ -45,6 +41,7 @@ proc mainLoop() {.cdecl.} =
defer: closeWindow() defer: closeWindow()
initWindow( 800, 600, "raylib nim playground" ) initWindow( 800, 600, "raylib nim playground" )
setTargetFPS( fps.int32 );
var count = 0 var count = 0
@ -62,11 +59,6 @@ proc mainLoop() {.cdecl.} =
count = count + 1 count = count + 1
when defined( emscripten ):
emscripten_sleep( tick )
else:
sleep( tick )
when defined( emscripten ): when defined( emscripten ):
emscripten_set_main_loop( mainLoop, 0, true ); emscripten_set_main_loop( mainLoop, 0, true );