Commit 1c516e64 authored by Hugo Hörnquist's avatar Hugo Hörnquist

Change how time is fetched.

parent 263e79c9
......@@ -34,10 +34,6 @@
(define texture-map (make-hash-table))
(define (get-t)
(define t (gettimeofday))
(+ (cdr t) (* 1000000 (car t))))
(define player (make-player 5 13 -2))
(define ray-count 64)
......@@ -46,7 +42,7 @@
(define update
(let ((keys-down '()))
(lambda (dt) ; dt in μs
(lambda (dt) ; dt in ms
(let ((ev (poll-event)))
(cond #; [(keyboard-event-repeat? ev) #f] ;; TODO implement in bindings
......@@ -64,15 +60,14 @@
(case key
((x q) (raise SIGINT))
((w s) (set! (p player)
= (+ (* dt 6e-6 (if (eq? key 'w) 1 -1)
= (+ (* dt 6e-3 (if (eq? key 'w) 1 -1)
(v3 (cos (a player))
(sin (a player))))))
(wake))
((j) (set! (a player) = (- (* dt 4e-6)))
(wake))
((p) (set! (a player) = (+ (* dt 4e-6)))
((j) (set! (a player) = (- (* dt 4e-3)))
(wake))
))
((p) (set! (a player) = (+ (* dt 4e-3)))
(wake))))
keys-down))))
(define (ray-trace player ray-count)
......@@ -184,9 +179,9 @@
(lambda () (set-render-target! (current-renderer) #f))))
(define (make-fps-counter)
(let ((last-time (get-t)))
(let ((last-time (sdl-ticks)))
(lambda ()
(let ((new-time (get-t)))
(let ((new-time (sdl-ticks)))
(let ((return (- new-time last-time)))
(set! last-time new-time)
return)))))
......@@ -215,7 +210,7 @@
(parameterize ((color (make-color 0 0 0 #xFF)))
;; FPS counter
(render-text (format #f "FPS: ~,2f" (/ 1000000 (fps-counter))) #:line 0)
(render-text (format #f "FPS: ~,2f" (/ 1000 (fps-counter))) #:line 0)
(render-text
(format #f "x = ~,4f y = ~,4f a = ~,4f"
......@@ -249,7 +244,7 @@
(begin (draw window rend) (set! counter 0))
(let ((dt (fps-counter)))
(update dt)
(usleep (int (/ (- 1000000 dt) 360)))
(usleep (max 0 (floor/ (- 1000 dt) 360)))
(set! counter = (+ 1)))))))
(sdl-init)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment