Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. bucket: Map<Bits, IntArray> = ...
  2.  
  3. fun getEntities(aspect: Aspect): IntArray {
  4. var result = HashMap<Bits, IntArray>()
  5.  
  6. // 1st pass, "allOf"
  7. if (aspect.required == Bits.ZERO) {
  8. result.addAll(bucket)
  9. } else {
  10. bucket.forEach { (bits, entities) ->
  11. if (bits AND aspect.required == aspect.required) {
  12. result.add(bits, entities)
  13. }
  14. }
  15. }
  16.  
  17. // 2nd pass, "anyOf"
  18. if (aspect.optional != Bits.ZERO) {
  19. result = result.filter { (bits, entities) ->
  20. bits AND aspect.optional != Bits.ZERO
  21. }.toMap()
  22. }
  23.  
  24. // 3rd pass, "excluding"
  25. if (aspect.excluded != Bits.ZERO) {
  26. result = result.filter { (bits, entities) ->
  27. bits AND aspect.excluded == Bits.ZERO
  28. }
  29. }
  30.  
  31. return result.values().reduce {base, next -> ...}
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement