Skip to content

Commit

Permalink
junkdog#385: ctor bool param: enable/disable processing LinkSites la…
Browse files Browse the repository at this point in the history
…cking a link listener
  • Loading branch information
junkdog committed Apr 28, 2016
1 parent 1b5247a commit 66ec1e7
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions artemis/src/main/java/com/artemis/link/EntityLinkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ public class EntityLinkManager extends BaseEntitySystem {
final Bag<LinkSite> singleLinkSites = new Bag<LinkSite>();
final Bag<Bag<LinkSite>> multiLinkSites = new Bag<Bag<LinkSite>>();

public EntityLinkManager(Aspect.Builder aspect) {
private final boolean requireListener;

public EntityLinkManager(Aspect.Builder aspect, boolean requireListenerToProcess) {
super(aspect);
this.requireListener = requireListenerToProcess;
}

public EntityLinkManager() {
this(all());
this(all(), false);
}

@Override
Expand All @@ -39,15 +42,23 @@ protected void initialize() {
world.getComponentManager().getTypeFactory().register(listener);
}


@Override
protected void processSystem() {
for (LinkSite ls : singleLinkSites) {
if (requireListener && ls.listener == null)
continue;

ls.process();
}

for (Bag<LinkSite> ls : multiLinkSites) {
for (int i = 0, s = ls.size(); s > i; i++) {
ls.get(i).process();
for (Bag<LinkSite> sites : multiLinkSites) {
for (int i = 0, s = sites.size(); s > i; i++) {
LinkSite ls = sites.get(i);
if (requireListener && ls.listener == null)
continue;

ls.process();
}
}
}
Expand Down Expand Up @@ -85,14 +96,14 @@ public void register(Class<? extends Component> component, String field, LinkLis

ComponentType ct = world.getComponentManager().getTypeFactory().getTypeFor(component);
for (LinkSite site : singleLinkSites) {
if (ct.equals(site.type) && (f == null ||site.field.equals(f))) {
if (ct.equals(site.type) && (f == null || site.field.equals(f))) {
site.listener = listener;
}
}
for (Bag<LinkSite> ls : multiLinkSites) {
for (int i = 0, s = ls.size(); s > i; i++) {
LinkSite site = ls.get(i);
if (ct.equals(site.type) && (f == null ||site.field.equals(f))) {
if (ct.equals(site.type) && (f == null || site.field.equals(f))) {
ls.get(i).process();
}
}
Expand Down

0 comments on commit 66ec1e7

Please sign in to comment.