예제 #1
0
        public void TestSimple()
        {
            var realStart = Environment.TickCount;
            const int tickCount = 1000;

            var realNow = DateTime.Now;
            _tickCount = tickCount;
            var fast = new FastDateTime(100);
            var fastNow = fast.Now;
            
            Assert.AreEqual(0, (realNow - fastNow).TotalMilliseconds, _toleranceMilliseconds);
            Assert.LessOrEqual(fast.LastUpdateMilliseconds, 100);
            Assert.GreaterOrEqual(fast.LastUpdateMilliseconds, 0);
            
            Thread.Sleep(80);

            realNow = DateTime.Now;
            _tickCount = tickCount + Environment.TickCount - realStart;
            fastNow = fast.Now;

            Assert.AreEqual(0, (realNow - fastNow).TotalMilliseconds, _toleranceMilliseconds);
            Assert.LessOrEqual(fast.LastUpdateMilliseconds, 100);
            Assert.GreaterOrEqual(fast.LastUpdateMilliseconds, 0);

            Thread.Sleep(25);

            realNow = DateTime.Now;
            _tickCount = tickCount + Environment.TickCount - realStart;
            fastNow = fast.Now;

            Assert.AreEqual(0, (realNow - fastNow).TotalMilliseconds, _toleranceMilliseconds);
            Assert.LessOrEqual(fast.LastUpdateMilliseconds, 100);
            Assert.GreaterOrEqual(fast.LastUpdateMilliseconds, 0);
        }
예제 #2
0
        public void TestRenderMultiHealthBarSystem()
        {
            Debug.WriteLine("Initialize EntityWorld: ");
            HealthBag.Clear();
            ComponentPool.Clear();

            HealthBag.Add(new TestHealthComponent());
            HealthBag.Add(new TestHealthComponent());
            ComponentPool.Add(typeof(TestHealthComponent), HealthBag);

            EntityWorld entityWorld = new EntityWorld();

            entityWorld.EntityManager.RemovedComponentEvent += RemovedComponent;
            entityWorld.EntityManager.RemovedEntityEvent    += RemovedEntity;
            entityWorld.SystemManager.SetSystem(new TestRenderHealthBarMultiSystem(), GameLoopType.Update);
            entityWorld.InitializeAll();
            Debug.WriteLine("OK");

            Debug.WriteLine("Fill EntityWorld with " + Load + " entities: ");
            List <Entity> entities = new List <Entity>();

            for (int index = Load - 1; index >= 0; --index)
            {
                Entity entity = TestEntityFactory.CreateTestHealthEntity(entityWorld);
                entities.Add(entity);
            }

            Debug.WriteLine("OK");

            const int Passes    = 9;
            Stopwatch stopwatch = Stopwatch.StartNew();

            for (int index = 0; index < Passes; ++index)
            {
                entityWorld.Update();
                entityWorld.Draw();
            }

            stopwatch.Stop();
            Debug.WriteLine("Update (" + Passes + " passes) duration: {0}", FastDateTime.ToString(stopwatch.Elapsed));

            int expectedPoints = 100 - (Passes * 10);

            if (expectedPoints < 0)
            {
                expectedPoints = 0;
            }

            int df = entities.Count(item => Math.Abs((int)(item.GetComponent <TestHealthComponent>().Points - expectedPoints)) < float.Epsilon);

            Assert.AreEqual(Load, df);

            Debug.WriteLine("Found {0} entities with health of {1}.", df, expectedPoints);
        }
