cl-fast-ecs
2023-06-18
Blazingly fast Entity-Component-System microframework.
1cl-fast-ecs ⚡6
https://img.shields.io/gitlab/pipeline-status/lockie/cl-fast-ecs?label=tests&style=plastic&extension=.png https://img.shields.io/gitlab/last-commit/lockie/cl-fast-ecs?style=plastic&extension=.png https://img.shields.io/gitlab/v/tag/lockie/cl-fast-ecs?label=version&style=plastic&extension=.png https://img.shields.io/gitlab/license/lockie/cl-fast-ecs?color=blue&style=plastic&extension=.png https://img.shields.io/mastodon/follow/109994839335624904?color=858AFA&domain=https%3A%2F%2Ffunctional.cafe&label=follow%20on%20mastodon&logo=mastodon&style=plastic&extension=.pngNOTE: this software is of alpha quiality, and the API is subject to change.
cl-fast-ecs
is a Common Lisp library providing an implementation of the Entity-Component-System pattern, primarily focused on speed and interactive development.
ECS is an architectural data-oriented design pattern that allows for the effective processing of a large number of in-game objects while keeping the code and data separated. This provides flexibility in the way that game objects are built at runtime.
See the documentation page for more details.
1.1Features
- Ability to interactively redefine components and systems on the fly.
- Ability to interactively add new components and systems on the fly.
- Native Lisp, no C/C++ code.
- Mininal external dependencies (
alexandria
andtrivial-garbage
).
1.2Installation
Just clone this repository to your Quicklisp's local-projects directory and execute(ql:quickload :cl-fast-ecs)
in your Lisp.Currently tested to work on following Lisp compilers:
1.3Usage
(ql:quickload :cl-fast-ecs)
(use-package :cl-fast-ecs)
(defcomponent position
"Location information"
(x 0.0 :type single-float :documentation "X coordinate")
(y 0.0 :type single-float :documentation "Y coordinate"))
(defcomponent velocity
(x 0.0 :type single-float)
(y 0.0 :type single-float))
(defsystem move
(:components-ro (velocity)
:components-rw (position))
"Moves objects according to their velocity."
(incf position-x velocity-x)
(incf position-y velocity-y))
(defsystem print
(:components-ro (position))
(format t "entity ~a: (~a, ~a)~%" entity position-x position-y))
(let* ((storage (make-storage))
(entity0 (make-entity storage)))
(make-position storage entity0 :x 0.0 :y 0.0)
(make-velocity storage entity0 :x 0.5 :y 0.5)
(make-object storage '((:position :x 1.0 :y 1.0)
(:velocity :x 0.1 :y 0.1)))
(dotimes (i 3)
(run-systems storage)))
1.4Related projects
- cl-ecs offers
defcomponent
/defsys
macros, similar to the ones found in this project, and uses hash tables for component storage. - lisp butts game engine (sic) rolls its own CLOS-based ECS implementation.