示例#1
0
        public void Mask()
        {
            var masker = new LayerMasker();

            var mask = masker.Mask(0, 2, 5);

            Assert.Equal((uint)37, mask);

            mask = masker.Mask(31);
            Assert.Equal(2147483648, mask);

            mask = masker.Mask(Enumerable.Range(0, 32));
            Assert.Equal(uint.MaxValue, masker.AllLayers);
            Assert.Equal(masker.AllLayers, mask);

            mask = masker.NoLayers;
            Assert.Equal((uint)0, mask);

            masker = new LayerMasker(3);
            mask   = masker.Mask(0, 2, 5);
            Assert.Equal((uint)5, mask); // 5 should be excluded since only 3 layers

            mask = masker.Mask(Enumerable.Range(0, 32));
            Assert.Equal((uint)7, masker.AllLayers);
            Assert.Equal(masker.AllLayers, mask); // All layers that don't exist are ignored
        }
示例#2
0
        public static TimeSpan TimeForGetLayers(int iterations, IEnumerable <int> layersToCheck = null)
        {
            var layerMasking = new LayerMasker(POSSIBLE_LAYERS.Length);

            var stopwatch = new Stopwatch();

            int[] layers = layersToCheck == null ? new int[] { 0, 2, 5 } : layersToCheck.ToArray();

            uint mask = layerMasking.Mask(layers);

            // For caching
            int myLayer;

            foreach (var i in layerMasking.Layers(mask))
            {
                myLayer = i;
            }

            stopwatch.Start();
            for (int it = 0; it < iterations; it++)
            {
                foreach (var i in layerMasking.Layers(mask))
                {
                    myLayer = i;
                }
            }
            stopwatch.Stop();

            return(stopwatch.Elapsed);
        }
示例#3
0
文件: Program.cs 项目: TimyJ/ReaperRL
        static void Main(string[] args)
        {
            WindowUtilities.OpenWindow();
            LayerMasker   mask          = new LayerMasker(3);
            Level         testLevel     = new Level(96, 96, 2, mask.Mask((int)LayerNames.ITEMS));
            LevelRenderer levelRenderer = new LevelRenderer(testLevel);
            Entity        player        = new Entity();
            DisplayInfo   d             = new DisplayInfo(player, '@', Color.White);

            player.AddComponent(d);
            ToolQualities t = new ToolQualities();

            player.AddComponent(t);
            testLevel.EnterLevel(player);
            Entity tree = new Entity();

            tree.AddComponent(new DisplayInfo(tree, '|', Color.ForestGreen));
            tree.AddComponent(new Tree(tree));
            testLevel.Add(tree, (4, 4));
            Globals.AddPanel(levelRenderer);
            MessageLog.AddMessage("Press ? for help");

            while (true)
            {
                Terminal.Clear();
                Globals.DrawAndInput();
                Terminal.Refresh();
            }
        }
示例#4
0
        public void GetLayers()
        {
            var masker = new LayerMasker();

            int[] layers = { 0, 2, 5 };

            var mask        = masker.Mask(layers);
            var layerReturn = masker.Layers(mask).ToEnumerable().ToArray();

            layers = layers.OrderByDescending(i => i).ToArray();

            _output.WriteLine("Actual layers");
            _output.WriteLine(layers.ExtendToString());
            _output.WriteLine("Returned layers:");
            _output.WriteLine(layerReturn.ExtendToString());

            Assert.Equal(layers.Length, layerReturn.Length);
            for (var i = 0; i < layers.Length; i++)
            {
                Assert.Equal(layers[i], layerReturn[i]);
            }

            masker      = new LayerMasker(3);
            layerReturn = masker.Layers(mask).ToEnumerable().ToArray();
            layers      = layers.OrderByDescending(i => i).Where(i => i < 3).ToArray();
            Assert.Equal(layers.Length, layerReturn.Length);
            for (var i = 0; i < layers.Length; i++)
            {
                Assert.Equal(layers[i], layerReturn[i]);
            }
        }
示例#5
0
        public void Layers()
        {
            var masker = new LayerMasker();

            int[] layers = new int[] { 0, 2, 5 };

            var mask        = masker.Mask(layers);
            var layerReturn = masker.Layers(mask).ToArray();

            layers = layers.OrderByDescending(i => i).ToArray();

            Console.WriteLine("Actual layers");
            Console.WriteLine(layers.ExtendToString());
            Console.WriteLine("Returned layers:");
            Console.WriteLine(layerReturn.ExtendToString());

            Assert.AreEqual(layers.Length, layerReturn.Length);
            for (int i = 0; i < layers.Length; i++)
            {
                Assert.AreEqual(layers[i], layerReturn[i]);
            }

            masker      = new LayerMasker(3);
            layerReturn = masker.Layers(mask).ToArray();
            layers      = layers.OrderByDescending(i => i).Where(i => i < 3).ToArray();
            Assert.AreEqual(layers.Length, layerReturn.Length);
            for (int i = 0; i < layers.Length; i++)
            {
                Assert.AreEqual(layers[i], layerReturn[i]);
            }
        }
示例#6
0
        public void AddLayer()
        {
            var masker = new LayerMasker();

            var mask = masker.Mask(0); // First layer;

            mask = masker.AddLayers(mask, 3);
            Assert.Equal(masker.Mask(0, 3), mask);

            mask = masker.AddLayers(mask, 31);
            Assert.Equal(masker.Mask(0, 3, 31), mask);

            masker = new LayerMasker(2);
            mask   = masker.Mask(1);

            mask = masker.AddLayers(mask, 0);
            Assert.Equal(masker.Mask(1, 0), mask);

            mask = masker.AddLayers(mask, 3);      // Out of range
            Assert.Equal(masker.Mask(0, 1), mask); // Should be same since we added a layer out of range

            mask = masker.AddLayers(mask, 31);     // Out of range
            Assert.Equal(masker.Mask(0, 1), mask); // Should be same since we added a layer out of range
        }