Make entity-system a module updated in the game loop

Each system is updated in parallel but the module itself will wait for
all the job to complete
This commit is contained in:
Renaud Casenave-Péré 2016-09-07 15:17:25 +02:00
parent 9ad17fecb4
commit 9ab27987b4

View file

@ -4,8 +4,9 @@
|#
(uiop:define-package :stoe/core/entity
(:use :cl :alexandria
:stoe/core/utils)
(:use :cl :alexandria :blackbird
:stoe/core/utils
:stoe/core/jobs)
(:export #:entity #:object-id
#:component #:owner #:activep
#:components #:component #:all-components
@ -271,6 +272,28 @@ class OPTIONS are supported together with the option :NEEDS used to define the d
(defun run-esystem (system)
(with-slots (components) system
(loop for classname in components
do (loop for component in (gethash classname *components-table-table*)
do (esystem-update system :entity (owner component) :component component)))))
(wait (all (flatten
(loop for classname in components
collect (loop for component being the hash-value of (gethash classname *components-table-table*)
collect (async-job (system component)
(esystem-update system :entity (owner component) :component component)))))))))
(defun initialize (&optional argv)
"Initialize the entity system module."
(format t "Initialize Entity System module~%")
(loop for system in *system-list*
do (esystem-initialize system)))
(defun finalize ()
"Finalize the entity system module."
(format t "Finalize Entity System module~%")
(loop for system in *system-list*
do (esystem-finalize system)))
(defun update (delta-time)
(declare (ignore delta-time))
(wait (all (loop for system in *system-list*
collect (async-job (system)
(run-esystem system))))))
(defmodule stoe/engine/entity :game)