Beispiel #1
0
        /// <summary>Initializes a new instance of the <see cref="SystemManager" /> class.</summary>
        /// <param name="entityWorld">The entity world.</param>
        internal SystemManager(EntityWorld entityWorld)
        {
            this.mergedBag = new Bag <EntitySystem>();
#if FULLDOTNET
            this.drawLayers   = new SortedDictionary <int, SystemLayer>();
            this.updateLayers = new SortedDictionary <int, SystemLayer>();
#else
            this.drawLayers   = new Dictionary <int, SystemLayer>();
            this.updateLayers = new Dictionary <int, SystemLayer>();
#endif
            this.systemBitManager = new SystemBitManager();
            this.systems          = new Dictionary <Type, IList>();
            this.entityWorld      = entityWorld;
        }
Beispiel #2
0
        /// <summary>Sets the system.</summary>
        /// <param name="systemType">Type of the system.</param>
        /// <param name="system">The system.</param>
        /// <param name="gameLoopType">Type of the game loop.</param>
        /// <param name="layer">The layer.</param>
        /// <param name="executionType">Type of the execution.</param>
        /// <returns>The EntitySystem.</returns>
        private EntitySystem SetSystem(Type systemType, EntitySystem system, GameLoopType gameLoopType, int layer = 0, ExecutionType executionType = ExecutionType.Synchronous)
        {
            system.EntityWorld = this.entityWorld;

            if (this.systems.ContainsKey(systemType))
            {
                this.systems[systemType].Add(system);
            }
            else
            {
                Type genericType = typeof(List <>);
                Type listType    = genericType.MakeGenericType(systemType);
                this.systems[systemType] = (IList)Activator.CreateInstance(listType);
                this.systems[systemType].Add(system);
            }

            switch (gameLoopType)
            {
            case GameLoopType.Draw:
            {
                SetSystem(ref this.drawLayers, system, layer, executionType);
            }

            break;

            case GameLoopType.Update:
            {
                SetSystem(ref this.updateLayers, system, layer, executionType);
            }

            break;
            }

            if (!this.mergedBag.Contains(system))
            {
                this.mergedBag.Add(system);
            }

            system.SystemBit = SystemBitManager.GetBitFor(system);

            return(system);
        }