summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
Diffstat (limited to '2d')
-rw-r--r--2d/game.scm31
-rw-r--r--2d/repl/repl.scm37
2 files changed, 34 insertions, 34 deletions
diff --git a/2d/game.scm b/2d/game.scm
index 00e5129..c58c419 100644
--- a/2d/game.scm
+++ b/2d/game.scm
@@ -22,7 +22,6 @@
;;; Code:
(define-module (2d game)
- #:use-module (srfi srfi-2)
#:use-module (srfi srfi-9)
#:use-module ((sdl sdl) #:prefix SDL:)
#:use-module (figl gl)
@@ -30,8 +29,6 @@
#:use-module (2d coroutine)
#:use-module (2d game)
#:use-module (2d mvars)
- #:use-module (2d repl server)
- #:use-module (2d repl repl)
#:use-module (2d signals)
#:use-module (2d vector2)
#:export (ticks-per-second
@@ -64,8 +61,6 @@
(parameterize ((game-loop-status 'running)
(tick-interval (floor (/ 1000 ticks-per-second)))
(accumulator 0))
- (resume-game)
- (spawn-server)
(game-loop (SDL:get-ticks))))
(define (draw dt alpha)
@@ -90,14 +85,12 @@ is the unused accumulator time."
(define (update-and-render dt)
(update)
- (run-repl)
(draw dt (alpha)))
(define (tick dt)
"Advance the game by one frame."
(if (game-paused?)
(begin
- (run-repl)
(SDL:delay (tick-interval))
accumulator)
(catch #t
@@ -165,27 +158,3 @@ milliseconds of the last iteration of the loop."
(let ((handle (hashq-get-handle event-handlers (SDL:event:type e))))
(when handle
((car handle) e))))
-
-;;;
-;;; REPL
-;;;
-
-(define (run-repl-thunk thunk input output error stack)
- "Run THUNK with the given REPL STACK. I/O is redirected to the given
-INPUT, OUTPUT, and ERROR ports."
- (put-mvar
- repl-output-mvar
- (with-input-from-port input
- (lambda ()
- (with-output-to-port output
- (lambda ()
- (with-error-to-port error
- (lambda ()
- (with-fluids ((*repl-stack* stack))
- (thunk))))))))))
-
-(define (run-repl)
- "Execute a thunk from the REPL is there is one."
- (unless (mvar-empty? repl-input-mvar)
- (and-let* ((vals (try-take-mvar repl-input-mvar)))
- (apply run-repl-thunk vals))))
diff --git a/2d/repl/repl.scm b/2d/repl/repl.scm
index df0b8fe..6b0a69b 100644
--- a/2d/repl/repl.scm
+++ b/2d/repl/repl.scm
@@ -29,9 +29,14 @@
#:use-module (system repl common)
#:use-module (system repl command)
#:use-module (ice-9 control)
- #:use-module (2d mvars)
+ #:use-module (srfi srfi-2)
+ #:use-module (2d agenda)
#:use-module (2d game)
- #:export (repl-input-mvar repl-output-mvar start-repl run-repl))
+ #:use-module (2d mvars)
+ #:export (repl-input-mvar
+ repl-output-mvar
+ start-repl
+ run-repl))
;;;
@@ -127,12 +132,38 @@
;;;
-;;; The repl
+;;; guile-2d REPL stuff
;;;
(define repl-input-mvar (new-empty-mvar))
(define repl-output-mvar (new-empty-mvar))
+(define (run-repl-thunk thunk input output error stack)
+ "Run THUNK with the given REPL STACK. I/O is redirected to the given
+INPUT, OUTPUT, and ERROR ports."
+ (put-mvar
+ repl-output-mvar
+ (with-input-from-port input
+ (lambda ()
+ (with-output-to-port output
+ (lambda ()
+ (with-error-to-port error
+ (lambda ()
+ (with-fluids ((*repl-stack* stack))
+ (thunk))))))))))
+
+(define (flush-repl)
+ "Execute a thunk from the REPL is there is one."
+ (unless (mvar-empty? repl-input-mvar)
+ (and-let* ((vals (try-take-mvar repl-input-mvar)))
+ (apply run-repl-thunk vals))))
+
+(schedule-interval flush-repl 5)
+
+;;;
+;;; The repl
+;;;
+
(define* (start-repl #:optional (lang (current-language)) #:key debug)
;; ,language at the REPL will update the current-language. Make
;; sure that it does so in a new dynamic scope.