Ejemplo n.º 1
0
        private static void SetupClients(World world, List <Client> clients, Stopwatch t)
        {
            for (int x = (int)(world.Area.Min.X + (world.TileDimensions.X / 2)); x < world.Area.Max.X; x += (int)world.TileDimensions.X)
            {
                for (int y = (int)(world.Area.Min.Y + (world.TileDimensions.Y / 2)); y < world.Area.Max.Y; y += (int)world.TileDimensions.Y)
                {
                    string name   = string.Format("MyUsername{0}/{1}", x, y);
                    var    client = new Client(name, new Vector(x / 100f, y / 100f));
                    client.BeginConnect();
                    clients.Add(client);
                    clientCount++;
                }

                for (int y = (int)(world.Area.Min.Y + (world.TileDimensions.Y / 2)) + 1; y < world.Area.Max.Y; y += (int)world.TileDimensions.Y)
                {
                    string name   = string.Format("MyUsername{0}/{1}", x + 1, y);
                    var    client = new Client(name, new Vector((x + 1) / 100f, y / 100f));
                    client.BeginConnect();
                    clients.Add(client);
                    clientCount++;
                }
            }

            clients.ForEach(c => Assert.IsTrue(c.EndConnect()));
            log.InfoFormat("connect completed, {0} clients", clientCount);

            clients.ForEach(c => EnterWorldBegin(c, world));
            clients.ForEach(EnterWorldEnd);
            clients.ForEach(c => BeginReceiveEvent(c, EventCode.ItemSubscribed, d => (string)d[(byte)ParameterCode.ItemId] != c.Username, 500));
            clients.ForEach(c => EndReceiveEvent(c, EventCode.ItemSubscribed));
            PrintStats(t);
            Client.ResetStats();
            Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at start");
            log.Info("enter completed");
        }
Ejemplo n.º 2
0
        public void Run()
        {
            WorldCache.Instance.Clear();
            World world;

            WorldCache.Instance.TryCreate(
                "HeavyLoad2", new BoundingBox(new Vector(0f, 0f), new Vector(100f, 100f)), new Vector(20f, 20f), out world);

            using (var client = new Client(string.Empty))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld(world, client);
            }

            Stopwatch t = Stopwatch.StartNew();

            var clients = new List <Client>();

            try
            {
                SetupClients(world, clients, t);

                Client.ResetStats();
                log.Info("ItemPositionUpdate wait completed");
                Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at exit");

                t = Stopwatch.StartNew();
                MoveClients(clients);
                PrintStats(t);
                MoveClients(clients);
                PrintStats(t);
                MoveClients(clients);
                PrintStats(t);
                MoveClients(clients);
                PrintStats(t);
                MoveClients(clients);
                PrintStats(t);
                Client.ResetStats();
                log.Info("move completed");
                Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at exit");

                DisconnectClients(clients);
            }
            finally
            {
                clients.ForEach(c => c.Dispose());
            }
        }
Ejemplo n.º 3
0
        private static void DisconnectClients(List <Client> clients)
        {
            Stopwatch t = Stopwatch.StartNew();

            clients.ForEach(ExitWorldBegin);
            clients.ForEach(ExitWorldEnd);
            log.Info("exit completed");
            PrintStats(t);
            Client.ResetStats();
            Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at exit");

            t = Stopwatch.StartNew();
            clients.ForEach(c => c.BeginDisconnect());
            clients.ForEach(c => c.EndDisconnect());
            log.Info("disconnect completed");
            PrintStats(t);
            Client.ResetStats();
            Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at exit");
        }
Ejemplo n.º 4
0
        public void RunForTime()
        {
            MmoWorldCache.Instance.Clear();
            MmoWorld world;

            MmoWorldCache.Instance.TryCreate(
                "HeavyLoad3", (new[] { 0f, 0f }).ToVector(), (new[] { 299f, 299f }).ToVector(), (new[] { 10f, 10f }).ToVector(), out world);

            using (var client = new Client(string.Empty))
            {
                Assert.IsTrue(client.Connect());
                CreateWorld(world, client);
            }

            Stopwatch t = Stopwatch.StartNew();

            var clients = new List <Client>();

            try
            {
                SetupClients(world, clients, t);

                Client.ResetStats();
                t = Stopwatch.StartNew();
                while (t.ElapsedMilliseconds < 10000)
                {
                    MoveClients(clients);
                    PrintStats(t);
                    Client.ResetStats();
                }

                log.Info("move completed");
                Assert.AreEqual(0, Client.Exceptions, "Exceptions occured at exit");

                DisconnectClients(clients);
            }
            finally
            {
                clients.ForEach(c => c.Dispose());
            }
        }