internal static bool Match(Aspect aspect, Utils.BitMask left, Utils.BitMask right) { switch (aspect) { case Aspect.Has: for (int i = 0; i < left.Count && i < right.Count; i++) { if (right.Get(i) == true && left.Get(i) != true) { return(false); } } return(true); case Aspect.Match: return(left == right); case Aspect.Complement: for (int i = 0; i < left.Count && i < right.Count; i++) { if (left.Get(i) != !right.Get(i)) { return(false); } } return(true); } return(false); }
public SystemInfo(Utils.BitMask mask, Processor processor, Dictionary <int, Entity> entities) { this.mask = mask; this.processor = processor; this.entities = entities; }
internal Entity(Caboodle entityWorld, int id) { this._world = entityWorld; this._id = id; this._active = true; this.mask = new Utils.BitMask(); }
/// <summary> /// Instantiates the system-type's class and adds it to the manager along with its attributes. /// </summary> public void Add(Type stype) { // Instantiate system class var system = Activator.CreateInstance(stype) as Processor; var attr = stype.GetCustomAttributes(typeof(Attributes.ComponentUsageAttribute), true); uint priority = 0; Aspect aspect = Aspect.Has; Attributes.LoopType loop = Attributes.LoopType.Update; Type[] comps = null; Utils.BitMask systemMask = new Utils.BitMask(); // Search through attributes for (int i = 0; i < attr.Length; i++) { if (attr[i] is Attributes.ComponentUsageAttribute) { Attributes.ComponentUsageAttribute attribute = (Attributes.ComponentUsageAttribute)attr[i]; priority = (uint)attribute.priority; aspect = attribute.aspect; comps = attribute.types; loop = attribute.loopType; break; } } if (comps != null) { for (int i = 0; i < comps.Length; i++) { var componentType = comps[i]; var classInstance = Activator.CreateInstance(componentType, null); MethodInfo methodInfo = typeof(ComponentManager).GetMethod("RegisterComponent"); var m = methodInfo.MakeGenericMethod(componentType); var result = m.Invoke(this.caboodle.Entities.Components, null); int id = this.caboodle.Entities.Components.Get(componentType).GetId(); systemMask.Set(id, true); } } SystemInfo info = new SystemInfo(systemMask, system, system.Entities); system.SetAttr(caboodle, nextSystemId, priority, aspect, loop, stype); entityCache.Set(nextSystemId, new Utils.Table <Entity>()); all_systems.Add(info); nextSystemId += 1; }