From 4ae55c2274d15891532897d93f6c24945f7d2a3a Mon Sep 17 00:00:00 2001
From: bakpakin
+
+
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 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: There are also a few other optional callbacks: 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: orModule
tiny-ecsInfo:
@@ -83,16 +85,16 @@
System functions
-
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.
World functions
@@ -126,8 +128,8 @@
Shortcut for removing multiple Entities and Systems from the World.
-
tiny.update (world, dt)
- Updates the World.
+ tiny.update (world, dt, filter)
+ Updates the World by dt (delta time).
tiny.clearEntities (world)
@@ -151,7 +153,7 @@
@@ -159,14 +161,17 @@
tiny.setSystemIndex (world, system, index)
- Sets the index of a System in the World.
+ Sets the index of a System in the World, and returns the old index.
- Filter functions
+ Filter functions
- 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"))
- Parameters:
-
-
@@ -232,12 +233,6 @@ filter = tiny.requireAll("image", tiny.rejectAny("Player", "Enemy"))
Components and Filters.
- Parameters:
-
-
@@ -253,12 +248,6 @@ filter = tiny.requireAll("image", tiny.rejectAny("Player", "Enemy"))
Filters, and selects all other Entities.
- Parameters:
-
-
@@ -274,12 +263,6 @@ filter = tiny.requireAll("image", tiny.rejectAny("Player", "Enemy"))
Components and Filters, and selects all other Entities.
- Parameters:
-
-
@@ -287,36 +270,39 @@ filter = tiny.requireAll("image", tiny.rejectAny("Player", "Enemy"))
System functions
+ System functions
-
-
-
function system:update(dt).function system:update(dt).
-
-
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.
-
system.filter = tiny.requireAll("a", "b", "c")
function system:filter(entity)
return entity.myRequiredComponentName ~= nil
end
@@ -327,41 +313,59 @@ end
commonly used.
-
+ 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.indices field is a table of Entity keys to their indices in the
-entities list. Most Systems can ignore this.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.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.indices field is a table of Entity keys to their indices in the
+ entities list. Most Systems can ignore this.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" 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.
-