diff --git a/syndicate/examples/gl-2d-platformer.rkt b/syndicate/examples/gl-2d-platformer.rkt index c96910d..fb35655 100644 --- a/syndicate/examples/gl-2d-platformer.rkt +++ b/syndicate/examples/gl-2d-platformer.rkt @@ -519,15 +519,20 @@ (play-sound-sequence 270318) (update-piece! g pos jump-vel))) - (on (message (inbound (inbound (frame-event $counter _ $elapsed-ms _)))) - (when (zero? (modulo counter 10)) - (log-info "Instantaneous frame rate at frame ~a: ~a Hz" - counter - (/ 1000.0 elapsed-ms))) - (previous-positions (positions)) - (previous-velocities (velocities)) - (for [((id g) (in-hash (configs))) #:when (game-piece-has-attribute? g 'mobile)] - (update-game-piece! elapsed-ms id))))) + (define start-time #f) + (on (message (inbound (inbound (frame-event $counter _ _ _)))) + (let ((stop-time (current-inexact-milliseconds))) + (when (not (eq? start-time #f)) + (define elapsed-ms (- stop-time start-time)) + (when (zero? (modulo counter 10)) + (log-info "Instantaneous frame rate at frame ~a: ~a Hz" + counter + (/ 1000.0 elapsed-ms))) + (previous-positions (positions)) + (previous-velocities (velocities)) + (for [((id g) (in-hash (configs))) #:when (game-piece-has-attribute? g 'mobile)] + (update-game-piece! elapsed-ms id))) + (set! start-time stop-time))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Player