Works again.
[uxul-world.git] / objectarray.lisp
1 ;;; Copyright 2009-2011 Christoph Senjak
2
3 (in-package :uxul-world)
4
5 (declaim (inline get-by-index))
6
7 (defun get-by-index (index array)
8   (svref array index))
9
10 (defun create-object-array ()
11   (make-array (list (length +class-indices+))
12               :element-type 'list
13               :initial-element nil
14               :adjustable nil))
15
16 (defun add-object-of-class (object array)
17   (dolist (class (c2mop:class-precedence-list (class-of object)))
18     (let ((index (position (class-name class) +class-indices+)))
19       (if index
20           (pushnew object (svref array index))))))
21
22 (defun get-objects-of-class (class-name array)
23   (get-by-index (position class-name +class-indices+) array))
24
25
26 (define-compiler-macro get-objects-of-class (&whole form class-name array)
27    (if (constantp class-name)
28        `(get-by-index ,(position (eval class-name) +class-indices+) ,array)
29        form))
30
31 ;; for rooms
32
33 (defmethod add-object ((room room) (object t))
34   (add-object-of-class object (object-array room)))
35
36 (defun get-objects (room class)
37   (get-objects-of-class class (object-array room)))
38
39 (define-compiler-macro get-objects (&whole form room class-name)
40   (format t "Compiler Macro for get-objects...")
41   (print (if (constantp class-name)
42       `(get-by-index ,(position (eval class-name) +class-indices+) (object-array ,room))
43       form
44       )))