View Source ECSx.Manager (ECSx v0.3.0)

The Manager for your ECSx application.

In an ECSx application, the Manager is responsible for:

  • starting up ETS tables for each Component Type, where the Components will be stored
  • prepopulating the game content into memory
  • keeping track of the Systems to run, and their run order
  • configuring the tick rate for the application
  • running the Systems every tick

tick_rate-option

:tick_rate option

The mix ecsx.setup generator creates a Manager file with :tick_rate set to 20 (i.e. 20 ticks per second). Feel free to change this number to fit the needs of your application.

components-0-and-systems-0

components/0 and systems/0

Your Manager module must contain two zero-arity functions called components and systems which return a list of all Component Types and Systems in your application. The order of the Component Types list is irrelevant, but the order of the Systems list is very important, because the Systems are run consecutively in the given order.

setup-block

setup block

Another important piece of the Manager module is the setup block. Here you can load all the necessary data for your app before any Systems run or users connect. See setup/1 for more information.

Link to this section Summary

Functions

Runs the given code block during startup.

Link to this section Functions

Runs the given code block during startup.

The code will be run during the Manager's initialization (so pay special attention to the position of ECSx.Manager in your application's supervision tree). The Component tables will be created before setup is executed.

example

Example

defmodule YourApp.Manager do
  use ECSx.Manager

  setup do
    for npc <- YourApp.fetch_npc_spawn_info() do
      YourApp.Components.Name.add(npc.id, npc.name)
      YourApp.Components.HitPoints.add(npc.id, npc.hp)
      YourApp.Components.Location.add(npc.id, npc.spawn_location)
    end
  end
end

This setup will spawn each NPC with Components for Name, HitPoints, and Location.