示例#1
0
        public static void QueueSystemTeste()
        {
            EntityWorld world = new EntityWorld();
            SystemManager systemManager = world.SystemManager;
            QueueSystemTest QueueSystemTest = new ArtemisTest.QueueSystemTest();
            QueueSystemTest QueueSystemTest2 = new ArtemisTest.QueueSystemTest();
            systemManager.SetSystem(QueueSystemTest, ExecutionType.Update);
            systemManager.SetSystem(QueueSystemTest2, ExecutionType.Update);

            systemManager.InitializeAll();

            QueueSystemTest.SetQueueProcessingLimit(20, QueueSystemTest.Id);
            Debug.Assert(QueueSystemTest.GetQueueProcessingLimit(QueueSystemTest.Id) == QueueSystemTest.GetQueueProcessingLimit(QueueSystemTest2.Id));

            QueueSystemTest2 QueueSystemTestteste = new ArtemisTest.QueueSystemTest2();
            Debug.Assert(QueueSystemTest.GetQueueProcessingLimit(QueueSystemTestteste.Id) != QueueSystemTest.GetQueueProcessingLimit(QueueSystemTest2.Id));

            QueueSystemTest.SetQueueProcessingLimit(1000, QueueSystemTest.Id);

            List<Entity> l = new List<Entity>();
            for (int i = 0; i < 1000000; i++)
            {
                Entity et = world.CreateEntity();
                et.AddComponent(new Health());
                et.GetComponent<Health>().HP = 100;
                QueueSystemTest.AddToQueue(et, QueueSystemTest.Id);
                l.Add(et);
            }

            Console.WriteLine("Start");
            while (QueueSystemTest.QueueCount(QueueSystemTest.Id) > 0 && QueueSystemTest.QueueCount(QueueSystemTest2.Id) > 0)
            {
                DateTime dt = DateTime.Now;
                world.LoopStart();
                systemManager.UpdateAsynchronous(ExecutionType.Update);
                Console.WriteLine("Count: " + QueueSystemTest.QueueCount(QueueSystemTest.Id));
                Console.WriteLine("Time: " + (DateTime.Now - dt).TotalMilliseconds);

            }
            Console.WriteLine("End");

            foreach (var item in l)
            {
                Debug.Assert(item.GetComponent<Health>().HP == 90);
            }
        }
示例#2
0
        public static void QueueSystemTeste()
        {
            EntityWorld     world            = new EntityWorld();
            SystemManager   systemManager    = world.SystemManager;
            QueueSystemTest QueueSystemTest  = new ArtemisTest.QueueSystemTest();
            QueueSystemTest QueueSystemTest2 = new ArtemisTest.QueueSystemTest();

            systemManager.SetSystem(QueueSystemTest, ExecutionType.Update);
            systemManager.SetSystem(QueueSystemTest2, ExecutionType.Update);

            QueueSystemTest2 QueueSystemTestteste = new ArtemisTest.QueueSystemTest2();

            systemManager.SetSystem(QueueSystemTestteste, ExecutionType.Update);

            systemManager.InitializeAll();

            QueueSystemTest.SetQueueProcessingLimit(20, QueueSystemTest.Id);
            Debug.Assert(QueueSystemTest.GetQueueProcessingLimit(QueueSystemTest.Id) == QueueSystemTest.GetQueueProcessingLimit(QueueSystemTest2.Id));



            Debug.Assert(QueueSystemTest.GetQueueProcessingLimit(QueueSystemTestteste.Id) != QueueSystemTest.GetQueueProcessingLimit(QueueSystemTest2.Id));

            QueueSystemTest.SetQueueProcessingLimit(1000, QueueSystemTest.Id);
            QueueSystemTest.SetQueueProcessingLimit(2000, QueueSystemTestteste.Id);

            List <Entity> l = new List <Entity>();

            for (int i = 0; i < 1000000; i++)
            {
                Entity et = world.CreateEntity();
                et.AddComponent(new Health());
                et.GetComponent <Health>().HP = 100;
                QueueSystemTest.AddToQueue(et, QueueSystemTest.Id);
                l.Add(et);
            }

            List <Entity> l2 = new List <Entity>();

            for (int i = 0; i < 1000000; i++)
            {
                Entity et = world.CreateEntity();
                et.AddComponent(new Health());
                et.GetComponent <Health>().HP = 100;
                QueueSystemTest.AddToQueue(et, QueueSystemTestteste.Id);
                l2.Add(et);
            }

            Console.WriteLine("Start");
            while (QueueSystemTest.QueueCount(QueueSystemTest.Id) > 0 || QueueSystemTest.QueueCount(QueueSystemTestteste.Id) > 0)
            {
                DateTime dt = DateTime.Now;
                world.LoopStart();
                systemManager.UpdateAsynchronous(ExecutionType.Update);
                Console.WriteLine("Count: " + QueueSystemTest.QueueCount(QueueSystemTest.Id));
                Console.WriteLine("Time: " + (DateTime.Now - dt).TotalMilliseconds);
            }
            Console.WriteLine("End");

            foreach (var item in l)
            {
                Debug.Assert(item.GetComponent <Health>().HP == 90);
            }
            foreach (var item in l2)
            {
                Debug.Assert(item.GetComponent <Health>().HP == 80);
            }
        }