예제 #3
0
        private HistoryItem[] ApplyFilters(HistoryItem[] historyItems)
        {
            IEnumerable <HistoryItem> result = historyItems.AsEnumerable();

            if (cbTypeFilter.Checked)
            {
                string type = cbTypeFilterSelection.Text;

                result = result.Where(x => x.Type == type);
            }

            if (cbHostFilter.Checked)
            {
                string host = txtHostFilter.Text;

                result = result.Where(x => x.Host.IndexOf(host, StringComparison.InvariantCultureIgnoreCase) >= 0);
            }

            string filenameFilter = txtFilenameFilter.Text;

            if (cbFilenameFilter.Checked && !string.IsNullOrEmpty(filenameFilter))
            {
                StringComparison rule = GetStringRule();

                if (cbFilenameFilterMethod.SelectedIndex == 0) // Contains
                {
                    result = result.Where(x => x.Filename.IndexOf(filenameFilter, rule) >= 0);
                }
                else if (cbFilenameFilterMethod.SelectedIndex == 1) // Starts with
                {
                    result = result.Where(x => x.Filename.StartsWith(filenameFilter, rule));
                }
                else if (cbFilenameFilterMethod.SelectedIndex == 2) // Exact match
                {
                    result = result.Where(x => x.Filename.Equals(filenameFilter, rule));
                }
            }

            if (cbDateFilter.Checked)
            {
                DateTime fromDate = dtpFilterFrom.Value.Date;
                DateTime toDate   = dtpFilterTo.Value.Date;

                result                       = from hi in result
                                    let date = FastDateTime.ToLocalTime(hi.DateTimeUtc).Date
                                               where date >= fromDate && date <= toDate
                                               select hi;
            }

            return(result.ToArray());
        }
예제 #4
0
        public void TestSystemCommunication()
        {
            Debug.WriteLine("Initialize EntityWorld: ");
            EntitySystem.BlackBoard.SetEntry("Damage", 5);
            EntityWorld entityWorld = new EntityWorld();

            entityWorld.SystemManager.SetSystem(new TestCommunicationSystem(), GameLoopType.Update);
            entityWorld.InitializeAll();
            Debug.WriteLine("OK");

            Debug.WriteLine("Fill EntityWorld with " + Load + " entities: ");
            List <Entity> entities = new List <Entity>();

            for (int index = Load; index >= 0; --index)
            {
                Entity entity = TestEntityFactory.CreateTestHealthEntity(entityWorld);
                entities.Add(entity);
            }

            Debug.WriteLine("OK");

            Stopwatch stopwatch = Stopwatch.StartNew();

            entityWorld.Update();
            entityWorld.Draw();
            stopwatch.Stop();
            Debug.WriteLine("Update 1 duration: {0}", FastDateTime.ToString(stopwatch.Elapsed));

            EntitySystem.BlackBoard.SetEntry("Damage", 10);

            stopwatch.Restart();
            entityWorld.Update();
            entityWorld.Draw();
            stopwatch.Stop();
            Debug.WriteLine("Update 2 duration: {0}", FastDateTime.ToString(stopwatch.Elapsed));

            Debug.WriteLine("Test entities: ");
            const float Expected = 85.0f;

            foreach (Entity item in entities)
            {
                Assert.AreEqual(Expected, item.GetComponent <TestHealthComponent>().Points);
            }

            Debug.WriteLine("OK");
            EntitySystem.BlackBoard.RemoveEntry("Damage");
        }
예제 #5
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");
        }
예제 #6
0
        public void TestSimpleSystem2()
        {
            Debug.WriteLine("Initialize EntityWorld: ");
            EntityWorld entityWorld = new EntityWorld();
            TestEntityProcessingSystem testEntityProcessingSystem = entityWorld.SystemManager.SetSystem(new TestEntityProcessingSystem(), GameLoopType.Update);

            entityWorld.InitializeAll();
            Debug.WriteLine("OK");

            const float Expected = 0;

            Assert.AreEqual(Expected, testEntityProcessingSystem.Counter);

            Stopwatch stopwatch = Stopwatch.StartNew();

            entityWorld.Update();
            entityWorld.Draw();
            stopwatch.Stop();
#if DEBUG
            Debug.WriteLine("Processed update and draw with duration {0} for {1} elements", FastDateTime.ToString(stopwatch.Elapsed), entityWorld.EntityManager.EntitiesRequestedCount);
#else
            Debug.WriteLine("Processed update and draw with duration {0} for {1} elements", FastDateTime.ToString(stopwatch.Elapsed), entityWorld.EntityManager.ActiveEntities.Count);
#endif
            const float Expected1 = 1;
            Assert.AreEqual(Expected1, testEntityProcessingSystem.Counter);
            Debug.WriteLine("OK");
        }
