# HG changeset patch
# User Steve Losh
Beast can be installed with Quicklisp:
-(ql:quickload :beast) +diff -r 00c5f966ddac -r f3fc28996523 beast/overview/index.html --- a/beast/overview/index.html Fri Dec 16 13:20:20 2016 -0500 +++ b/beast/overview/index.html Fri Dec 23 10:50:32 2016 -0500 @@ -20,12 +20,13 @@(ql:quickload :beast)
There are a couple of ECS libraries for Common Lisp already:
+There were a couple of ECS libraries for Common Lisp already:
-Both of these favor composition over inheritance -- game objects (entities) +
Which were both superseded by net.axity.common-lisp.gamedev.ecs.
+All of these favor composition over inheritance -- game objects (entities) contain various components, but they don't inherit from components.
Beast takes the opposite approach, favoring (restricted) inheritance over composition.
@@ -33,7 +34,7 @@ a little bit less in this crazy world. Aspects are essentially mixins, with some sugar for defining them and running systems over them: -(define-aspect throwable accuracy damage) +(define-aspect throwable accuracy damage) (define-aspect edible nutrition-value) (define-entity dart (throwable)) diff -r 00c5f966ddac -r f3fc28996523 beast/reference/index.html --- a/beast/reference/index.html Fri Dec 16 13:20:20 2016 -0500 +++ b/beast/reference/index.html Fri Dec 23 10:50:32 2016 -0500 @@ -35,7 +35,7 @@Package
BEAST
-
CLEAR-ENTITIES
(function)(CLEAR-ENTITIES) +@@ -43,7 +43,7 @@(CLEAR-ENTITIES)
destroy-entity
will be called for each entity.Returns a list of all the destroyed entites.
-
CREATE-ENTITY
(function)(CREATE-ENTITY CLASS &REST INITARGS) +@@ -52,7 +52,7 @@(CREATE-ENTITY CLASS &REST INITARGS)The
entity-created
generic function will be called just before returning the entity.-
DEFINE-ASPECT
(macro)(DEFINE-ASPECT NAME &REST FIELDS) +@@ -65,7 +65,7 @@ the slot names.(DEFINE-ASPECT NAME &REST FIELDS):initarg
and:accessor
slot options will also be automatically generated.Example:
-(define-aspect edible +(define-aspect edible energy (taste :initform nil)) => @@ -79,7 +79,7 @@-
DEFINE-ENTITY
(macro)(DEFINE-ENTITY NAME ASPECTS &REST SLOTS) +@@ -88,7 +88,7 @@(DEFINE-ENTITY NAME ASPECTS &REST SLOTS)
aspects
should be a list of the aspects this entity should inherit from.
slots
can be zero or more extra CLOS slot definitions.Examples:
-(define-entity potion (drinkable)) +(define-entity potion (drinkable)) (define-entity cheese (edible visible) (flavor :accessor cheese-flavor :initarg :flavor)) @@ -96,7 +96,7 @@-
DEFINE-SYSTEM
(macro)(DEFINE-SYSTEM NAME-AND-OPTIONS +(DEFINE-SYSTEM NAME-AND-OPTIONS ARGLIST &BODY BODY) @@ -121,7 +121,7 @@ entity. Defaults tonil
.Examples:
-(define-system age ((entity lifetime)) +(define-system age ((entity lifetime)) (when (> (incf (lifetime/age entity)) (lifetime/lifespan entity)) (destroy-entity entity))) @@ -129,7 +129,7 @@-
DESTROY-ENTITY
(function)(DESTROY-ENTITY ENTITY) +@@ -139,7 +139,7 @@(DESTROY-ENTITY ENTITY)
ENTITY
(class)A single entity in the game world.
-
ENTITY-CREATED
(generic function)(ENTITY-CREATED ENTITY) +@@ -147,7 +147,7 @@(ENTITY-CREATED ENTITY)The default method does nothing, but users can implement their own auxillary methods to run code when entities are created.
-
ENTITY-DESTROYED
(generic function)(ENTITY-DESTROYED ENTITY) +@@ -155,7 +155,7 @@(ENTITY-DESTROYED ENTITY)The default method does nothing, but users can implement their own auxillary methods to run code when entities are destroyed.
-
MAP-ENTITIES
(function)(MAP-ENTITIES FUNCTION &OPTIONAL (TYPE 'ENTITY)) +diff -r 00c5f966ddac -r f3fc28996523 beast/usage/index.html --- a/beast/usage/index.html Fri Dec 16 13:20:20 2016 -0500 +++ b/beast/usage/index.html Fri Dec 23 10:50:32 2016 -0500 @@ -37,7 +37,7 @@ examples could be things like: location, moveable, visible, edible, sentient.(MAP-ENTITIES FUNCTION &OPTIONAL (TYPE 'ENTITY))Defining Aspects
To define an aspect you use
-define-aspect
:(define-aspect location x y) +@@ -46,13 +46,13 @@(define-aspect location x y) (define-aspect edible nutrition-value)The names of aspect slots will be have the aspect name prepended to them with a slash to avoid clashing between aspects, and the
-initargs
andaccessors
will be added for you. So for example, this:(define-aspect inspectable text) +(define-aspect inspectable text) (define-aspect readable text)Would macroexpand into something roughly like:
-(defclass inspectable () +(defclass inspectable () ((inspectable/text :initarg :inspectable/text :accessor inspectable/text))) @@ -66,7 +66,7 @@You can include extra slot options when defining an aspect's slots, and they'll be passed along to the
-defclass
. This is especially handy for:initform
and:type
.(define-aspect container +(define-aspect container (contents :initform nil)) (define-aspect throwable @@ -81,7 +81,7 @@When you define an aspect named
-foo
Beast also defines afoo?
predicate that returns(typep object 'foo)
, which comes in handy when using higher-order functions:(defun whats-for-dinner? () +@@ -91,7 +91,7 @@ them together.(defun whats-for-dinner? () (remove-if-not #'edible? (container/contents *fridge*)))Defining Entities
You define entity classes using
-define-entity
:(define-entity dart (throwable)) +(define-entity dart (throwable)) (define-entity bread (edible)) (define-entity pie (edible throwable)) (define-entity icebox (container)) @@ -100,7 +100,7 @@The resulting classes will inherit from
-entity
and each of the aspects (in order). This example would expand (roughly) into:(defclass dart (entity throwable) ()) +(defclass dart (entity throwable) ()) (defun dart? (object) (typep object 'dart)) (defclass bread (entity edible) ()) @@ -117,7 +117,7 @@Entity Slot Definitions
You can also specify slot definitions at the entity level, and they'll be passed along to
-defclass
:(define-entity cheese (edible) +(define-entity cheese (edible) (variety :type (member :swiss :cheddar :feta) :initarg :variety :reader :cheese-variety)) @@ -130,7 +130,7 @@Creating and Destroying Entities
After you've defined your entity classes you can can create some entities using
-create-entity
:(defparameter *my-fridge* (create-entity 'icebox)) +(defparameter *my-fridge* (create-entity 'icebox)) (dotimes (i 30) (push (create-entity 'cheese @@ -150,7 +150,7 @@Beast also defines two generic functions called
-entity-created
andentity-destroyed
which don't do anything by default, but are there for you to add methods on if you want. For example:(define-aspect location x y) +(define-aspect location x y) (defvar *world* (make-array (100 100) :initial-element nil)) @@ -169,7 +169,7 @@A system is essentially a function that takes an entity as an argument with zero or more aspects as type specifiers. When you run a system the function will be run on every entity that meet the requirements. For example:
-; No specifiers, this just runs on every entity. +; No specifiers, this just runs on every entity. (define-system log-all-entities (entity) (print entity)) @@ -189,7 +189,7 @@Systems with more than one argument are currently supported, but should be considered experimental. The API may change in the future.
-; Run on all PAIRS of entities that have the appropriate aspects. +; Run on all PAIRS of entities that have the appropriate aspects. (define-system detect-collisions ((e1 location collidable) (e2 location collidable)) ; ... @@ -199,7 +199,7 @@-
define-system
defines a function with the same name as the system, and arun-...
function that will do the actual running for you:(define-system log-all-entities (entity) +(define-system log-all-entities (entity) (print entity)) (run-log-all-entities)