106 lines
3.3 KiB
Common Lisp
106 lines
3.3 KiB
Common Lisp
#|
|
|
This file is a part of stoe project.
|
|
Copyright (c) 2015 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|
|
|#
|
|
|
|
(uiop:define-package :stoe/test/entity
|
|
(:use :cl :prove
|
|
:stoe/core/utils
|
|
:stoe/core/graph
|
|
:stoe/core/entity))
|
|
(in-package :stoe/test/entity)
|
|
|
|
(defparameter *old-entity-array* stoe/core/entity::*entity-array*)
|
|
(defparameter *old-components-table-table* stoe/core/entity::*components-table-table*)
|
|
(defparameter *old-system-dependency-graph* stoe/core/entity::*system-dependency-graph*)
|
|
(setf stoe/core/entity::*entity-array* (make-array 10 :adjustable t :fill-pointer 0))
|
|
(setf stoe/core/entity::*components-table-table* (make-hash-table))
|
|
(setf stoe/core/entity::*system-dependency-graph* (make-graph-node))
|
|
|
|
(stoe/core/entity::ensure-components-table 'component)
|
|
|
|
(plan 21)
|
|
(diag "Define components")
|
|
|
|
(defcomponent comp-base1 ()
|
|
())
|
|
|
|
(ok (stoe/core/entity::components-table 'comp-base1)
|
|
"define component 1")
|
|
|
|
(defcomponent comp-base2 (component)
|
|
())
|
|
|
|
(ok (stoe/core/entity::components-table 'comp-base2)
|
|
"define component 2")
|
|
|
|
(defcomponent comp-derived (comp-base1)
|
|
())
|
|
|
|
(ok (stoe/core/entity::components-table 'comp-derived)
|
|
"define subcomponent")
|
|
|
|
(diag "Entity Creation")
|
|
(defparameter ent1 (create-entity "ent1"))
|
|
|
|
(is (object-id ent1) 0 "Object ID 0")
|
|
|
|
(defparameter ent2 (create-entity "ent2"
|
|
comp-base1))
|
|
|
|
(is (object-id ent2) 1 "Object ID 1")
|
|
(is (length (all-components ent2)) 1 "all-components 2")
|
|
(is (length (components ent2 'comp-base1)) 1 "get-component comp-base1")
|
|
|
|
(defparameter ent3 (create-entity "ent3"
|
|
comp-derived))
|
|
|
|
(is (object-id ent3) 2 "Object ID 2")
|
|
(is (length (all-components ent3)) 1 "all-components 3")
|
|
(is (length (components ent3 'comp-derived)) 1 "get-component comp-derived")
|
|
(is (length (components ent3 'comp-base1)) 1 "get-components comp-base1")
|
|
|
|
(defparameter ent4 (create-entity "ent4"
|
|
comp-base1
|
|
comp-base2
|
|
comp-derived))
|
|
|
|
(is (object-id ent4) 3 "Object ID 3")
|
|
(is (length (all-components ent4)) 3 "all-components 4")
|
|
(is (length (components ent4 'comp-base1)) 2 "get-components comp-base1")
|
|
(is (length (components ent4 'comp-base2)) 1 "get-components comp-base2")
|
|
(is (length (components ent4 'comp-derived)) 1 "get-component comp-derived")
|
|
|
|
(diag "Entity Systems")
|
|
(defesystem system1 (entity (comp comp-base1))
|
|
(declare (ignore entity comp)))
|
|
|
|
(is (first (prior-nodes system1)) stoe/core/entity::*system-dependency-graph*
|
|
"defesystem 1")
|
|
|
|
(defesystem system2 (entity (comp comp-base1))
|
|
(declare (ignore entity comp)))
|
|
|
|
(is (length (stoe/core/entity::system-precedence-list system2)) 1
|
|
"defesystem 2")
|
|
|
|
(defesystem system3 :after system2 (entity (comp comp-base2))
|
|
(declare (ignore entity comp)))
|
|
|
|
(is (length (prior-nodes system3)) 1
|
|
"defesystem 3")
|
|
|
|
(defesystem system4 :before system3 :after system2 (entity (comp comp-base2))
|
|
(declare (ignore entity comp)))
|
|
|
|
(is (length (stoe/core/entity::system-precedence-list system4)) 2
|
|
"defesystem 4")
|
|
|
|
(is (length (stoe/core/entity::system-precedence-list system3)) 3
|
|
"system3 precedence-list")
|
|
|
|
(finalize)
|
|
|
|
(setf stoe/core/entity::*entity-array* *old-entity-array*)
|
|
(setf stoe/core/entity::*components-table-table* *old-components-table-table*)
|
|
(setf stoe/core/entity::*system-dependency-graph* *old-system-dependency-graph*)
|