Module tiny-ecs
Info:
| tiny.activate (world, ...) |
Activates Systems in the World. |
| tiny.add (world, ...) |
Shortcut for adding multiple Entities and Systems to the World. |
| tiny.addEntity (world, entity) |
Adds an Entity to the world. |
| tiny.addSystem (world, system) |
Adds a System to the world. |
| tiny.clearEntities (world) |
Removes all Entities from the World. |
| tiny.clearSystems (world) |
Removes all Systems from the World. |
| tiny.deactivate (world, ...) |
Deactivates Systems in the World. |
| tiny.getEntityCount (world) |
Gets count of Entities in World. |
| tiny.getSystemCount (world) |
Gets count of Systems in World. |
| tiny.getSystemIndex (world, system) |
Gets the index of a System in the world. |
| tiny.manageEntities (world) |
Adds and removes Entities that have been marked. |
| tiny.manageSystems (world) |
Adds and removes Systems that have been marked from the World. |
| tiny.remove (world, ...) |
Shortcut for removing multiple Entities and Systems from the World. |
| tiny.removeEntity (world, entity) |
Removes an Entity to the World. |
| tiny.removeSystem (world, system) |
Removes a System from the world. |
| tiny.setSystemIndex (world, system, index) |
Sets the index of a System in the world. |
| tiny.update (world, dt) |
Updates the World. |
| tiny.updateSystem (world, system, dt) |
Updates a System. |
| tiny.world (...) |
Creates a new World. |
Filter functions
A Filter is a function that selects which Entities apply to a System.
-
tiny.requireAll (...)
-
Makes a Filter that filters Entities with specified Components.
An Entity must have all Components to match the filter.
Parameters:
-
tiny.requireOne (...)
-
Makes a Filter that filters Entities with specified Components.
An Entity must have at least one specified Component to match the filter.
Parameters:
System functions
A System is a wrapper around function callbacks for manipulating Entities.
-
tiny.processingSystem (table)
-
Creates a Processing System. 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), and function
system:filter(entity). entities is an unordered table of Entities with
Entities as KEYS, and dt is the delta time. There are also a few other
optional callbacks:
function system:preProcess(entities, dt) - returns nil,
function system:postProcess(entities, dt) - returns nil,
function system:onAdd(entity) - returns nil,
function system:onRemove(entity) - returns nil.
For Filters, it is conveient to use tiny.requireAll or tiny.requireOne,
but one can write their own filters as well.
Parameters:
- table
A table to be used as a System, or
nil to create a new
Processing System.
-
tiny.system (table)
-
Creates a System. Systems are tables that contain at least one field;
an update function that takes parameters like so:
function system:update(entities, dt). entities is an unordered table of
Entities with Entities as KEYS, and dt is the delta time. There are also a
few other optional callbacks:
function system:filter(entity) - returns a boolean,
function system:onAdd(entity) - returns nil,
function system:onRemove(entity) - returns nil.
For Filters, it is conveient to use tiny.requireAll or tiny.requireOne,
but one can write their own filters as well.
Parameters:
- table
A table to be used as a System, or
nil to create a new System.
World functions
A World is a container that manages Entities and Systems. The tiny-ecs module
is set to be the
__index of all World tables, so the often clearer syntax of
World:method can be used for any function in the library. For example,
tiny.add(world, e1, e2, e3) is the same as
world:add(e1, e2, e3).
-
tiny.activate (world, ...)
-
Activates Systems in the World.
Activated Systems will be update whenever tiny.update(world, dt) is called.
Parameters:
- world
- ...
Systems to activate. The Systems must already be added to the
World.
-
tiny.add (world, ...)
-
Shortcut for adding multiple Entities and Systems to the World.
New objects will enter the World the next time World:update(dt) is called.
Also call this method when an Entity has had its Components changed, such
that it matches different Filters.
Parameters:
- world
- ...
Systems and Entities
-
tiny.addEntity (world, entity)
-
Adds an Entity to the world.
The new Entity will enter the world next time World:update is called.
Also call this on Entities that have changed Components such that it
matches different systems.
Parameters:
-
tiny.addSystem (world, system)
-
Adds a System to the world.
The new System will enter the world next time World:update is called.
Parameters:
-
tiny.clearEntities (world)
-
Removes all Entities from the World.
When World:update(dt) is next called,
all Entities will be removed.
Parameters:
-
tiny.clearSystems (world)
-
Removes all Systems from the World.
When World:update(dt) is next called,
all Systems will be removed.
Parameters:
-
tiny.deactivate (world, ...)
-
Deactivates Systems in the World.
Deactivated Systems must be update manually, and will not update when the
rest of World updates. They will, however, process new Entities added while
the System is deactivated.
Parameters:
- world
- ...
Systems to deactivate. The Systems must already be added to the
World.
-
tiny.getEntityCount (world)
-
Gets count of Entities in World.
Parameters:
-
tiny.getSystemCount (world)
-
Gets count of Systems in World.
Parameters:
-
tiny.getSystemIndex (world, system)
-
Gets the index of a System in the world. Lower indexed Systems are processed
before higher indexed systems.
Parameters:
-
tiny.manageEntities (world)
-
Adds and removes Entities that have been marked.
The user of this library should seldom if ever call this.
Parameters:
-
tiny.manageSystems (world)
-
Adds and removes Systems that have been marked from the World.
The user of this library should seldom if ever call this.
Parameters:
-
tiny.remove (world, ...)
-
Shortcut for removing multiple Entities and Systems from the World.
Objects will exit the World the next time World:update(dt) is called.
Parameters:
- world
- ...
Systems and Entities
-
tiny.removeEntity (world, entity)
-
Removes an Entity to the World.
The Entity will exit the World next time World:update is called.
Also call this on Entities that have changed Components such that it
matches different systems.
Parameters:
-
tiny.removeSystem (world, system)
-
Removes a System from the world.
The System will exit the World next time World:update is called.
Parameters:
-
tiny.setSystemIndex (world, system, index)
-
Sets the index of a System in the world. Changes the order in
which they Systems processed, because lower indexed Systems are processed
first.
Parameters:
-
tiny.update (world, dt)
-
Updates the World.
Frees Entities that have been marked for freeing, adds
entities that have been marked for adding, etc.
Parameters:
-
tiny.updateSystem (world, system, dt)
-
Updates a System.
Parameters:
- world
- system
A System in the World to update
- dt
Delta time
-
tiny.world (...)
-
Creates a new World.
Can optionally add default Systems and Entities.
Parameters:
- ...
Systems and Entities to add to the World
Returns:
A new World