Aspect.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Specialized;
  3. namespace MonoGame.Extended.ECS
  4. {
  5. public class Aspect
  6. {
  7. internal Aspect()
  8. {
  9. AllSet = new BitVector32();
  10. ExclusionSet = new BitVector32();
  11. OneSet = new BitVector32();
  12. }
  13. public BitVector32 AllSet;
  14. public BitVector32 ExclusionSet;
  15. public BitVector32 OneSet;
  16. public static AspectBuilder All(params Type[] types)
  17. {
  18. return new AspectBuilder().All(types);
  19. }
  20. public static AspectBuilder One(params Type[] types)
  21. {
  22. return new AspectBuilder().One(types);
  23. }
  24. public static AspectBuilder Exclude(params Type[] types)
  25. {
  26. return new AspectBuilder().Exclude(types);
  27. }
  28. public bool IsInterested(BitVector32 componentBits)
  29. {
  30. if (AllSet.Data != 0 && (componentBits.Data & AllSet.Data) != AllSet.Data)
  31. return false;
  32. if (ExclusionSet.Data != 0 && (componentBits.Data & ExclusionSet.Data) != 0)
  33. return false;
  34. if (OneSet.Data != 0 && (componentBits.Data & OneSet.Data) == 0)
  35. return false;
  36. return true;
  37. }
  38. }
  39. }