From ba3650e87bdfd4626e409287e0287c125a00b99b Mon Sep 17 00:00:00 2001 From: Vivianne Langdon Date: Sun, 16 Jul 2023 21:32:21 -0700 Subject: [PATCH] Okay this was annoying. IO is blocking by default and it's not obvious. Working again. --- gib-gab-gob/game.scm | 7 +------ gib-gab-gob/ui/console.scm | 7 +++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gib-gab-gob/game.scm b/gib-gab-gob/game.scm index 70b2434..35c7d4e 100644 --- a/gib-gab-gob/game.scm +++ b/gib-gab-gob/game.scm @@ -20,9 +20,7 @@ ((board-winner? board peer-mark) 'lost) (else 'play))) (define (signal-turn) - (format #t "signal-turn start\n") (syscaller-free-fiber (λ () (put-message state+ (%state)))) - (format #t "signal-turn end\n") #f) (define (switch-turn!) (let ((new-turn (not ($ %my-turn?)))) @@ -36,8 +34,7 @@ (if (not ($ %my-turn?)) (begin (board-choose! board peer-mark x y) - (switch-turn!) - (format #t "I have logged the peer's turn.\n")) + (switch-turn!)) (error "It's my turn!"))] ;; TODO: These need to go somewhere else so the peer can't move or init for us! [(try-transition) 'playing] @@ -54,10 +51,8 @@ (if ($ %my-turn?) (begin (board-assert-vacant board x y) - (format #t "tell peer about it\n") (on (<- peer 'peer-turn! x y) (λ (_) - (format #t "peer promise resolve, then switch and return\n") (board-choose! board mark x y) (switch-turn!) (%state)) diff --git a/gib-gab-gob/ui/console.scm b/gib-gab-gob/ui/console.scm index 5ce8b2b..96c00d4 100644 --- a/gib-gab-gob/ui/console.scm +++ b/gib-gab-gob/ui/console.scm @@ -4,6 +4,7 @@ #:use-module (gib-gab-gob board) #:use-module (ice-9 rdelim) #:use-module (ice-9 exceptions) + #:use-module (ice-9 suspendable-ports) #:use-module (srfi srfi-9) #:use-module (srfi srfi-1) #:use-module (fibers) @@ -15,6 +16,12 @@ #:use-module (goblins ocapn netlayer onion) #:export (make-initiator make-joiner)) +;; https://www.gnu.org/software/guile/manual/guile.html#Non_002dBlocking-I_002fO +(let* ((input (current-input-port)) + (flags (fcntl input F_GETFL))) + (fcntl input F_SETFL (logior O_NONBLOCK flags))) +(install-suspendable-ports!) + (random-state-from-platform) ;; Module for simple console-based UI (no curses)