1 module artemisd.aspect; 2 3 import std.bitmanip; 4 import artemisd.component; 5 6 void set(alias ba, T,R...)() if( is(T:Component) ) 7 { 8 if( ba.length < T.TypeId + 1 ) 9 ba.length = T.TypeId + 1; 10 ba[T.TypeId] = 1; 11 12 static if( R.length ) 13 set!(ba, R)(); 14 } 15 16 final class Aspect 17 { 18 private BitArray allSet; 19 private BitArray exclusionSet; 20 private BitArray oneSet; 21 22 BitArray getAllSet() 23 { 24 return allSet; 25 } 26 27 BitArray getExclusionSet() 28 { 29 return exclusionSet; 30 } 31 32 BitArray getOneSet() 33 { 34 return oneSet; 35 } 36 37 Aspect all(T...)() 38 { 39 set!(allSet, T)(); 40 return this; 41 } 42 43 Aspect exclude(T...)() 44 { 45 set!(exclusionSet, T)(); 46 return this; 47 } 48 49 Aspect one(T...)() 50 { 51 set!(oneSet, T)(); 52 return this; 53 } 54 55 static Aspect getAspectFor(T...)() 56 { 57 return getAspectForAll!T(); 58 } 59 60 static Aspect getAspectForAll(T...)() 61 { 62 Aspect aspect = new Aspect(); 63 aspect.all!T(); 64 return aspect; 65 } 66 67 static Aspect getAspectForOne(T...)() 68 { 69 Aspect aspect = new Aspect(); 70 aspect.one!T(); 71 return aspect; 72 } 73 74 static Aspect getEmpty() 75 { 76 return new Aspect(); 77 } 78 }