Change add-hook's semantic and export functions to register modules

This commit is contained in:
Renaud Casenave-Péré 2014-10-11 17:18:13 +09:00
parent c9b3877f64
commit 9a32457848
5 changed files with 26 additions and 14 deletions

View file

@ -29,9 +29,6 @@ start the swank server to accept remote connection."
#+swank
(swank:stop-server *swank-server-port*)))
(add-hook modules:*initialize-hook* #'initialize)
(add-hook modules:*finalize-hook* #'finalize)
(let ((time-counter 0.0)
(frames-counter 0))
(defun update (delta-time)
@ -48,4 +45,6 @@ start the swank server to accept remote connection."
(setf time-counter 0.0)
(setf frames-counter 0))))
(add-hook modules:*update-hook* #'update)
(modules:register-initialize-fun #'initialize)
(modules:register-finalize-fun #'finalize)
(modules:register-update-fun #'update)

View file

@ -81,9 +81,9 @@ If a thread is available, assign a new job to it."
(if (not (thread-alive-p (thread-thread thread)))
(finalize-thread thread))))))
(add-hook modules:*initialize-hook* #'initialize)
(add-hook modules:*finalize-hook* #'finalize)
(add-hook modules:*update-hook* #'update)
(modules:register-initialize-fun #'initialize)
(modules:register-finalize-fun #'finalize)
(modules:register-update-fun #'update)
(defun push-job (fun args)
"Create a new job using `fun' and `data' and push it into the job-list."

View file

@ -8,7 +8,7 @@
(:nicknames :modules)
(:use :cl
:utils)
(:export :*initialize-hook* :*finalize-hook* :*update-hook*
(:export :register-initialize-fun :register-finalize-fun :register-update-fun
:initialize :finalize :update))
(in-package :stoe.modules)
@ -21,7 +21,9 @@ the program argv.")
"Hook run on finalization.")
(defparameter *update-hook* nil
"Hook run each frame.")
"Hook run each frame.
Functions attached to this hook should expect an argument containing the time
since last frame.")
(defun initialize (&optional argv)
"Perform the engine and subsystems initialization process."
@ -36,3 +38,12 @@ the program argv.")
(defun update (delta-time)
"Update the modules each loop."
(run-hook *update-hook* delta-time))
(defun register-initialize-fun (fun)
(add-hook *initialize-hook* fun 'append))
(defun register-finalize-fun (fun)
(add-hook *finalize-hook* fun))
(defun register-update-fun (fun)
(add-hook *update-hook* fun 'append))

View file

@ -49,9 +49,9 @@ Render a frame and swap buffers."
(gl:clear :color-buffer-bit :depth-buffer-bit)
(glop:swap-buffers *window*))
(add-hook modules:*initialize-hook* #'initialize)
(add-hook modules:*finalize-hook* #'finalize)
(add-hook modules:*update-hook* #'update)
(modules:register-initialize-fun #'initialize)
(modules:register-finalize-fun #'finalize)
(modules:register-update-fun #'update)
(defmethod glop:on-event (window event)
(declare (ignore window event)))

View file

@ -71,10 +71,12 @@
,@body)
(continue () :report "Continue"))))
(defmacro add-hook (hook fun)
(defmacro add-hook (hook fun &optional append)
"Setup `fun' to be called within specified `hook'."
`(unless (member ,fun ,hook)
(setf ,hook (append ,hook (list ,fun)))))
,(if append
`(setf ,hook (append ,hook (list ,fun)))
`(push ,fun ,hook))))
(defmacro remove-hook (hook fun)
"Remove `fun' from `hook'."