diff options
| author | gonzo <gonzo@toniatuh.com> | 2024-11-03 21:43:37 +0100 |
|---|---|---|
| committer | gonzo <gonzo@toniatuh.com> | 2024-11-03 21:48:36 +0100 |
| commit | 42d46d324715a27b763d39cc6bf34bb40a594f22 (patch) | |
| tree | 04b9286c56e13998c2fa3fbb46aad7536436879d | |
| parent | 9bb2bf304e47fe74952f88ffcacabb25ae4b5014 (diff) | |
| download | gambit-snek-42d46d324715a27b763d39cc6bf34bb40a594f22.tar.gz | |
now has separation between compiled and interpreted contexts
- use cond-expand to load raylib if the snek.scm is interpreted
- .gambini added to automatically add gambit-raylib to search order
- game now starts in background when interpreted
- this makes it easier to incrementally develop in emacs
- game starts in foreground when compiled
| -rw-r--r-- | .gambini | 1 | ||||
| m--------- | gambit-raylib | 0 | ||||
| -rw-r--r-- | makefile | 11 | ||||
| -rw-r--r-- | snek.scm | 39 |
4 files changed, 41 insertions, 10 deletions
diff --git a/.gambini b/.gambini new file mode 100644 index 0000000..d56a888 --- /dev/null +++ b/.gambini @@ -0,0 +1 @@ +(module-search-order-add! "./gambit-raylib/") diff --git a/gambit-raylib b/gambit-raylib -Subproject 5e764e9edd3c5e33fa9a384b49b74e5c4eb370a +Subproject c24e9c8679d43ad5960864b1e7c746b2dcf5356 @@ -1,10 +1,19 @@ -all: snek +all: snek loadable .PHONY: all +# dynamic library +loadable: ./gambit-raylib/raylib.sld ./gambit-raylib/*.scm + make -C gambit-raylib + +# static library lib: ./gambit-raylib/raylib.sld gsc -:s -c -module-ref raylib -o gambit-raylib.c ./gambit-raylib/raylib.sld +# executable snek: lib snek.scm gsc -:s -exe -ld-options "-lm -lraylib" -o snek gambit-raylib.c snek.scm +clean: + make -C gambit-raylib clean + rm snek gambit-raylib.c @@ -1,3 +1,9 @@ +(cond-expand ((and (compilation-target (_)) + (not raylib)) + (import (raylib)) + (define-cond-expand-feature raylib)) + (else #t)) + (define-syntax with-drawing (syntax-rules () ((with-drawing body ...) @@ -9,6 +15,7 @@ (define BLACK (raylib#make-color 0 0 0 255)) (define WHITE (raylib#make-color 255 255 255 255)) (define RED (raylib#make-color 255 0 0 255)) +(define GREEN (raylib#make-color 0 255 0 255)) (define KEY_ESC 256) (define KEY_RIGHT 262) @@ -152,15 +159,29 @@ 0 'right)) +(define (run-game) + (dynamic-wind + (lambda () (begin + (raylib#set-target-fps 60) + (raylib#init-window VP_WIDTH VP_HEIGHT "snek") + (raylib#set-exit-key KEY_ESC) + (set! game-running #t) + (display "GAME ON!"))) + (lambda () (let ((state (init))) + (place-apple! state) + (main-loop state))) + (lambda () (raylib#close-window)))) + +(define (run-game-bg) + (thread-start! (make-thread (lambda () (run-game)) "game-loop"))) + (define (main arg) - (raylib#set-target-fps 60) - (raylib#init-window VP_WIDTH VP_HEIGHT "snek") - (raylib#set-exit-key KEY_ESC) - (set! game-running #t) - (display "GAME ON!") - (let ((state (init))) - (place-apple! state) - (main-loop state)) - (raylib#close-window)) + ;; compilation-target (_) denotes the interpreter ! + (cond-expand ((compilation-target (_)) + (display "BG-RUN") + (run-game-bg)) + (else + (display "FG-RUN") + (run-game)))) (main '()) |
