34d31559b20af941c01cbded51bfb38d34b867fc — Thomas Letan 1 year, 6 months ago 4d268b9
refactor: Rename ~game~ into ~daemon~

There is no notion of gameplay in the current implementation, only a
very straightforward players management. The gameplay will take place
into the map instances, probably with some kind of ECS
pattern. Therefore, the name ~daemon~ is more precise and describes
better the role of the class.

Signed-off-by: Thomas Letan <contact@thomasletan.fr>
1 files changed, 15 insertions(+), 17 deletions(-)

M daemon.lisp
M daemon.lisp => daemon.lisp +15 -17
@@ 17,35 17,33 @@
(defpackage :lycan/daemon
  (:nicknames :ld)
  (:use :cl)
  (:export game

  (:export main))

(cl:in-package :lycan/daemon)

(defclass game ()
(defclass daemon ()
  ((players :initform nil
            :accessor players)))

(defun make-game ()
  (make-instance 'game))
(defun make-daemon ()
  (make-instance 'daemon))

(defmethod add-new-player ((g game) socket)
  (setf (players g) (cons socket (players g))))
(defmethod register-new-player ((dm daemon) socket)
  (push socket (players dm)))

(defmethod tcp-server-init ((g game))
(defmethod init ((g daemon))
   :connect-cb (lambda (socket) (add-new-player g socket))))
   :connect-cb (lambda (socket) (register-new-player g socket))))

(defmethod frame-step ((g game))
  (dolist (socket (players g))
(defmethod frame-step ((dm daemon))
  (dolist (socket (players dm))
    (as:write-socket-data socket "hi")))

(defmethod start ((g game))
  (as:with-event-loop (:catch-app-errors t)
    (tcp-server-init g)
    (as:interval (lambda () (frame-step g)) :time 1)))
(defun main ()
  (let ((dm (make-daemon)))
    (as:with-event-loop (:catch-app-errors t)
      (init dm)
      (as:interval (lambda () (frame-step dm)) :time 1))))