-
Notifications
You must be signed in to change notification settings - Fork 1
@ArtemisManager
Adrian Papari edited this page Nov 14, 2013
·
3 revisions
Configures an artemis Manager
by injecting code during the compilation phase.
Simulates Aspects by prepending if-checks before any methods defined in EntityObserver
.
Fields for ComponentMappers, EntitySystems and Mangers are wired in the initialize method, prior to any existing code in the initialize method is executed.
Component mappers are named according to the component type they operate on, suffixed with -Mapper. Systems and managers retain their full type name. All field names are camelCased.
@ArtemisManager(
requires={Cullable.class, Renderable.class})
public final class CullableManager extends Manager
{
@Override
protected void initialize() {}
@Override
public void added(Entity e)
{
Vector2 size = cullableMapper.get(e).size;
Sprite sprite = renderableMapper.get(e).sprite;
if (size.x == 0) size.x = sprite.getWidth();
if (size.y == 0) size.y = sprite.getHeight();
}
}
@WovenByTheHuntress // marker annotation; don't process class when present
@ArtemisManager(
requires={Cullable.class, Renderable.class})
public final class CullableManager extends Manager
{
private ComponentMapper<Cullable> cullableMapper;
private ComponentMapper<Renderable> renderableMapper;
@Override
protected void initialize()
{
cullableMapper = world.getMapper(Cullable.class);
renderableMapper = world.getMapper(Renderable.class);
}
@Override
public void added(Entity e)
{
if (!cullableMapper.has(e)) return;
if (!renderableMapper.has(e) return;
Vector2 size = cullableMapper.get(e).size;
Sprite sprite = renderableMapper.get(e).sprite;
if (size.x == 0) size.x = sprite.getWidth();
if (size.y == 0) size.y = sprite.getHeight();
}
}