Exemplo n.º 1
0
        public void LoadMap01()
        {
            using (var resource = CommonResource.CreateDummy(WadPath.Doom2))
            {
                var options = new GameOptions();
                var players = DoomTest.GetDefaultPlayers();
                var world   = new World(resource, options, players);
                var map     = new Map(resource, world);

                var mapMinX = map.Lines.Min(line => Fixed.Min(line.Vertex1.X, line.Vertex2.X).ToDouble());
                var mapMaxX = map.Lines.Max(line => Fixed.Max(line.Vertex1.X, line.Vertex2.X).ToDouble());
                var mapMinY = map.Lines.Min(line => Fixed.Min(line.Vertex1.Y, line.Vertex2.Y).ToDouble());
                var mapMaxY = map.Lines.Max(line => Fixed.Max(line.Vertex1.Y, line.Vertex2.Y).ToDouble());

                for (var i = 0; i < map.Sectors.Length; i++)
                {
                    var sector = map.Sectors[i];
                    var sLines = map.Lines.Where(line => line.FrontSector == sector || line.BackSector == sector).ToArray();

                    CollectionAssert.AreEqual(sLines, sector.Lines);

                    var minX = sLines.Min(line => Fixed.Min(line.Vertex1.X, line.Vertex2.X).ToDouble()) - maxRadius;
                    minX = Math.Max(minX, mapMinX);
                    var maxX = sLines.Max(line => Fixed.Max(line.Vertex1.X, line.Vertex2.X).ToDouble()) + maxRadius;
                    maxX = Math.Min(maxX, mapMaxX);
                    var minY = sLines.Min(line => Fixed.Min(line.Vertex1.Y, line.Vertex2.Y).ToDouble()) - maxRadius;
                    minY = Math.Max(minY, mapMinY);
                    var maxY = sLines.Max(line => Fixed.Max(line.Vertex1.Y, line.Vertex2.Y).ToDouble()) + maxRadius;
                    maxY = Math.Min(maxY, mapMaxY);

                    var bboxTop    = (map.BlockMap.OriginY + BlockMap.MapBlockSize * (sector.BlockBox[Box.Top] + 1)).ToDouble();
                    var bboxBottom = (map.BlockMap.OriginY + BlockMap.MapBlockSize * sector.BlockBox[Box.Bottom]).ToDouble();
                    var bboxLeft   = (map.BlockMap.OriginX + BlockMap.MapBlockSize * sector.BlockBox[Box.Left]).ToDouble();
                    var bboxRight  = (map.BlockMap.OriginX + BlockMap.MapBlockSize * (sector.BlockBox[Box.Right] + 1)).ToDouble();

                    Assert.IsTrue(bboxLeft <= minX);
                    Assert.IsTrue(bboxRight >= maxX);
                    Assert.IsTrue(bboxTop >= maxY);
                    Assert.IsTrue(bboxBottom <= minY);

                    Assert.IsTrue(Math.Abs(bboxLeft - minX) <= 128);
                    Assert.IsTrue(Math.Abs(bboxRight - maxX) <= 128);
                    Assert.IsTrue(Math.Abs(bboxTop - maxY) <= 128);
                    Assert.IsTrue(Math.Abs(bboxBottom - minY) <= 128);
                }
            }
        }
Exemplo n.º 2
0
        public LineDef(Vertex vertex1, Vertex vertex2, LineFlags flags, LineSpecial special, short tag, SideDef frontSide, SideDef backSide)
        {
            this.vertex1   = vertex1;
            this.vertex2   = vertex2;
            this.flags     = flags;
            this.special   = special;
            this.tag       = tag;
            this.frontSide = frontSide;
            this.backSide  = backSide;

            this.dx = vertex2.X - vertex1.X;
            this.dy = vertex2.Y - vertex1.Y;

            if (this.dx == Fixed.Zero)
            {
                this.slopeType = SlopeType.Vertical;
            }
            else if (this.dy == Fixed.Zero)
            {
                this.slopeType = SlopeType.Horizontal;
            }
            else
            {
                if (this.dy / this.dx > Fixed.Zero)
                {
                    this.slopeType = SlopeType.Positive;
                }
                else
                {
                    this.slopeType = SlopeType.Negative;
                }
            }

            this.boundingBox             = new Fixed[4];
            this.boundingBox[Box.Top]    = Fixed.Max(vertex1.Y, vertex2.Y);
            this.boundingBox[Box.Bottom] = Fixed.Min(vertex1.Y, vertex2.Y);
            this.boundingBox[Box.Left]   = Fixed.Min(vertex1.X, vertex2.X);
            this.boundingBox[Box.Right]  = Fixed.Max(vertex1.X, vertex2.X);

            this.frontSector = frontSide?.Sector;
            this.backSector  = backSide?.Sector;
        }
Exemplo n.º 3
0
        public void MinMax()
        {
            var random = new Random(666);

            for (var i = 0; i < 100; i++)
            {
                var a   = random.Next(5);
                var b   = random.Next(5);
                var min = Math.Min(a, b);
                var max = Math.Max(a, b);

                var fa   = Fixed.FromInt(a);
                var fb   = Fixed.FromInt(b);
                var fmin = Fixed.Min(fa, fb);
                var fmax = Fixed.Max(fa, fb);

                Assert.AreEqual(min, fmin.ToDouble(), 1.0E-9);
                Assert.AreEqual(max, fmax.ToDouble(), 1.0E-9);
            }
        }