ecs v0.2.1 ECS.Service behaviour

Functions to setup and control services.

A service iterates over entities with certain components, defined in component_types/0, and calls perform/1 on each entity. perform/1 should return the entity_pid when the entity should continue to exist in the shared collection.

Examples

# Define a service to display entities' names.
defmodule DisplayNames do
  @behaviour ECS.Service

  # Accepts entities with a "name" component.
  def component_types, do: [:name]

  def perform(entity) do
    # Displays the entity's name.
    IO.puts ECS.Entity.get(entity, :name)

    # Return the entity so that it is passed onto other services.
    entity
  end
end

# Run entities through systems.
updated_entities = ECS.Service.run([DisplayNames], entities)

Summary

Functions

Run services over entities

Functions

run(list, entities)

Run services over entities.

Callbacks

component_types()

Specs

component_types :: [atom]
perform(pid)

Specs

perform(pid) :: pid