-
Notifications
You must be signed in to change notification settings - Fork 3
Overview
The main concept behind Entity Systems is to completely divide logic and data.
Data is contained by components, and logic by systems. Entities are nothing more than an ID number to identify a group of components that belong with each other.
Systems declare that they work with certain components.
class MySystem extends EntityProcessingSystem
{
public function new()
{
super( new Demand().has( TransformComponent ).has( DisplayComponent ) );
}
}In the above example, this system will receive all entities that have a TransformComponent and DisplayComponent attached to them. ( You can also exclude components by using .lacks( ComponentThatEntitiesMustNOTHave ) )
Contexts are a way to allow systems to communicate with each other and with your application in a completely detached, modular way. They are sort of globals within an EntityWorld.
Creating a context is simple, your class must extend hxE.Context, and cannot have any constructor parameters! To access a context, you use
EntityWorld::getContext<T>( contextId:String, contextClass:Class<T> ):TContexts should not rely on being constructed at any certain point, as they are constructed the first time they are requested, afterwards, the same instance of the context is returned.
EntitySystems can access world contexts after their initialization ( Which includes any processing functions, or entity addition/removal events. ):
override function initialize():Void
{
var myDisplayContext = world.getContext( "DisplayContext", DisplayContext );
//myDisplayContext is ready to be used.
}A context's ID is there in case a user may want to create several contexts, but using the same class. So far, this has not been necessary, and up until a 1.0.0 release, I may remove the need to provide a String ID ( In which case each EntityWorld will only be able to have 1 type of each context class. This would also improve reliability, since you don't need to ensure all systems are accessing the same context ID. )
For more, see the samples on actual usage of Entity Systems, or read the t-machine blog: http://t-machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-1/ ( There are 5 parts! )