Skip to content
ConcordConcordConcord

World

A collection of Systems and Entities.

If the concord folder is in the root directory of your game, you can import this module like so:

concord.system = require('concord.world')

A World emits events so Systems can iterate their Pools. A World contains any amount of Systems and Entities, plus optional named resources. World(...) is equivalent to World.new(...). Override optional callbacks below on the world instance (methods are copied onto each instance at creation).

Name Type Description
ENABLE_OPTIMIZATION boolean When true, shallow-copies class methods onto each instance for faster access (default true)
Method Description
World.new Creates a new World.
World:addEntity Queues an Entity to be added to the World.
World:newEntity Creates a new Entity and queues it to be added to the World.
World:query Queries flushed Entities against a Filter definition.
World:removeEntity Queues an Entity to be removed from the World.
World:canFlush Returns whether a Flush can currently be performed.
World:flush Applies queued Entity additions, removals, and dirty reevaluations.
World:addSystem Adds a System to the World.
World:addSystems Adds multiple Systems to the World.
World:hasSystem Returns whether the World has a System.
World:getSystem Gets a System from the World.
World:emit Emits a callback in the World.
World:emitNoFlush Emits a callback in the World without flushing.
World:clear Removes all Entities from the World and flushes.
World:getEntities Returns the List of flushed Entities in the World.
World:getSystems Returns the List of Systems in the World.
World:serialize Serializes serializable Entities in the World.
World:deserialize Deserializes Entities into the World.
World:setKeyGenerator Sets the function used to generate Entity keys.
World:getEntityByKey Gets an Entity by its key.
World:setResource Sets a named resource on the World (singleton shared state, not an Entity Component).
World:getResource Gets a named resource from the World.
World:onEntityAdded Callback for when an Entity is added to the World.
World:onEntityRemoved Callback for when an Entity is removed from the World.
World:beforeEmit Callback before World:emit forwards an event to Systems.
World:afterEmit Callback after World:emit has forwarded an event to Systems.
World:beforeSystemCallback Callback before World:emit forwards an event to a System.
World:afterSystemCallback Callback after World:emit has forwarded an event to a System.
Type Description
SerializedWorld Payload from World:serialize, passed to World:deserialize.