예제 #1
0
 internal void SetAttr(Caboodle c, int id, uint priority, Aspect aspect,
                       Attributes.LoopType loopType, global::System.Type systemType)
 {
     this._caboodle  = c;
     this._systemId  = id;
     this._priority  = priority;
     this._aspect    = aspect;
     this._loopType  = loopType;
     this.systemType = systemType;
 }
예제 #2
0
        /// <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;
        }