Batch outbound actions per-actor, not per-facet; continue to retain ordering within a batch group

This commit is contained in:
Tony Garnock-Jones 2021-06-12 22:16:59 +02:00
parent 6546e335ef
commit 4dc40da056
1 changed files with 18 additions and 4 deletions

View File

@ -300,9 +300,23 @@
(set-facet-end-of-turn-actions! f '()) (set-facet-end-of-turn-actions! f '())
(for [(action (in-list pending))] (action)) (for [(action (in-list pending))] (action))
(loop)))) (loop))))
(for [((ff qq) (in-hash (turn-queues turn)))] (for [((aa qq) (in-hash (turn-queues turn)))]
(queue-task! (actor-engine (facet-actor ff)) (queue-task! (actor-engine aa)
(lambda () (turn! ff (lambda () (for [(a (in-list (reverse qq)))] (a))))))) (lambda ()
(define pending (reverse qq))
(let loop ()
(when (pair? pending)
(define ff (caar pending))
(define action (cdar pending))
(set! pending (cdr pending))
(turn! ff (lambda ()
(action)
(let inner ()
(when (and (pair? pending) (eq? ff (caar pending)))
((cdar pending))
(set! pending (cdr pending))
(inner)))))
(loop))))))
(set-turn-queues! turn #f))) (set-turn-queues! turn #f)))
(log-syndicate/actor-debug "end turn ~v\n" f))) (log-syndicate/actor-debug "end turn ~v\n" f)))
@ -315,7 +329,7 @@
(define qs (turn-queues turn)) (define qs (turn-queues turn))
(when (not qs) (when (not qs)
(error 'turn-enqueue! "Attempt to reuse ~a in ~a" turn (turn-active-facet turn))) (error 'turn-enqueue! "Attempt to reuse ~a in ~a" turn (turn-active-facet turn)))
(hash-update! qs f (lambda (actions) (cons action actions)) '())) (hash-update! qs (facet-actor f) (lambda (actions) (cons (cons f action) actions)) '()))
(define (turn-ref turn entity [attenuation '()]) (define (turn-ref turn entity [attenuation '()])
(entity-ref (turn-active-facet turn) entity attenuation)) (entity-ref (turn-active-facet turn) entity attenuation))