Skip to content

Commit

Permalink
remove some inexact numbers, fix bug with FPS display in viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
alanb2718 committed Oct 9, 2016
1 parent 860424e commit 0a607bb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions reactive/abstract-reactive-thing.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
(define/public (milliseconds-evaluated)
(send this milliseconds))
(define/public (seconds)
(/ (send this milliseconds-evaluated) 1000.0))
(/ (send this milliseconds-evaluated) 1000))

; Accessing the thing's image. concrete-image should be overridden if the image needs to be evaluated before drawing it
(define/public (image) myimage)
Expand Down Expand Up @@ -301,7 +301,7 @@
; sets another alert
(set! alert (thread (lambda ()
; seconds-to-sleep might be negative, if clock time advanced beyond the target already
(cond [(> seconds-to-sleep 0.0) (sleep seconds-to-sleep)])
(cond [(> seconds-to-sleep 0) (sleep seconds-to-sleep)])
; we might already have gone by the target -- that's ok, since advance-time-syncd
; won't do anything in that case
(send-syncd this advance-time-syncd target)
Expand Down
2 changes: 1 addition & 1 deletion reactive/integral-preprocessor.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
; rather than human consumption, and the code is going to be really fast with or without simplication.
(define (symbolic-integral expr var)
(match expr
[v #:when (equal? v var) (list '* 0.5 (list 'expt var 2))]
[v #:when (equal? v var) (list '* 1/2 (list 'expt var 2))]
[(? number? n) (list '* n var)]
[(list '+ x y) (list '+ (symbolic-integral x var) (symbolic-integral y var))]
[(cons '* (list-no-order (? number? n) x)) (list '* n (symbolic-integral x var))]
Expand Down
6 changes: 3 additions & 3 deletions reactive/reactive-thing.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
; The default is to try symbolic, and if that doesn't work, use numeric. However, if #:symbolic is listed
; explicitly, then either symbolic integration must succeed or the system raises an exception.
; #:dt d -- time step (only allowed with #:numeric)
; Example: (integral (sin x) #:var x #:numeric #:dt 0.1)
; Example: (integral (sin x) #:var x #:numeric #:dt 1)
; A Racket macro ninja would check the restrictions in the macro itself, but here the integral-preprocessor function checks them.
; The integral-preprocessor function includes definitions of the default values for #:var and #:dt
(require (for-syntax "integral-preprocessor.rkt"))
Expand Down Expand Up @@ -173,7 +173,7 @@
; to get around a bug where the integral expression is being evaluated on startup before all variables have values.
(cond [(or (not (hash-has-key? accumulator-values id)) (eq? interesting 'first) (equal? (send this milliseconds-evaluated) 0))
(hash-set! accumulator-values id (f))
0.0]
0]
[else (- (f) (hash-ref accumulator-values id))]))
; Version of runtime integral method for use with code for numeric integration. Calling this method should return the current
; value of (integral expr) plus do some bookkeeping.
Expand All @@ -191,7 +191,7 @@
; integral expression is being evaluated on startup before all variables have values.
[new-sum (if (and (hash-has-key? accumulator-values id) (> (send this milliseconds-evaluated) 0))
(let* ([oldstruct (hash-ref accumulator-values id)]
[delta-sum (* 0.5 (+ new-expr-value (nstruct-expr-value oldstruct))
[delta-sum (* 1/2 (+ new-expr-value (nstruct-expr-value oldstruct))
(- new-var-value (nstruct-var-value oldstruct)))])
(+ (nstruct-sum oldstruct) delta-sum))
0)])
Expand Down
9 changes: 5 additions & 4 deletions reactive/viewer.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(define my-time-display time-display)
(define my-fps-display fps-display)
(define my-sleep-time sleep-time)
(define last-frame-time (current-milliseconds))
(define last-frame-time (current-inexact-milliseconds))
(super-new)

(define/override (match-thread-receive r)
Expand All @@ -43,9 +43,10 @@
(cond [running
(send-thing my-thing show my-dc)
(send my-time-display set-label (seconds->string (send my-thing seconds)))
(let ([dt (- (current-milliseconds) last-frame-time)])
(send my-fps-display set-label (string-append "FPS: " (~r (/ 1000 dt) #:precision 0)))
(set! last-frame-time (current-milliseconds)))]
(let ([dt (- (current-inexact-milliseconds) last-frame-time)])
(cond [(> dt 0)
(send my-fps-display set-label (string-append "FPS: " (~r (/ 1000 dt) #:precision 0)))])
(set! last-frame-time (current-inexact-milliseconds)))]
[else
(send my-dc clear)
(send my-time-display set-label " ")
Expand Down

0 comments on commit 0a607bb

Please sign in to comment.