Skip to content
Daan van Yperen edited this page May 30, 2019 · 24 revisions

Artemis-odb provides many types of systems. You will use IteratingSystem and BaseSystem the most.

Iterating System

Iterating systems operate over entities that match a certain Aspect.

// What do we subscribe to?
@One(Cookie.class, Bread.class)
@Exclude(Baked.class) 
public class BakingSystem extends IteratingSystem {
        // odb injects dependencies automatically. 
	ComponentMapper<Baked> mBaked;  // used to access component.

	/* called for each matching entity. */
	@Override
	protected void process(int e) {
		mBaked.create(e); // bake cookie! (adds Bake component if missing)
	}
}

See World how to add this system to your game.

Subscribing to entities

To subscribe your system to entities of a certain composition, use aspect annotations.

// Anotations can be combined.
@All(A.class,B.class,C.class) // The entity must have `A` and 'B' and 'C' component.
@One(D.class, E.class)  // The entity must possess at least one of `D` OR `E` component.
@Exclude(F.class, G.class)  // The entity may not possess `F` or 'G' component.
public class MySystem extends IteratingSystem {
..

Dependency injection

Artemis-odb handles most object creation for you. It will inject systems, Component mappers, or any other desired any object into entity systems, during initialization:

public class MySystem extends ... {
    private ComponentMapper<Position> mPosition;
    private MyOtherSystem myOtherSystem;
    private MyObject object;
    private 
}

By default, systems inject inherited fields from superclasses. Override this behavior with @Wire(injectInherited=true).

By default, if @Wire fails to inject a field - typically because the requested type hasn't been added to the world instance - a MundaneWireException is thrown. Override this behavior via @Wire(failOnNull=false).

Explicitly injecting into any object

When injectables are required outside systems, the world can inject any object:

world.inject(this)
Clone this wiki locally