~kingcons/clones

ref: 91d581d3afab2aa932adb42b9c25657cb6ae7fc5 clones/src/input.lisp -rw-r--r-- 1.4 KiB
91d581d3Brit Butler Handle COARSE-Y 31 scrolling case. 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(mgl-pax:define-package :clones.input
  (:use :cl :alexandria :mgl-pax))

(in-package :clones.input)

(defsection @input (:title "Input Handling")
  (controller class)
  (make-controller function)
  (read-controller function)
  (reset-controller function)
  (update-button function))

(defclass controller ()
  ((a       :type bit :initform 0 :accessor controller-a)
   (b       :type bit :initform 0 :accessor controller-b)
   (select  :type bit :initform 0 :accessor controller-select)
   (start   :type bit :initform 0 :accessor controller-start)
   (up      :type bit :initform 0 :accessor controller-up)
   (down    :type bit :initform 0 :accessor controller-down)
   (left    :type bit :initform 0 :accessor controller-left)
   (right   :type bit :initform 0 :accessor controller-right)
   (strobe  :type cons :accessor controller-strobe
            :initform '#0=(a b select start up down left right . #0#))))

(defun make-controller ()
  (make-instance 'controller))

(defun next-button (controller)
  (pop (controller-strobe controller)))

(defun read-controller (controller)
  (slot-value controller (next-button controller)))

(defun reset-controller (controller)
  (loop for button = (next-button controller)
        until (eq button 'right)))

(defun update-button (controller button value)
  (let ((slot-name (find-symbol (string button) :clones.input)))
    (setf (slot-value controller slot-name) value)))