コード例 #1
0
        public void FTestQueueSystems()
        {
            Debug.WriteLine("Initialize EntityWorld: ");
            EntityWorld entityWorld = new EntityWorld();

#if !PORTABLE
            TestQueueSystemCopy2 testQueueSystem1 = entityWorld.SystemManager.SetSystem(new TestQueueSystemCopy2(10), GameLoopType.Update, 0, ExecutionType.Asynchronous);
#else
            TestQueueSystemCopy2 testQueueSystem1 = entityWorld.SystemManager.SetSystem(new TestQueueSystemCopy2(10), GameLoopType.Update);
#endif
            entityWorld.InitializeAll();
            Debug.WriteLine("OK");

            QueueSystemProcessingThreadSafe <DummyPlaceHolder> .SetQueueProcessingLimit(20, testQueueSystem1.Id);

            Debug.WriteLine("Fill EntityWorld with first  chunk of " + Load + " entities: ");
            List <DummyPlaceHolder> entities1 = new List <DummyPlaceHolder>();
            for (int index = Load; index >= 0; --index)
            {
                DummyPlaceHolder dph = new DummyPlaceHolder {
                    Component = new TestHealthComponent(100)
                };
                QueueSystemProcessingThreadSafe <DummyPlaceHolder> .AddToQueue(dph, testQueueSystem1.Id);

                entities1.Add(dph);
            }

            Debug.WriteLine("OK");
            Debug.WriteLine("Begin down tearing of queues...");
            Stopwatch stopwatch = Stopwatch.StartNew();
            int       loopCount = 0;
            while (QueueSystemProcessingThreadSafe <DummyPlaceHolder> .QueueCount(testQueueSystem1.Id) > 0 || QueueSystemProcessingThreadSafe <DummyPlaceHolder> .QueueCount(testQueueSystem1.Id) > 0)
            {
                entityWorld.Update();
                entityWorld.Draw();
                ++loopCount;
#if DEBUG
                Debug.WriteLine("Queue size thread A: {0} ", QueueSystemProcessingThreadSafe <DummyPlaceHolder> .QueueCount(testQueueSystem1.Id));
#endif
            }

            stopwatch.Stop();
            Debug.WriteLine("End OK. Loops: {0} Time: {1}", loopCount, FastDateTime.ToString(stopwatch.Elapsed));

            Debug.WriteLine("Test entities 1: ");
            const float Expected1 = 90.0f;
            foreach (DummyPlaceHolder entity in entities1)
            {
                TestHealthComponent testHealthComponent = entity.Component as TestHealthComponent;
                if (testHealthComponent != null)
                {
                    Assert.AreEqual(Expected1, testHealthComponent.Points);
                }
            }

            Debug.WriteLine("OK");
        }
コード例 #2
0
        public void TestQueueSystems()
        {
            Debug.WriteLine("Initialize EntityWorld: ");
            EntityWorld entityWorld = new EntityWorld();

#if !PORTABLE
            TestQueueSystem     testQueueSystem1 = entityWorld.SystemManager.SetSystem(new TestQueueSystem(10), GameLoopType.Update, 0, ExecutionType.Asynchronous);
            TestQueueSystem     testQueueSystem2 = entityWorld.SystemManager.SetSystem(new TestQueueSystem(10), GameLoopType.Update, 0, ExecutionType.Asynchronous);
            TestQueueSystemCopy testQueueSystem3 = entityWorld.SystemManager.SetSystem(new TestQueueSystemCopy(20), GameLoopType.Update, 0, ExecutionType.Asynchronous);
#else
            TestQueueSystem     testQueueSystem1 = entityWorld.SystemManager.SetSystem(new TestQueueSystem(10), GameLoopType.Update);
            TestQueueSystem     testQueueSystem2 = entityWorld.SystemManager.SetSystem(new TestQueueSystem(10), GameLoopType.Update);
            TestQueueSystemCopy testQueueSystem3 = entityWorld.SystemManager.SetSystem(new TestQueueSystemCopy(20), GameLoopType.Update);
#endif
            entityWorld.InitializeAll();
            Debug.WriteLine("OK");

            QueueSystemProcessingThreadSafe.SetQueueProcessingLimit(20, testQueueSystem2.Id);

            int expectedLimit = QueueSystemProcessingThreadSafe.GetQueueProcessingLimit(testQueueSystem2.Id);
            Assert.AreEqual(expectedLimit, QueueSystemProcessingThreadSafe.GetQueueProcessingLimit(testQueueSystem1.Id));
            Assert.AreNotEqual(expectedLimit, QueueSystemProcessingThreadSafe.GetQueueProcessingLimit(testQueueSystem3.Id));

            QueueSystemProcessingThreadSafe.SetQueueProcessingLimit(1024, testQueueSystem1.Id);
            QueueSystemProcessingThreadSafe.SetQueueProcessingLimit(4096, testQueueSystem3.Id);

            Debug.WriteLine("Fill EntityWorld with first  chunk of " + Load + " entities: ");
            List <Entity> entities1 = new List <Entity>();
            for (int index = Load; index >= 0; --index)
            {
                Entity entity = TestEntityFactory.CreateTestHealthEntity(entityWorld);

                QueueSystemProcessingThreadSafe.AddToQueue(entity, testQueueSystem1.Id);
                entities1.Add(entity);
            }

            Debug.WriteLine("OK");
            Debug.WriteLine("Fill EntityWorld with second chunk of " + Load + " entities: ");
            List <Entity> entities2 = new List <Entity>();
            for (int index = Load; index >= 0; --index)
            {
                Entity entity = TestEntityFactory.CreateTestHealthEntity(entityWorld);

                QueueSystemProcessingThreadSafe.AddToQueue(entity, testQueueSystem3.Id);
                entities2.Add(entity);
            }

            Debug.WriteLine("OK");
            Debug.WriteLine("Begin down tearing of queues...");
            Stopwatch stopwatch = Stopwatch.StartNew();
            int       loopCount = 0;
            while (QueueSystemProcessingThreadSafe.QueueCount(testQueueSystem1.Id) > 0 || QueueSystemProcessingThreadSafe.QueueCount(testQueueSystem3.Id) > 0)
            {
                entityWorld.Update();
                entityWorld.Draw();
                ++loopCount;
#if DEBUG
                Debug.WriteLine("Queue size thread A: {0} B: {1}", QueueSystemProcessingThreadSafe.QueueCount(testQueueSystem1.Id), QueueSystemProcessingThreadSafe.QueueCount(testQueueSystem3.Id));
#endif
            }

            stopwatch.Stop();
            Debug.WriteLine("End OK. Loops: {0} Time: {1}", loopCount, FastDateTime.ToString(stopwatch.Elapsed));

            Debug.WriteLine("Test entities 1: ");
            const float Expected1 = 90.0f;
            foreach (Entity entity in entities1)
            {
                Assert.AreEqual(Expected1, entity.GetComponent <TestHealthComponent>().Points);
            }

            Debug.WriteLine("OK");
            Debug.WriteLine("Test entities 2: ");
            const float Expected2 = 80.0f;
            foreach (Entity entity in entities2)
            {
                Assert.AreEqual(Expected2, entity.GetComponent <TestHealthComponent>().Points);
            }

            Debug.WriteLine("OK");
        }