public void ExecuteInOutFilter(IFilter filter, Action <Entity> callbackIn, Action <Entity> callbackOut, FilterTarget target) { switch (target) { case FilterTarget.All: for (int i = 0; i < this.Components.Count; i++) { if (this.Components[i] is Entity) { if (filter.Contains(this.Components[i] as Entity)) { callbackIn(this.Components[i] as Entity); } else { callbackOut(this.Components[i] as Entity); } } } break; case FilterTarget.AlwaysUpdate: for (int i = 0; i < this.AlwaysUpdate.Count; i++) { if (this.AlwaysUpdate[i] is Entity) { if (filter.Contains(this.AlwaysUpdate[i] as Entity)) { callbackIn(this.AlwaysUpdate[i] as Entity); } else { callbackOut(this.AlwaysUpdate[i] as Entity); } } } break; case FilterTarget.OnScreen: EntityRenderer r = this.renderer as EntityRenderer; if (r != null) { foreach (Entity e in this.integrator.GetEntitiesInRect(r.TopLeft, r.BottomRight, true)) { if (filter.Contains(e)) { callbackIn(e); } else { callbackOut(e); } } } break; } }
public IEnumerable <Entity> GetEntitiesByFilter(IFilter filter, FilterTarget target) { switch (target) { case FilterTarget.All: for (int i = 0; i < this.Components.Count; i++) { if (this.Components[i] is Entity && filter.Contains(this.Components[i] as Entity)) { yield return(this.Components[i] as Entity); } } break; case FilterTarget.AlwaysUpdate: for (int i = 0; i < this.AlwaysUpdate.Count; i++) { if (this.AlwaysUpdate[i] is Entity && filter.Contains(this.AlwaysUpdate[i] as Entity)) { yield return(this.Components[i] as Entity); } } break; case FilterTarget.OnScreen: EntityRenderer r = this.renderer as EntityRenderer; if (r != null) { foreach (Entity e in this.integrator.GetEntitiesInRect(r.TopLeft, r.BottomRight, true)) { if (filter.Contains(e)) { yield return(e); } } } break; } }