Add controller-name procedure.
authorDavid Thompson <dthompson2@worcester.edu>
Sun, 6 Jan 2019 05:05:47 +0000 (00:05 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Sun, 6 Jan 2019 05:05:47 +0000 (00:05 -0500)
* chickadee.scm (controller-name): New procedure.

chickadee.scm

index e14f924..0b46237 100644 (file)
   #:use-module (chickadee render gl)
   #:use-module (chickadee render gpu)
   #:use-module (chickadee render viewport)
+  #:use-module (chickadee utils)
   #:export (current-window
             controller-button-pressed?
             controller-axis
+            controller-name
             key-pressed?
             key-released?
             mouse-x
@@ -108,6 +110,13 @@ not being pushed at all."
   (/ (sdl2:game-controller-axis controller axis)
      32768.0))
 
+(define controller-name
+  ;; Memoize to avoid repeated allocation of strings via
+  ;; pointer->string.
+  (memoize
+   (lambda (controller)
+     (sdl2:game-controller-name controller))))
+
 (define current-window (make-parameter #f))
 
 (define* (run-game #:key