예제 #7
0
        public void TestSimpleSystem()
        {
            Debug.WriteLine("Initialize EntityWorld: ");
            EntityWorld entityWorld = new EntityWorld();

            entityWorld.SystemManager.SetSystem(new TestNormalEntityProcessingSystem1(), GameLoopType.Update);
            entityWorld.InitializeAll();
            Debug.WriteLine("OK");

            Entity entity1 = TestEntityFactory.CreateTestHealthEntity(entityWorld);

            Assert.IsNotNull(entity1);

            Entity entity2 = TestEntityFactory.CreateTestPowerEntity(entityWorld);

            Assert.IsNotNull(entity2);

            Stopwatch stopwatch = Stopwatch.StartNew();

            entityWorld.Update();
            entityWorld.Draw();
            stopwatch.Stop();
#if DEBUG
            Debug.WriteLine("Processed update and draw with duration {0} for {1} elements", FastDateTime.ToString(stopwatch.Elapsed), entityWorld.EntityManager.EntitiesRequestedCount);
#else
            Debug.WriteLine("Processed update and draw with duration {0} for {1} elements", FastDateTime.ToString(stopwatch.Elapsed), entityWorld.EntityManager.ActiveEntities.Count);
#endif
            const float Expected1 = 90.0f;
            Assert.AreEqual(Expected1, entity1.GetComponent <TestHealthComponent>().Points);

            const float Expected2 = 100.0f;
            Assert.AreEqual(Expected2, entity2.GetComponent <TestHealthComponent>().Points);
            Assert.AreEqual(Expected2, entity2.GetComponent <TestPowerComponent>().Power);
        }
예제 #8
0
        public void TestHybridQueueSystem()
        {
            Debug.WriteLine("Initialize EntityWorld: ");
            EntityWorld           entityWorld           = new EntityWorld();
            TestQueueHybridSystem testQueueHybridSystem = entityWorld.SystemManager.SetSystem(new TestQueueHybridSystem(), GameLoopType.Update);

            entityWorld.InitializeAll();
            Debug.WriteLine("OK");

            const int Chunk = 500;

            Debug.WriteLine("Fill EntityWorld with first  chunk of " + Chunk + " entities: ");
            List <Entity> entities = new List <Entity>();

            for (int index = Chunk; index > 0; --index)
            {
                entities.Add(TestEntityFactory.CreateTestHealthEntity(entityWorld));
            }

            Debug.WriteLine("OK");
            Debug.WriteLine("Fill EntityWorld with second chunk of " + Chunk + " entities: ");

            for (int index = Chunk; index > 0; --index)
            {
                Entity entity = TestEntityFactory.CreateTestHealthEntity(entityWorld);

                testQueueHybridSystem.AddToQueue(entity);
                entities.Add(entity);
            }

            Debug.WriteLine("OK");

            Stopwatch stopwatch      = Stopwatch.StartNew();
            int       numberOfQueues = 0;

            while (testQueueHybridSystem.QueueCount > 0)
            {
                ++numberOfQueues;
                entityWorld.Update();
                entityWorld.Draw();
            }

            stopwatch.Stop();
            Debug.WriteLine("Processed {0} hybrid queues with duration {1}", numberOfQueues, FastDateTime.ToString(stopwatch.Elapsed));

            Debug.WriteLine("Test first  chunk: ");
            float expectedPointsFirstChunk = 100.0f - (10 * numberOfQueues);

            if (expectedPointsFirstChunk < 0.0f)
            {
                Debug.WriteLine("Results may be inaccurate. Please lower chunk size. ");
                expectedPointsFirstChunk = 0.0f;
            }

            for (int index = Chunk - 1; index >= 0; --index)
            {
                Assert.AreEqual(expectedPointsFirstChunk, entities[index].GetComponent <TestHealthComponent>().Points, "Index:<" + index + ">.");
            }

            Debug.WriteLine("OK");

            Debug.WriteLine("Test second chunk: ");
            float expectedPointsSecondChunk = 90.0f - (10 * numberOfQueues);

            if (expectedPointsSecondChunk < 0.0f)
            {
                Debug.WriteLine("Results may be inaccurate. Please lower chunk size. ");
                expectedPointsSecondChunk = 0.0f;
            }

            for (int index = (Chunk * 2) - 1; index >= Chunk; --index)
            {
                Assert.AreEqual(expectedPointsSecondChunk, entities[index].GetComponent <TestHealthComponent>().Points, "Index:<" + index + ">.");
            }

            Debug.WriteLine("OK");
        }
