Better gameobj-inject! system. Also now use run-hive.
authorChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 19 Jan 2017 19:55:39 +0000 (13:55 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 19 Jan 2017 19:55:56 +0000 (13:55 -0600)
mudsync/run-game.scm

index fe7cb516ca81177a4b276fff107228cd01baaf88..0fed48d0c51f3a43182aff45d953a368d0ad09a7 100644 (file)
 
 (define-module (mudsync run-game)
   #:use-module (mudsync game-master)
-  #:use-module (8sync agenda)
+  #:use-module (8sync)
   #:use-module (8sync repl)
-  #:use-module (8sync actors)
   #:use-module (8sync debug)
   #:use-module (srfi srfi-1)
   #:use-module (ice-9 receive)
   #:use-module (ice-9 q)
+  #:use-module (ice-9 match)
   #:export (run-demo
             do-inject-special!
             make-special-injector
 ;; "quasi-evil for productivity's sake" anyway).  You can set up your own
 ;; solution which doesn't use a global though.
 
+(define %inject-queue #f)
+
 (define (inject-gameobj! game-spec special-symbol)
-  (display "Game hasn't been started...\n"))
+  (if %inject-queue
+      (let ((gameobj-spec
+             (or (find
+                  (lambda (entry) (eq? (car entry) special-symbol))
+                  game-spec)
+                 (throw 'no-such-symbol "Can't find such a symbol in the game-spec"
+                        #:symbol special-symbol))))
+        (enq! %inject-queue (cons gameobj-spec special-symbol)))
+      (display "Game hasn't been started...\n"))
+  'done)
+
+(define-actor <gameobj-injector> (<actor>)
+  ((repl-update gameobj-injector-inject-queued))
+  (gm #:init-keyword #:gm
+      #:getter .gm))
 
+(define (gameobj-injector-inject-queued injector message)
+  (while (not (q-empty? %inject-queue))
+    (match (deq! %inject-queue)
+      ((gameobj-spec . special-symbol)
+       (<- (.gm injector) 'inject-special!
+           #:special-symbol special-symbol
+           #:gameobj-spec gameobj-spec)))))
 
 \f
 ;;; Game running stuff
   (define gm
     (bootstrap-actor-gimmie* hive <game-master> "gm"
                              #:new-conn-handler new-conn-handler))
-  (define repl-manager
-    (bootstrap-actor* hive <repl-manager> "repl"))
-
-  (define initial-tasks
-    (list (bootstrap-message hive (actor-id gm) 'init-world
-                             #:game-spec game-spec)
-          (apply bootstrap-message hive repl-manager 'init
-                 (if (string? repl-server)
-                     `(#:path ,repl-server)
-                     '()))))
+  (define injector
+    (bootstrap-actor hive <gameobj-injector>
+                     #:gm (actor-id gm)))
 
-  (define agenda
-    (make-agenda #:pre-unwind-handler print-error-and-continue
-                 #:queue (list->q initial-tasks)))
+  (define repl-manager
+    (bootstrap-actor* hive <repl-manager> "repl"
+                      #:subscribers (list injector)))
 
   (set! %live-gm gm)
   (set! %live-hive hive)
 
-  (receive (post-run-hook gameobj-injector)
-      (make-special-injector agenda hive (actor-id gm))
-    ;; Set up injector for live hacking
-    (set! inject-gameobj! gameobj-injector)
-
-    (run-agenda agenda #:post-run-hook post-run-hook)))
-
-
-(define (do-inject-special! queue hive gm-id game-spec special-symbol)
-  (define gameobj-spec
-    (or (find
-         (lambda (entry) (eq? (car entry) special-symbol))
-         game-spec)
-        (throw 'no-such-symbol "Can't find such a symbol in the game-spec"
-               #:symbol special-symbol)))
-  (define task
-    (bootstrap-message hive gm-id 'inject-special!
-                       #:special-symbol special-symbol
-                       #:gameobj-spec gameobj-spec))
-  (enq! queue task)
-  'done)
-
-(define (queue-injected-tasks-on-agenda! agenda inject-queue)
-  "Inject tasks from the inject-queue onto the agenda queue."
-  (while (not (q-empty? inject-queue))
-    (enq! (agenda-queue agenda) (q-pop! inject-queue))))
+  (set! %inject-queue (make-q))
 
-(define* (make-special-injector agenda hive gm-id)
-  "Make a post-run-hook and gameobj injector for quick live hacking."
-  (define inject-queue (make-q))
-  (values
-   (lambda (agenda)
-     (queue-injected-tasks-on-agenda! agenda inject-queue))
-   (lambda (game-spec special-symbol)
-     (do-inject-special! inject-queue hive gm-id
-                         game-spec special-symbol))))
+  (run-hive hive
+            (list (bootstrap-message hive (actor-id gm) 'init-world
+                                     #:game-spec game-spec))))