Final version, much better performance, tested on examples
This commit is contained in:
parent
883daf4faa
commit
0fc700c0a0
|
@ -21,8 +21,6 @@
|
||||||
;; This is really bad. The goal should be for the counts for
|
;; This is really bad. The goal should be for the counts for
|
||||||
;; word-(evt,output,label,fps) to all be the same as tick
|
;; word-(evt,output,label,fps) to all be the same as tick
|
||||||
;;
|
;;
|
||||||
;; The second release was this:
|
|
||||||
;;
|
|
||||||
;; [log.2]
|
;; [log.2]
|
||||||
;; 844 Events
|
;; 844 Events
|
||||||
;; word-event: #179, average gap 27.584044724367978
|
;; word-event: #179, average gap 27.584044724367978
|
||||||
|
@ -33,11 +31,27 @@
|
||||||
;; word-return: #1, average gap 0
|
;; word-return: #1, average gap 0
|
||||||
;; word-tick: #132, average gap 37.29275442807729
|
;; word-tick: #132, average gap 37.29275442807729
|
||||||
;;
|
;;
|
||||||
|
;; [log.3]
|
||||||
|
;; 1997 Events
|
||||||
|
;; word-event: #492, average gap 22.231684480810845
|
||||||
|
;; word-evt: #301, average gap 36.38639729817708
|
||||||
|
;; word-fps: #301, average gap 36.386416829427084
|
||||||
|
;; word-label: #301, average gap 36.440130208333336
|
||||||
|
;; word-output: #301, average gap 37.64551025390625
|
||||||
|
;; word-return: #1, average gap 0
|
||||||
|
;; word-tick: #300, average gap 36.4600801499791
|
||||||
|
;;
|
||||||
|
;; [log.4]
|
||||||
|
;; 1231 Events
|
||||||
|
;; word-event: #306, average gap 22.516072457735657
|
||||||
|
;; word-evt: #185, average gap 37.325081203294836
|
||||||
|
;; word-fps: #185, average gap 37.32514091159987
|
||||||
|
;; word-label: #185, average gap 37.34000562584919
|
||||||
|
;; word-output: #185, average gap 39.36237501061481
|
||||||
|
;; word-return: #1, average gap 0
|
||||||
|
;; word-tick: #184, average gap 37.38046981728142
|
||||||
|
|
||||||
(module+ main
|
(define (check log-p)
|
||||||
(require racket/runtime-path)
|
|
||||||
(define-runtime-path log-p "log")
|
|
||||||
|
|
||||||
(define events (file->list log-p))
|
(define events (file->list log-p))
|
||||||
|
|
||||||
(printf "~a Events\n" (length events))
|
(printf "~a Events\n" (length events))
|
||||||
|
@ -67,8 +81,15 @@
|
||||||
|
|
||||||
(define (average-gap ts)
|
(define (average-gap ts)
|
||||||
(average (gaps ts)))
|
(average (gaps ts)))
|
||||||
(for ([(i ts) (in-hash label->times)])
|
(for ([i (in-list (sort (hash-keys label->times) string<=? #:key symbol->string))])
|
||||||
|
(define ts (hash-ref label->times i))
|
||||||
(printf "~a: #~a, average gap ~a\n"
|
(printf "~a: #~a, average gap ~a\n"
|
||||||
i
|
i
|
||||||
(length ts)
|
(length ts)
|
||||||
(average-gap ts))))
|
(average-gap ts))))
|
||||||
|
|
||||||
|
(module+ main
|
||||||
|
(require racket/cmdline)
|
||||||
|
(command-line #:program "log-check"
|
||||||
|
#:args (log-p)
|
||||||
|
(check log-p)))
|
||||||
|
|
60
word.rkt
60
word.rkt
|
@ -67,62 +67,68 @@
|
||||||
(define next-time (fl+ start-time time-incr))
|
(define next-time (fl+ start-time time-incr))
|
||||||
next-time)
|
next-time)
|
||||||
|
|
||||||
(define (factum-fiat-lux c w)
|
(define (continue-or-word-return next-w old-w k)
|
||||||
(define (continue-or-word-return next-w old-w k)
|
|
||||||
(cond
|
(cond
|
||||||
[(not next-w)
|
[(not next-w)
|
||||||
((LOG! word-return) old-w)]
|
(word-return old-w)]
|
||||||
[else
|
[else
|
||||||
(k next-w)]))
|
(k next-w)]))
|
||||||
|
|
||||||
|
(define (factum-fiat-lux c w)
|
||||||
(define (output&process-input&wait frame-start-time w)
|
(define (output&process-input&wait frame-start-time w)
|
||||||
(chaos-output! c ((LOG! word-output) w))
|
(chaos-output! c (word-output w))
|
||||||
(define frame-end-time (current-inexact-milliseconds))
|
(define frame-end-time (current-inexact-milliseconds))
|
||||||
(define frame-time (- frame-end-time frame-start-time))
|
(define frame-time (- frame-end-time frame-start-time))
|
||||||
(define new-label ((LOG! word-label) w frame-time))
|
(define new-label (word-label w frame-time))
|
||||||
(chaos-label! c new-label)
|
(chaos-label! c new-label)
|
||||||
|
|
||||||
(define fps ((LOG! word-fps) w))
|
(define fps (word-fps w))
|
||||||
(define next-time (compute-next-time frame-end-time fps))
|
(define next-time (compute-next-time frame-end-time fps))
|
||||||
(define deadline-evt (alarm-evt next-time))
|
(define deadline-evt (alarm-evt next-time))
|
||||||
(define input-enabled? (zero? fps))
|
(define input-enabled? (fl= 0.0 fps))
|
||||||
|
|
||||||
(define w-evt ((LOG! word-evt) w))
|
(define w-evt (word-evt w))
|
||||||
(define c-evt (chaos-event c))
|
(define c-evt (chaos-event c))
|
||||||
(define w-or-c-evt (choice-evt w-evt c-evt))
|
(define w-or-c-evt (choice-evt w-evt c-evt))
|
||||||
|
|
||||||
(let process-input&wait ([w w])
|
(define continue
|
||||||
|
(λ (next-w)
|
||||||
|
(output&process-input&wait frame-end-time next-w)))
|
||||||
|
|
||||||
|
(define THE-W w)
|
||||||
(define wait-evt
|
(define wait-evt
|
||||||
(handle-evt deadline-evt
|
(handle-evt deadline-evt
|
||||||
(λ (_)
|
(λ (_)
|
||||||
(define next-w ((LOG! word-tick) w))
|
(define next-w (word-tick THE-W))
|
||||||
(continue-or-word-return
|
(continue-or-word-return
|
||||||
next-w w
|
next-w THE-W
|
||||||
|
continue))))
|
||||||
|
(define input-continue
|
||||||
(λ (next-w)
|
(λ (next-w)
|
||||||
(output&process-input&wait frame-end-time next-w))))))
|
(cond
|
||||||
|
[input-enabled?
|
||||||
|
(output&process-input&wait frame-end-time next-w)]
|
||||||
|
[else
|
||||||
|
(set! THE-W next-w)
|
||||||
|
(process-input&wait)])))
|
||||||
(define input-evt
|
(define input-evt
|
||||||
(handle-evt w-or-c-evt
|
(handle-evt w-or-c-evt
|
||||||
(λ (e)
|
(λ (e)
|
||||||
(define next-w ((LOG! word-event) w e))
|
(define next-w (word-event THE-W e))
|
||||||
(continue-or-word-return
|
(continue-or-word-return
|
||||||
next-w w
|
next-w THE-W
|
||||||
(λ (next-w)
|
input-continue))))
|
||||||
(if input-enabled?
|
|
||||||
(output&process-input&wait frame-end-time next-w)
|
|
||||||
(process-input&wait next-w)))))))
|
|
||||||
(define both-evt
|
(define both-evt
|
||||||
(choice-evt input-evt wait-evt))
|
(choice-evt input-evt wait-evt))
|
||||||
(sync/timeout
|
(define timeout-f
|
||||||
(λ () (chaos-yield c both-evt))
|
(λ () (chaos-yield c both-evt)))
|
||||||
input-evt)))
|
(define (process-input&wait)
|
||||||
|
(sync/timeout timeout-f input-evt))
|
||||||
|
|
||||||
|
(process-input&wait))
|
||||||
|
|
||||||
(chaos-swap! c (λ () (output&process-input&wait (current-inexact-milliseconds) w))))
|
(chaos-swap! c (λ () (output&process-input&wait (current-inexact-milliseconds) w))))
|
||||||
|
|
||||||
(define-syntax-rule (LOG! id)
|
|
||||||
(begin (LOG!* 'id) id))
|
|
||||||
(define (LOG!* i)
|
|
||||||
(writeln (cons (current-inexact-milliseconds) i))
|
|
||||||
(flush-output))
|
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
gen:word
|
gen:word
|
||||||
(contract-out
|
(contract-out
|
||||||
|
|
Loading…
Reference in New Issue