stoe/core/modules.lisp

53 lines
2 KiB
Common Lisp

#|
This file is a part of stoe project.
Copyright (c) 2014 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|#
(uiop:define-package :stoe/core/modules
(:use :cl)
(:export #:initialize-modules #:finalize-modules #:update-modules #:defmodule))
(in-package :stoe/core/modules)
(defparameter *modules-list* nil)
(defun initialize-modules (&optional argv)
"Perform the engine and subsystems initialization process."
(format t "Initialize...~%")
(loop for module in *modules-list*
do (funcall (intern "INITIALIZE" (cdr module)) argv)))
(defun finalize-modules ()
"Perform the engine and subsystems initialization process."
(format t "Initialize...~%")
(loop for module in (reverse *modules-list*)
do (funcall (intern "FINALIZE" (cdr module)))))
(defun update-modules (delta-time)
"Update-the modules each loop."
(loop for module in *modules-list*
do (funcall (intern "UPDATE" (cdr module)) delta-time)))
(defun register-module (module priority)
(pushnew (cons priority module) *modules-list*)
(sort *modules-list* (lambda (prio1 prio2)
(< prio1 prio2)) :key #'car))
(defmacro defmodule (module priority)
"Register a new module.
The module is expected to have at least `initialize', `update', and `finalize' functions.
`initialize' accepts an optional `argv' argument,
`update' accepts a delta-time argument."
`(register-module ',module
,(ecase priority
(:first (if (null *modules-list*)
0.0
(1- (caar *modules-list*))))
(:last (if (null *modules-list*)
10.0
(1+ (caar (reverse *modules-list*)))))
(:jobs 1.0)
(:resources 2.0)
(:input 3.0)
(:game 4.0)
(:render 9.0)
(t priority))))