-
Notifications
You must be signed in to change notification settings - Fork 3
World
The World in an ECS architecture ties together the Systems and the Entities on which they operate. It contains a list of Systems, an Entity Manager, and a Blackboarding system. Normally, you would have a single World to contain all the objects in your game. You could conceivably maintain multiple Worlds simultaneously but I haven't yet found a use-case for this.
The World keeps track of its Systems in two separate lists: one for the update loop and one for the draw loop. The Systems will be executed sequentially in the order that they were added to the World. When the System is added to the World, it is given a World reference so that the System can use the World to retrieve entities or get the milliseconds that have elapsed since the previous frame.
The Entity Manager stores entities in such a way that they can be retrieved efficiently by either their Component list or by a Tag. It is used by Systems to retrieve matching Entities each frame.
This is a simple hash attached to the World that can be used to pass data through the ECS framework when necessary. There is a World reference in every System, so you can use it to pass data between Systems or from your main game class into your Systems. In general, it's best to avoid doing this since it can lead to dangling object references that don't get garbage collected, but it can be quite useful when used judiciously.