diff --git a/doc/index.html b/doc/index.html index 5d7e6fb..5452439 100644 --- a/doc/index.html +++ b/doc/index.html @@ -46,8 +46,10 @@
tiny-ecs+
+
| tiny.system (table) | -Creates a default System. | +tiny.system (table, attributes) | +Creates a new System or System class. |
| tiny.processingSystem (table) | -Creates a Processing System. | +Creates a new Processing System or Processing System class. | |
| tiny.sortedSystem (table) | -Creates a Sorted Processing System. | +tiny.getSystemEntityCount (system) | +Get number of Entities in the System. |
A Filter is a function that selects which Entities apply to a System. +
A Filter is a function that selects which Entities apply to a System. Filters take two parameters, the System and the Entity, and return a boolean value indicating if the Entity should be processed by the System.
Filters must be added to Systems by setting the filter field of the System.
- Filter’s returned by tiny.requireAll and tiny.requireAny are immutable
+ Filter's returned by tiny.requireAll and tiny.requireAny are immutable
and can be used by multiple Systems.
local f1 = tiny.requireAll("position", "velocity", "size")
@@ -201,6 +206,8 @@ print(f2(nil, e1), f2(nil, e2), f2(nil, e3)) -- prints true, true, true
filter = tiny.requireAll("image", tiny.rejectAny("Player", "Enemy"))
+
+ A System is a wrapper around function callbacks for manipulating Entities. +
A System is a wrapper around function callbacks for manipulating Entities. Systems are implemented as tables that contain at least one method; an update function that takes parameters like so:
function system:update(dt).function system:update(dt).There are also a few other optional callbacks:
function system:filter(entity)function system:onAdd(entity)function system:onRemove(entity)function system:onModify(dt)function system:filter(entity) - Returns true if this System should
+ include this Entity, otherwise should return false. If this isn't specified,
+ no Entities are included in the System.function system:onAdd(entity) - Called when an Entity is added to the
+ System.function system:onRemove(entity) - Called when an Entity is removed
+ from the System.function system:onModify(dt) - Called when the System is modified by
+ adding or removing Entities from the System.For Filters, it is convenient to use tiny.requireAll or tiny.requireAny, but one can write their own filters as well. Set the Filter of a System like so:
-system.filter = tiny.requireAll("a", "b", "c")
-
or
-function system:filter(entity)
return entity.myRequiredComponentName ~= nil
end
@@ -327,41 +313,59 @@ end
commonly used.
-- The
active flag is whether or not the System is updated automatically.
-Inactive Systems should be updated manually or not at all via
-system:update(dt). Defaults to true.
-- The ‘entities’ field is an ordered list of Entities in the System. This
-list can be used to quickly iterate through all Entities in a System.
-- The
indices field is a table of Entity keys to their indices in the
-entities list. Most Systems can ignore this.
-- The
modified flag is an indicator if the System has been modified in
-the last update. If so, the onModify callback will be called on the System
-in the next update, if it has one. This is usually managed by tiny-ecs, so
-users should mostly ignore this, too.
+ - The
active flag is whether or not the System is updated automatically.
+ Inactive Systems should be updated manually or not at all via
+ system:update(dt). Defaults to true.
+ - The 'entities' field is an ordered list of Entities in the System. This
+ list can be used to quickly iterate through all Entities in a System.
+ - The
indices field is a table of Entity keys to their indices in the
+ entities list. Most Systems can ignore this.
+ - The
modified flag is an indicator if the System has been modified in
+ the last update. If so, the onModify callback will be called on the System
+ in the next update, if it has one. This is usually managed by tiny-ecs, so
+ users should mostly ignore this, too.
+ "process", "sorted", and "interval".
-
- "process" marks the new System as a Processing System. Processing
+ Systems process each entity individual, and are usually what is needed.
+ Processing Systems have three extra callbacks compared to a vanilla System.
nil to create a new System.
- function system:preProcess(entities, dt) - Called before iterating
+ over each Entity.function system:postProcess(entities, dt) - Called for each Entity in
+ the System.function system:process(entity, dt) - Called after iteration.
+ Processing Systems have their own update method, so don't implement a
+ a custom update callback for Processing Systems."sorted" marks the new System as a Sorted System. Sorted Systems sort
+ their Entities according to a user-defined method, system:compare(e1, e2),
+ which should return true if e1 should come before e2 and false otherwise."interval" marks the new System as an Interval System. Interval
+ Systems are updated regulary according to an interval rather than every time
+ the world is update. This is useful for Systems that don't need to be updated
+ often or need be deterministic. Interval Systems have a user-defined field
+ interval that is the time interval between updates. If no interval is
+ specified, a default of 1 is used. If table is nil, this function uses an empty table.
+
-
A Processing System iterates through its Entities in no particluar order, and - updates them individually. It has two important fields:
- -function system:process(entity, dt)function system:filter(entity)tiny.system(table, { "process" }).
-There are also a few other optional callbacks, including the optional - callbacks in tiny.system:
-function system:preProcess(entities, dt)function system:postProcess(entities, dt)Processing System. - - -
nil to create a new
- function system:process(entity, dt)function system:compare(entity1, entity2)function system:filter(entity)Sorted Systems have the same optitonal callbacks as ProcessingSystems. - Sorted System. -
nil to create a new
- For all World functions except tiny.world(…), object-oriented syntax can
+
For all World functions except tiny.world(...), object-oriented syntax can
be used instead of the documented syntax. For example,
tiny.add(world, e1, e2, e3) is the same as world:add(e1, e2, e3).
+
filter,
+ which is a Filter that selects Systems from the World. Only selected Systems
+ are updated. Put this function in your main loop.
-