summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-09-13 19:55:14 -0400
committerDavid Thompson <dthompson@member.fsf.org>2013-09-13 19:55:14 -0400
commitcba91570c627522ef948a68809448aba0d5e8234 (patch)
tree0fcbef33935f5375f6f8d9276289895900c5218f /2d
parent7880b916e1088b252461c820e49943200318f6f9 (diff)
Start debugging the "spiral of death" issue.
Diffstat (limited to '2d')
-rw-r--r--2d/game-loop.scm58
1 files changed, 33 insertions, 25 deletions
diff --git a/2d/game-loop.scm b/2d/game-loop.scm
index 37e8036..eb8aa8b 100644
--- a/2d/game-loop.scm
+++ b/2d/game-loop.scm
@@ -133,6 +133,8 @@
"Display the current FPS every second."
(wait 60)
(pk 'FPS (floor game-fps))
+ (pk 'Updates *updates*)
+ (set! *updates* 0)
(show-fps))
;;;
@@ -147,21 +149,22 @@
(scene-draw current-scene)
(SDL:gl-swap-buffers))
+(define *updates* 0)
+
(define (update accumulator)
"Call the update callback. The update callback will be called as
many times as tick-interval can divide accumulator. The return value
is the unused accumulator time."
(if (>= accumulator tick-interval)
- (begin
- (scene-update current-scene)
- (update-agenda)
- (update (- accumulator tick-interval)))
- accumulator))
-
-(define (time-left current-time next-time)
- "Calculate the delta between NEXT-TIME and CURRENT-TIME. If
-NEXT-TIME is less than CURRENT-TIME, 0 is returned."
- (max (floor (- next-time current-time)) 0))
+ (begin
+ (set! *updates* (1+ *updates*))
+ (handle-events)
+ (update-agenda)
+ ;; (scene-update current-scene)
+ ;; (update (- accumulator tick-interval))
+ (- accumulator tick-interval)
+ )
+ accumulator))
;;;
;;; REPL
@@ -233,21 +236,27 @@ the stack."
;;; Game Loop
;;;
-(define (game-loop last-time next-time accumulator)
+;; (define (time-left current-time next-time)
+;; "Calculate the delta between NEXT-TIME and CURRENT-TIME. If
+;; NEXT-TIME is less than CURRENT-TIME, 0 is returned."
+;; (max (floor (- next-time current-time)) 0))
+
+;; (define (frame-sleep time)
+;; (unless (zero? time)
+;; (SDL:delay time)))
+
+(define (game-loop last-time accumulator)
"Runs input, render, and update hooks."
(when running
- (handle-events)
- (let* ((time (SDL:get-ticks))
- (dt (- time last-time))
- (accumulator (+ accumulator dt))
- (remainder (update accumulator)))
- (run-repl)
- (render)
- (switch-scenes-maybe)
+ (let* ((current-time (SDL:get-ticks))
+ (dt (- current-time last-time))
+ (remainder (update (+ accumulator dt))))
+ ;; (run-repl)
+ ;; (render)
(accumulate-fps! dt)
- (SDL:delay (time-left (SDL:get-ticks) next-time))
- (game-loop time
- (+ next-time tick-interval)
+ (switch-scenes-maybe)
+ ;; (frame-sleep (time-left (SDL:get-ticks) next-time))
+ (game-loop current-time
remainder))))
(define (run-game game)
@@ -257,10 +266,9 @@ the stack."
(game-fullscreen? game))
(set! running #t)
(set-initial-scene ((game-first-scene game)))
- (spawn-server)
+ ;; (spawn-server)
(agenda-schedule show-fps)
- (let ((time (SDL:get-ticks)))
- (game-loop time (+ time tick-interval) 0))
+ (game-loop (SDL:get-ticks) 0)
(close-window))
(define (quit-game-loop!)