예제 #9
0
        public void TestPerformance()
        {
            Debug.WriteLine("Number of elements: ");

            // Identify max mem size.
            Bag <int> bigBag = new Bag <int>();

#if METRO
            int maxMem = 50;
#else
            int maxMem = 5000;
#endif


            // pointless to use int.maxvalue (sometimes it works, some it does not ... depends on other process)
            for (int index = 0; index < maxMem; ++index)
            {
                try
                {
                    bigBag.Add(index);
                }
                catch (Exception)
                {
                    // some extra to be sure (there are some memory allocs we cant control in other threads)
                    maxMem = index;
                    break;
                }
            }

            bigBag = null;
#if !MONO
            // This is need to secure that enough memory is left.
            GC.Collect();
            GC.WaitForPendingFinalizers();
#if !METRO
            GC.WaitForFullGCComplete();
#endif
            GC.Collect();
#endif

            Debug.WriteLine(maxMem.ToString(CultureInfo.InvariantCulture));

            // Reset bag.
            bigBag = new Bag <int>(0);

            // Start measurement.
            Stopwatch stopwatch = Stopwatch.StartNew();

            // Fill
            for (int index = maxMem; index >= 0; --index)
            {
                bigBag.Add(index);
            }

            stopwatch.Stop();
            Debug.WriteLine("Load  duration: {0}", FastDateTime.ToString(stopwatch.Elapsed));

            stopwatch.Restart();
            bigBag.Clear();
            stopwatch.Stop();
            Debug.WriteLine("Clear duration: {0}", FastDateTime.ToString(stopwatch.Elapsed));
        }
예제 #10
0
        public void TestTicksOverflow()
        {
            var realStart = Environment.TickCount;
            const int tickCount = int.MaxValue - 5;

            var realNow = DateTime.Now;
            var fast = new FastDateTime(100);
            _tickCount = tickCount;
            var fastNow = fast.Now;

            Assert.AreEqual(0, (realNow - fastNow).TotalMilliseconds, _toleranceMilliseconds);
            Assert.LessOrEqual(fast.LastUpdateMilliseconds, 100);
            Assert.GreaterOrEqual(fast.LastUpdateMilliseconds, 0);

            Thread.Sleep(80);

            realNow = DateTime.Now;
            unchecked
            {
                _tickCount = tickCount + Environment.TickCount - realStart;
            }
            fastNow = fast.Now;

            Assert.Less(_tickCount, 0);
            Assert.AreEqual(0, (realNow - fastNow).TotalMilliseconds, _toleranceMilliseconds);
            Assert.LessOrEqual(fast.LastUpdateMilliseconds, 100);
            Assert.GreaterOrEqual(fast.LastUpdateMilliseconds, 0);

            Thread.Sleep(25);

            realNow = DateTime.Now;
            unchecked
            {
                _tickCount = tickCount + Environment.TickCount - realStart;
            }
            fastNow = fast.Now;

            Assert.Less(_tickCount, 0);
            Assert.AreEqual(0, (realNow - fastNow).TotalMilliseconds, _toleranceMilliseconds);
            Assert.LessOrEqual(fast.LastUpdateMilliseconds, 100);
            Assert.GreaterOrEqual(fast.LastUpdateMilliseconds, 0);

            Thread.Sleep(25);

            realNow = DateTime.Now;
            unchecked
            {
                _tickCount = tickCount + Environment.TickCount - realStart;
            }
            fastNow = fast.Now;

            Assert.Less(_tickCount, 0);
            Assert.AreEqual(0, (realNow - fastNow).TotalMilliseconds, _toleranceMilliseconds);
            Assert.LessOrEqual(fast.LastUpdateMilliseconds, 100);
            Assert.GreaterOrEqual(fast.LastUpdateMilliseconds, 0);
        }