subscribe to component fields; notified when value is updated
supplements systems; can replace "reactive" systems
desired performance characteristics (dev and artemis-odb-plugin):
dev/no plugin: artemis internally copies all component data and compares with actual. somewhat wasteful and slow, but convenient during dev.
plugin/build-time: intercepts field writes and replaces them with a generated setter; the generated method sets a global dirty state; overhead should be minimal. this won't work in multi-threaded contexts however (ie, when running simultaneous active worlds on multiple threads).
possible to control frequency of flushing as of yet not notified listeners.
@Relay: component scaffolding
Only primitive types and String are supported.
public class Layer extends Component {
@Relay // mark primitive fields and strings
public int order;
}
RelayProcessor: listening in on updated values
// this is the actual contract - the @Relay on Layer::order
// is only validated and serves as documentation; so that
// we don't accidentally forget that we might be running
// custom code against the component.
@Relay.Receiver(type = Layer.class, field = "order")
public class LayerOrderRelay
implements RelayProcessor<Layer> {
// auto-@Wire
private ComponentMapper<HudRenderable> hudRenderableMapper;
@Override // compare to systems' begin/end
public void begin(IntBag entites) {}
@Override
public void onUpdate(int entityId,
Layer layer) {
boolean isHud = hudRenderableMapper.has(entityId);
if (layer.isUiLayer() != isHud)
hudRenderableMapper.set(entityId, !isHud);
}
@Override // just like systems; these are executed in batch
public void end(IntBag entites) {}
}
A @Relayed field can have multiple registered LayerProcessors.
RelaySystem (?, not sure about the name) is responsible for executing the processors.
RelaySystem may flush multiple times per processing round; best controlled via custom invocation strategies
What?
@Relay
: component scaffoldingOnly primitive types and String are supported.
RelayProcessor: listening in on updated values
@Relayed
field can have multiple registered LayerProcessors.