summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-02-17 20:54:57 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-02-17 20:54:57 -0500
commit990b2c4c08a54f56a30bfa4eeec04af410d24006 (patch)
tree6edc46e53efcde84e74837668a3fc739d57cc5ed /examples
parent4febe9a02f8f3c2f4e2104452e505d5a9ebc970f (diff)
Update font example.
* examples/common.scm: Change format for displaying FPS in console. * examples/font.scm: Use new signal API generating labels.
Diffstat (limited to 'examples')
-rw-r--r--examples/common.scm3
-rw-r--r--examples/font.scm46
2 files changed, 21 insertions, 28 deletions
diff --git a/examples/common.scm b/examples/common.scm
index 760ce2f..8468687 100644
--- a/examples/common.scm
+++ b/examples/common.scm
@@ -15,6 +15,5 @@
(schedule-interval game-agenda
(lambda ()
- (display (fps))
- (newline))
+ (format #t "FPS: ~d\n" (signal-ref fps)))
60)
diff --git a/examples/font.scm b/examples/font.scm
index 2398b36..91acfc0 100644
--- a/examples/font.scm
+++ b/examples/font.scm
@@ -1,54 +1,48 @@
-(use-modules (srfi srfi-9)
- (figl gl)
- (2d agenda)
+(use-modules (2d agenda)
(2d fps)
(2d color)
(2d font)
(2d game)
(2d mouse)
- (2d signals)
+ (2d signal)
(2d vector2)
(2d window))
(load "common.scm")
(define font (load-default-font 18))
-(define position (vector2 320 240))
-(define text "The quick brown fox jumped over the lazy dog.")
-(define label (make-label font text position #:anchor 'center))
+(define label (make-label font "The quick brown fox jumped over the lazy dog."
+ (vector2 320 240) #:anchor 'center))
-(define fps-label-position (vector2 0 0))
-(define (make-fps-label)
- (make-label font (format #f "FPS: ~d" (fps)) fps-label-position))
-(define fps-label (make-fps-label))
+(define-signal fps-label
+ (signal-map (lambda (fps)
+ (let ((text (format #f "FPS: ~d" fps)))
+ (make-label font text (vector2 0 0))))
+ (signal-sample game-agenda 60 fps)))
-(define mouse-label-position (vector2 0 20))
-(define mouse-label
+(define-signal mouse-label
(signal-map (lambda (p)
(let ((text (format #f "Mouse: (~d, ~d)" (vx p) (vy p))))
- (make-label font text mouse-label-position)))
- mouse-position))
+ (make-label font text (vector2 0 20))))
+ (signal-throttle game-agenda 5 mouse-position)))
-(define gc-label-position (vector2 0 40))
-(define gc-counter (make-root-signal 0))
-(define gc-label
+(define-signal gc-counter (make-signal 0))
+(define-signal gc-label
(signal-map (lambda (counter)
(let ((text (format #f "GCs: ~d" counter)))
- (make-label font text gc-label-position)))
+ (make-label font text (vector2 0 40))))
gc-counter))
(add-hook! after-gc-hook
(lambda ()
- (signal-set! gc-counter (1+ (signal-ref gc-counter)))))
-
-(schedule-interval game-agenda
- (lambda ()
- (set! fps-label (make-fps-label)))
- 60)
+ (schedule game-agenda
+ (lambda ()
+ (signal-set! gc-counter
+ (1+ (signal-ref gc-counter)))))))
(add-hook! draw-hook (lambda (dt alpha)
(draw-label label)
- (draw-label fps-label)
+ (draw-label (signal-ref fps-label))
(draw-label (signal-ref mouse-label))
(draw-label (signal-ref gc-label))))