Esempio n. 1
0
            private void ArchiveLine(LineDef line)
            {
                this.writer.Write((short)line.Flags);
                this.writer.Write((short)line.Special);
                this.writer.Write((short)line.Tag);

                if (line.FrontSide != null)
                {
                    var side = line.FrontSide;
                    this.writer.Write((short)side.TextureOffset.ToIntFloor());
                    this.writer.Write((short)side.RowOffset.ToIntFloor());
                    this.writer.Write((short)side.TopTexture);
                    this.writer.Write((short)side.BottomTexture);
                    this.writer.Write((short)side.MiddleTexture);
                }

                if (line.BackSide != null)
                {
                    var side = line.BackSide;
                    this.writer.Write((short)side.TextureOffset.ToIntFloor());
                    this.writer.Write((short)side.RowOffset.ToIntFloor());
                    this.writer.Write((short)side.TopTexture);
                    this.writer.Write((short)side.BottomTexture);
                    this.writer.Write((short)side.MiddleTexture);
                }
            }
Esempio n. 2
0
        public void PointOnLineSide1()
        {
            var random = new Random(666);

            for (var i = 0; i < 1000; i++)
            {
                var startX = -1 - 666 * random.NextDouble();
                var endX   = +1 + 666 * random.NextDouble();

                var pointX     = 666 * random.NextDouble() - 333;
                var frontSideY = -1 - 666 * random.NextDouble();
                var backSideY  = -frontSideY;

                var vertex1 = new Vertex(Fixed.FromDouble(startX), Fixed.Zero);
                var vertex2 = new Vertex(Fixed.FromDouble(endX - startX), Fixed.Zero);

                var line = new LineDef(
                    vertex1,
                    vertex2,
                    0, 0, 0, null, null);

                var x = Fixed.FromDouble(pointX);
                {
                    var y = Fixed.FromDouble(frontSideY);
                    Assert.AreEqual(0, Geometry.PointOnLineSide(x, y, line));
                }
                {
                    var y = Fixed.FromDouble(backSideY);
                    Assert.AreEqual(1, Geometry.PointOnLineSide(x, y, line));
                }
            }
        }
Esempio n. 3
0
 public void MakeFrom(LineDef line)
 {
     this.x  = line.Vertex1.X;
     this.y  = line.Vertex1.Y;
     this.dx = line.Dx;
     this.dy = line.Dy;
 }
Esempio n. 4
0
        /// <summary>
        /// Sets opentop and openbottom to the window through a two sided line.
        /// </summary>
        public void LineOpening(LineDef line)
        {
            if (line.BackSide == null)
            {
                // If the line is single sided, nothing can pass through.
                this.openRange = Fixed.Zero;

                return;
            }

            var front = line.FrontSector;
            var back  = line.BackSector;

            if (front.CeilingHeight < back.CeilingHeight)
            {
                this.openTop = front.CeilingHeight;
            }
            else
            {
                this.openTop = back.CeilingHeight;
            }

            if (front.FloorHeight > back.FloorHeight)
            {
                this.openBottom = front.FloorHeight;
                this.lowFloor   = back.FloorHeight;
            }
            else
            {
                this.openBottom = back.FloorHeight;
                this.lowFloor   = front.FloorHeight;
            }

            this.openRange = this.openTop - this.openBottom;
        }
Esempio n. 5
0
        public static LineDef ParseLineDef(IHaveAssignments block)
        {
            var parsedBlock = new LineDef();

            block.GetValueFor("Id").SetOptionalInteger(value => parsedBlock.Id                       = value, "LineDef", "Id");
            block.GetValueFor("V1").SetRequiredInteger(value => parsedBlock.V1                       = value, "LineDef", "V1");
            block.GetValueFor("V2").SetRequiredInteger(value => parsedBlock.V2                       = value, "LineDef", "V2");
            block.GetValueFor("Blocking").SetOptionalBoolean(value => parsedBlock.Blocking           = value, "LineDef", "Blocking");
            block.GetValueFor("BlockMonsters").SetOptionalBoolean(value => parsedBlock.BlockMonsters = value, "LineDef", "BlockMonsters");
            block.GetValueFor("TwoSided").SetOptionalBoolean(value => parsedBlock.TwoSided           = value, "LineDef", "TwoSided");
            block.GetValueFor("DontPegTop").SetOptionalBoolean(value => parsedBlock.DontPegTop       = value, "LineDef", "DontPegTop");
            block.GetValueFor("DontPegBottom").SetOptionalBoolean(value => parsedBlock.DontPegBottom = value, "LineDef", "DontPegBottom");
            block.GetValueFor("Secret").SetOptionalBoolean(value => parsedBlock.Secret               = value, "LineDef", "Secret");
            block.GetValueFor("BlockSound").SetOptionalBoolean(value => parsedBlock.BlockSound       = value, "LineDef", "BlockSound");
            block.GetValueFor("DontDraw").SetOptionalBoolean(value => parsedBlock.DontDraw           = value, "LineDef", "DontDraw");
            block.GetValueFor("Mapped").SetOptionalBoolean(value => parsedBlock.Mapped               = value, "LineDef", "Mapped");
            block.GetValueFor("Special").SetOptionalInteger(value => parsedBlock.Special             = value, "LineDef", "Special");
            block.GetValueFor("Arg0").SetOptionalInteger(value => parsedBlock.Arg0                   = value, "LineDef", "Arg0");
            block.GetValueFor("Arg1").SetOptionalInteger(value => parsedBlock.Arg1                   = value, "LineDef", "Arg1");
            block.GetValueFor("Arg2").SetOptionalInteger(value => parsedBlock.Arg2                   = value, "LineDef", "Arg2");
            block.GetValueFor("Arg3").SetOptionalInteger(value => parsedBlock.Arg3                   = value, "LineDef", "Arg3");
            block.GetValueFor("Arg4").SetOptionalInteger(value => parsedBlock.Arg4                   = value, "LineDef", "Arg4");
            block.GetValueFor("SideFront").SetRequiredInteger(value => parsedBlock.SideFront         = value, "LineDef", "SideFront");
            block.GetValueFor("SideBack").SetOptionalInteger(value => parsedBlock.SideBack           = value, "LineDef", "SideBack");
            block.GetValueFor("Comment").SetOptionalString(value => parsedBlock.Comment              = value, "LineDef", "Comment");
            return(parsedBlock);
        }
Esempio n. 6
0
        public void LoadE1M1()
        {
            using (var wad = new Wad(WadPath.Doom1))
            {
                var flats      = new FlatLookup(wad, true);
                var textures   = new TextureLookup(wad, true);
                var map        = wad.GetLumpNumber("E1M1");
                var vertices   = Vertex.FromWad(wad, map + 4);
                var sectors    = Sector.FromWad(wad, map + 8, flats);
                var sides      = SideDef.FromWad(wad, map + 3, textures, sectors);
                var lines      = LineDef.FromWad(wad, map + 2, vertices, sides);
                var segs       = Seg.FromWad(wad, map + 5, vertices, lines);
                var subsectors = Subsector.FromWad(wad, map + 6, segs);

                Assert.AreEqual(239, subsectors.Length);

                Assert.AreEqual(8, subsectors[0].SegCount);
                for (var i = 0; i < 8; i++)
                {
                    Assert.IsTrue(segs[subsectors[0].FirstSeg + i] == segs[0 + i]);
                }

                Assert.AreEqual(1, subsectors[54].SegCount);
                for (var i = 0; i < 1; i++)
                {
                    Assert.IsTrue(segs[subsectors[54].FirstSeg + i] == segs[181 + i]);
                }

                Assert.AreEqual(2, subsectors[238].SegCount);
                for (var i = 0; i < 2; i++)
                {
                    Assert.IsTrue(segs[subsectors[238].FirstSeg + i] == segs[745 + i]);
                }
            }
        }
Esempio n. 7
0
 private static void Write(StreamWriter writer, LineDef linedef)
 {
     writer.WriteLine("linedef");
     writer.WriteLine("{");
     WriteProperty(writer, "id", linedef.Id, -1);
     WriteProperty(writer, "v1", linedef.V1);
     WriteProperty(writer, "v2", linedef.V2);
     WriteProperty(writer, "blocking", linedef.Blocking, false);
     WriteProperty(writer, "blockMonsters", linedef.BlockMonsters, false);
     WriteProperty(writer, "twoSided", linedef.TwoSided, false);
     WriteProperty(writer, "dontPegTop", linedef.DontPegTop, false);
     WriteProperty(writer, "dontPegBottom", linedef.DontPegBottom, false);
     WriteProperty(writer, "secret", linedef.Secret, false);
     WriteProperty(writer, "blockSound", linedef.BlockSound, false);
     WriteProperty(writer, "dontDraw", linedef.DontDraw, false);
     WriteProperty(writer, "mapped", linedef.Mapped, false);
     WriteProperty(writer, "special", linedef.Special, 0);
     WriteProperty(writer, "arg0", linedef.Arg0, 0);
     WriteProperty(writer, "arg1", linedef.Arg1, 0);
     WriteProperty(writer, "arg2", linedef.Arg2, 0);
     WriteProperty(writer, "arg3", linedef.Arg3, 0);
     WriteProperty(writer, "arg4", linedef.Arg4, 0);
     WriteProperty(writer, "sideFront", linedef.SideFront);
     WriteProperty(writer, "sideBack", linedef.SideBack, -1);
     WriteProperty(writer, "comment", linedef.Comment, "");
     writer.WriteLine("}");
 }
Esempio n. 8
0
        private void StartButton(LineDef line, ButtonPosition w, int texture, int time)
        {
            // See if button is already pressed.
            for (var i = 0; i < Specials.maxButtonCount; i++)
            {
                if (this.buttonList[i].Timer != 0 && this.buttonList[i].Line == line)
                {
                    return;
                }
            }

            for (var i = 0; i < Specials.maxButtonCount; i++)
            {
                if (this.buttonList[i].Timer == 0)
                {
                    this.buttonList[i].Line        = line;
                    this.buttonList[i].Position    = w;
                    this.buttonList[i].Texture     = texture;
                    this.buttonList[i].Timer       = time;
                    this.buttonList[i].SoundOrigin = line.SoundOrigin;

                    return;
                }
            }

            throw new Exception("No button slots left!");
        }
Esempio n. 9
0
        public void LoadMap01()
        {
            using (var wad = new Wad(WadPath.Doom2))
            {
                var flats      = new FlatLookup(wad, true);
                var textures   = new TextureLookup(wad, true);
                var map        = wad.GetLumpNumber("MAP01");
                var vertices   = Vertex.FromWad(wad, map + 4);
                var sectors    = Sector.FromWad(wad, map + 8, flats);
                var sides      = SideDef.FromWad(wad, map + 3, textures, sectors);
                var lines      = LineDef.FromWad(wad, map + 2, vertices, sides);
                var segs       = Seg.FromWad(wad, map + 5, vertices, lines);
                var subsectors = Subsector.FromWad(wad, map + 6, segs);

                Assert.AreEqual(194, subsectors.Length);

                Assert.AreEqual(4, subsectors[0].SegCount);
                for (var i = 0; i < 4; i++)
                {
                    Assert.IsTrue(segs[subsectors[0].FirstSeg + i] == segs[i]);
                }

                Assert.AreEqual(4, subsectors[57].SegCount);
                for (var i = 0; i < 4; i++)
                {
                    Assert.IsTrue(segs[subsectors[57].FirstSeg + i] == segs[179 + i]);
                }

                Assert.AreEqual(4, subsectors[193].SegCount);
                for (var i = 0; i < 4; i++)
                {
                    Assert.IsTrue(segs[subsectors[193].FirstSeg + i] == segs[597 + i]);
                }
            }
        }
Esempio n. 10
0
            private void UnArchiveLine(LineDef line)
            {
                line.Flags   = (LineFlags)this.reader.ReadInt16();
                line.Special = (LineSpecial)this.reader.ReadInt16();
                line.Tag     = this.reader.ReadInt16();

                if (line.FrontSide != null)
                {
                    var side = line.FrontSide;
                    side.TextureOffset = Fixed.FromInt(this.reader.ReadInt16());
                    side.RowOffset     = Fixed.FromInt(this.reader.ReadInt16());
                    side.TopTexture    = this.reader.ReadInt16();
                    side.BottomTexture = this.reader.ReadInt16();
                    side.MiddleTexture = this.reader.ReadInt16();
                }

                if (line.BackSide != null)
                {
                    var side = line.BackSide;
                    side.TextureOffset = Fixed.FromInt(this.reader.ReadInt16());
                    side.RowOffset     = Fixed.FromInt(this.reader.ReadInt16());
                    side.TopTexture    = this.reader.ReadInt16();
                    side.BottomTexture = this.reader.ReadInt16();
                    side.MiddleTexture = this.reader.ReadInt16();
                }
            }
Esempio n. 11
0
        public void PointOnDivLineSide2()
        {
            var random = new Random(666);

            for (var i = 0; i < 1000; i++)
            {
                var startY = +1 + 666 * random.NextDouble();
                var endY   = -1 - 666 * random.NextDouble();

                var pointY     = 666 * random.NextDouble() - 333;
                var frontSideX = -1 - 666 * random.NextDouble();
                var backSideX  = -frontSideX;

                var vertex1 = new Vertex(Fixed.Zero, Fixed.FromDouble(startY));
                var vertex2 = new Vertex(Fixed.Zero, Fixed.FromDouble(endY - startY));

                var line = new LineDef(
                    vertex1,
                    vertex2,
                    0, 0, 0, null, null);

                var divLine = new DivLine();
                divLine.MakeFrom(line);

                var y = Fixed.FromDouble(pointY);
                {
                    var x = Fixed.FromDouble(frontSideX);
                    Assert.AreEqual(0, Geometry.PointOnDivLineSide(x, y, divLine));
                }
                {
                    var x = Fixed.FromDouble(backSideX);
                    Assert.AreEqual(1, Geometry.PointOnDivLineSide(x, y, divLine));
                }
            }
        }
Esempio n. 12
0
        private bool SlideTraverse(Intercept intercept)
        {
            var mc = this.world.MapCollision;

            if (intercept.Line == null)
            {
                throw new Exception("ThingMovement.SlideTraverse: Not a line?");
            }

            var line = intercept.Line;

            if ((line.Flags & LineFlags.TwoSided) == 0)
            {
                if (Geometry.PointOnLineSide(this.slideThing.X, this.slideThing.Y, line) != 0)
                {
                    // Don't hit the back side.
                    return(true);
                }

                goto isBlocking;
            }

            // Set openrange, opentop, openbottom.
            mc.LineOpening(line);

            if (mc.OpenRange < this.slideThing.Height)
            {
                // Doesn't fit.
                goto isBlocking;
            }

            if (mc.OpenTop - this.slideThing.Z < this.slideThing.Height)
            {
                // Mobj is too high.
                goto isBlocking;
            }

            if (mc.OpenBottom - this.slideThing.Z > Fixed.FromInt(24))
            {
                // Too big a step up.
                goto isBlocking;
            }

            // This line doesn't block movement.
            return(true);

            // The line does block movement, see if it is closer than best so far.
isBlocking:

            if (intercept.Frac < this.bestSlideFrac)
            {
                this.secondSlideFrac = this.bestSlideFrac;
                this.secondSlideLine = this.bestSlideLine;
                this.bestSlideFrac   = intercept.Frac;
                this.bestSlideLine   = line;
            }

            // Stop.
            return(false);
        }
Esempio n. 13
0
        public static LineDef LineDef(BinaryReader reader)
        {
            var ld = new LineDef
            {
                V1 = reader.ReadInt16(),
                V2 = reader.ReadInt16()
            };

            var flags = (LineDefFlags)reader.ReadInt16();

            ld.Blocking      = flags.HasFlag(LineDefFlags.BlockPlayersAndMonsters);
            ld.BlockMonsters = flags.HasFlag(LineDefFlags.BlockMonsters);
            ld.TwoSided      = flags.HasFlag(LineDefFlags.TwoSided);
            ld.DontPegTop    = flags.HasFlag(LineDefFlags.UpperTextureUnpegged);
            ld.DontPegBottom = flags.HasFlag(LineDefFlags.LowerTextureUnpegged);
            ld.Secret        = flags.HasFlag(LineDefFlags.Secret);
            ld.BlockSound    = flags.HasFlag(LineDefFlags.BlocksSound);
            ld.DontDraw      = flags.HasFlag(LineDefFlags.NeverShowOnAutomap);
            ld.Mapped        = flags.HasFlag(LineDefFlags.AlwaysShowOnAutomap);

            ld.Special   = reader.ReadInt16();
            ld.Id        = reader.ReadInt16();
            ld.SideFront = reader.ReadInt16();
            ld.SideBack  = reader.ReadInt16();

            return(ld);
        }
Esempio n. 14
0
        public void DivLineSide3()
        {
            var random = new Random(666);

            for (var i = 0; i < 1000; i++)
            {
                var startX = -1 - 666 * random.NextDouble();
                var endX   = +1 + 666 * random.NextDouble();

                var pointX     = 666 * random.NextDouble() - 333;
                var frontSideY = -1 - 666 * random.NextDouble();
                var backSideY  = -frontSideY;

                for (var j = 0; j < 100; j++)
                {
                    var theta = 2 * Math.PI * random.NextDouble();
                    var ox    = 666 * random.NextDouble() - 333;
                    var oy    = 666 * random.NextDouble() - 333;

                    var vertex1 = new Vertex(
                        Fixed.FromDouble(ox + startX * Math.Cos(theta)),
                        Fixed.FromDouble(oy + startX * Math.Sin(theta)));

                    var vertex2 = new Vertex(
                        vertex1.X + Fixed.FromDouble((endX - startX) * Math.Cos(theta)),
                        vertex1.Y + Fixed.FromDouble((endX - startX) * Math.Sin(theta)));

                    var line = new LineDef(
                        vertex1,
                        vertex2,
                        0, 0, 0, null, null);

                    var divLine = new DivLine();
                    divLine.MakeFrom(line);

                    var node = new Node(
                        Fixed.FromDouble(ox + startX * Math.Cos(theta)),
                        Fixed.FromDouble(oy + startX * Math.Sin(theta)),
                        Fixed.FromDouble((endX - startX) * Math.Cos(theta)),
                        Fixed.FromDouble((endX - startX) * Math.Sin(theta)),
                        Fixed.Zero, Fixed.Zero, Fixed.Zero, Fixed.Zero,
                        Fixed.Zero, Fixed.Zero, Fixed.Zero, Fixed.Zero,
                        0, 0);

                    {
                        var x = Fixed.FromDouble(ox + pointX * Math.Cos(theta) - frontSideY * Math.Sin(theta));
                        var y = Fixed.FromDouble(oy + pointX * Math.Sin(theta) + frontSideY * Math.Cos(theta));
                        Assert.AreEqual(0, Geometry.DivLineSide(x, y, divLine));
                        Assert.AreEqual(0, Geometry.DivLineSide(x, y, node));
                    }
                    {
                        var x = Fixed.FromDouble(ox + pointX * Math.Cos(theta) - backSideY * Math.Sin(theta));
                        var y = Fixed.FromDouble(oy + pointX * Math.Sin(theta) + backSideY * Math.Cos(theta));
                        Assert.AreEqual(1, Geometry.DivLineSide(x, y, divLine));
                        Assert.AreEqual(1, Geometry.DivLineSide(x, y, node));
                    }
                }
            }
        }
Esempio n. 15
0
 public Line(Vertex start, Vertex end, SideDef side, bool isFrontSide, LineDef definition)
 {
     Start       = start;
     End         = end;
     Side        = side;
     IsFrontSide = isFrontSide;
     Definition  = definition;
 }
Esempio n. 16
0
 public void Clear()
 {
     this.line        = null;
     this.position    = 0;
     this.texture     = 0;
     this.timer       = 0;
     this.soundOrigin = null;
 }
Esempio n. 17
0
        public bool TeleportMove(Mobj thing, Fixed x, Fixed y)
        {
            // Kill anything occupying the position.
            this.currentThing = thing;
            this.currentFlags = thing.Flags;

            this.currentX = x;
            this.currentY = y;

            this.currentBox[Box.Top]    = y + this.currentThing.Radius;
            this.currentBox[Box.Bottom] = y - this.currentThing.Radius;
            this.currentBox[Box.Right]  = x + this.currentThing.Radius;
            this.currentBox[Box.Left]   = x - this.currentThing.Radius;

            var ss = Geometry.PointInSubsector(x, y, this.world.Map);

            this.currentCeilingLine = null;

            // The base floor / ceiling is from the subsector that contains the point.
            // Any contacted lines the step closer together will adjust them.
            this.currentFloorZ   = this.currentDropoffZ = ss.Sector.FloorHeight;
            this.currentCeilingZ = ss.Sector.CeilingHeight;

            var validcount = this.world.GetNewValidCount();

            this.crossedSpecialCount = 0;

            // Stomp on any things contacted.
            var bm      = this.world.Map.BlockMap;
            var blockX1 = bm.GetBlockX(this.currentBox[Box.Left] - GameConst.MaxThingRadius);
            var blockX2 = bm.GetBlockX(this.currentBox[Box.Right] + GameConst.MaxThingRadius);
            var blockY1 = bm.GetBlockY(this.currentBox[Box.Bottom] - GameConst.MaxThingRadius);
            var blockY2 = bm.GetBlockY(this.currentBox[Box.Top] + GameConst.MaxThingRadius);

            for (var bx = blockX1; bx <= blockX2; bx++)
            {
                for (var by = blockY1; by <= blockY2; by++)
                {
                    if (!bm.IterateThings(bx, by, this.stompThingFunc))
                    {
                        return(false);
                    }
                }
            }

            // the move is ok, so link the thing into its new position
            this.UnsetThingPosition(thing);

            thing.FloorZ   = this.currentFloorZ;
            thing.CeilingZ = this.currentCeilingZ;
            thing.X        = x;
            thing.Y        = y;

            this.SetThingPosition(thing);

            return(true);
        }
Esempio n. 18
0
 public LineSeg(int v1, int v2, int angle, LineDef line, SideDef side, int offset)
 {
     V1     = v1;
     V2     = v2;
     Angle  = angle;
     Line   = line;
     Side   = side;
     Offset = offset;
 }
Esempio n. 19
0
        /// <summary>
        /// Calculate on which side of the line the box is.
        /// </summary>
        /// <returns>
        /// 0 (front), 1 (back), or -1 if the box crosses the line.
        /// </returns>
        public static int BoxOnLineSide(Fixed[] box, LineDef line)
        {
            int p1;
            int p2;

            switch (line.SlopeType)
            {
            case SlopeType.Horizontal:
                p1 = box[Box.Top] > line.Vertex1.Y ? 1 : 0;
                p2 = box[Box.Bottom] > line.Vertex1.Y ? 1 : 0;

                if (line.Dx < Fixed.Zero)
                {
                    p1 ^= 1;
                    p2 ^= 1;
                }

                break;

            case SlopeType.Vertical:
                p1 = box[Box.Right] < line.Vertex1.X ? 1 : 0;
                p2 = box[Box.Left] < line.Vertex1.X ? 1 : 0;

                if (line.Dy < Fixed.Zero)
                {
                    p1 ^= 1;
                    p2 ^= 1;
                }

                break;

            case SlopeType.Positive:
                p1 = Geometry.PointOnLineSide(box[Box.Left], box[Box.Top], line);
                p2 = Geometry.PointOnLineSide(box[Box.Right], box[Box.Bottom], line);

                break;

            case SlopeType.Negative:
                p1 = Geometry.PointOnLineSide(box[Box.Right], box[Box.Top], line);
                p2 = Geometry.PointOnLineSide(box[Box.Left], box[Box.Bottom], line);

                break;

            default:
                throw new Exception("Invalid SlopeType.");
            }

            if (p1 == p2)
            {
                return(p1);
            }
            else
            {
                return(-1);
            }
        }
Esempio n. 20
0
        public void BoxOnLineSide2()
        {
            var random = new Random(666);

            for (var i = 0; i < 1000; i++)
            {
                var radius = 33 + 33 * random.NextDouble();

                var startY = +1 + 666 * random.NextDouble();
                var endY   = -1 - 666 * random.NextDouble();

                var pointY     = 666 * random.NextDouble() - 333;
                var frontSideX = -1 - radius - 666 * random.NextDouble();
                var backSideX  = -frontSideX;
                var crossingX  = radius * 1.9 * (random.NextDouble() - 0.5);

                var frontBox = new Fixed[]
                {
                    Fixed.FromDouble(pointY + radius),
                    Fixed.FromDouble(pointY - radius),
                    Fixed.FromDouble(frontSideX - radius),
                    Fixed.FromDouble(frontSideX + radius)
                };

                var backBox = new Fixed[]
                {
                    Fixed.FromDouble(pointY + radius),
                    Fixed.FromDouble(pointY - radius),
                    Fixed.FromDouble(backSideX - radius),
                    Fixed.FromDouble(backSideX + radius)
                };

                var crossingBox = new Fixed[]
                {
                    Fixed.FromDouble(pointY + radius),
                    Fixed.FromDouble(pointY - radius),
                    Fixed.FromDouble(crossingX - radius),
                    Fixed.FromDouble(crossingX + radius)
                };

                var vertex1 = new Vertex(Fixed.Zero, Fixed.FromDouble(startY));
                var vertex2 = new Vertex(Fixed.Zero, Fixed.FromDouble(endY - startY));

                var line = new LineDef(
                    vertex1,
                    vertex2,
                    0, 0, 0, null, null);

                Assert.AreEqual(0, Geometry.BoxOnLineSide(frontBox, line));
                Assert.AreEqual(1, Geometry.BoxOnLineSide(backBox, line));
                Assert.AreEqual(-1, Geometry.BoxOnLineSide(crossingBox, line));
            }
        }
Esempio n. 21
0
        public void LoadMap01()
        {
            using (var wad = new Wad(WadPath.Doom2))
            {
                var flats    = new DummyFlatLookup(wad);
                var textures = new DummyTextureLookup(wad);
                var map      = wad.GetLumpNumber("MAP01");
                var vertices = Vertex.FromWad(wad, map + 4);
                var sectors  = Sector.FromWad(wad, map + 8, flats);
                var sides    = SideDef.FromWad(wad, map + 3, textures, sectors);
                var lines    = LineDef.FromWad(wad, map + 2, vertices, sides);
                var segs     = Seg.FromWad(wad, map + 5, vertices, lines);

                Assert.AreEqual(601, segs.Length);

                Assert.IsTrue(segs[0].Vertex1 == vertices[9]);
                Assert.IsTrue(segs[0].Vertex2 == vertices[316]);
                Assert.AreEqual(ToRadian(-32768), segs[0].Angle.ToRadian(), delta);
                Assert.IsTrue(segs[0].LineDef == lines[8]);
                Assert.IsTrue((segs[0].LineDef.Flags & LineFlags.TwoSided) != 0);
                Assert.IsTrue(segs[0].FrontSector == segs[0].LineDef.FrontSide.Sector);
                Assert.IsTrue(segs[0].BackSector == segs[0].LineDef.BackSide.Sector);
                Assert.AreEqual(0, segs[0].Offset.ToDouble(), delta);

                Assert.IsTrue(segs[42].Vertex1 == vertices[26]);
                Assert.IsTrue(segs[42].Vertex2 == vertices[320]);
                Assert.AreEqual(ToRadian(-22209), segs[42].Angle.ToRadian(), delta);
                Assert.IsTrue(segs[42].LineDef == lines[33]);
                Assert.IsTrue((segs[42].LineDef.Flags & LineFlags.TwoSided) != 0);
                Assert.IsTrue(segs[42].FrontSector == segs[42].LineDef.BackSide.Sector);
                Assert.IsTrue(segs[42].BackSector == segs[42].LineDef.FrontSide.Sector);
                Assert.AreEqual(0, segs[42].Offset.ToDouble(), delta);

                Assert.IsTrue(segs[103].Vertex1 == vertices[331]);
                Assert.IsTrue(segs[103].Vertex2 == vertices[329]);
                Assert.AreEqual(ToRadian(16384), segs[103].Angle.ToRadian(), delta);
                Assert.IsTrue(segs[103].LineDef == lines[347]);
                Assert.IsTrue((segs[103].LineDef.Flags & LineFlags.TwoSided) == 0);
                Assert.IsTrue(segs[103].FrontSector == segs[103].LineDef.FrontSide.Sector);
                Assert.IsTrue(segs[103].BackSector == null);
                Assert.AreEqual(64, segs[103].Offset.ToDouble(), delta);

                Assert.IsTrue(segs[600].Vertex1 == vertices[231]);
                Assert.IsTrue(segs[600].Vertex2 == vertices[237]);
                Assert.AreEqual(ToRadian(-16384), segs[600].Angle.ToRadian(), delta);
                Assert.IsTrue(segs[600].LineDef == lines[271]);
                Assert.IsTrue((segs[600].LineDef.Flags & LineFlags.TwoSided) != 0);
                Assert.IsTrue(segs[600].FrontSector == segs[600].LineDef.BackSide.Sector);
                Assert.IsTrue(segs[600].BackSector == segs[600].LineDef.FrontSide.Sector);
                Assert.AreEqual(0, segs[600].Offset.ToDouble(), delta);
            }
        }
Esempio n. 22
0
        public void LoadE1M1()
        {
            using (var wad = new Wad(WadPath.Doom1))
            {
                var flats    = new DummyFlatLookup(wad);
                var textures = new DummyTextureLookup(wad);
                var map      = wad.GetLumpNumber("E1M1");
                var vertices = Vertex.FromWad(wad, map + 4);
                var sectors  = Sector.FromWad(wad, map + 8, flats);
                var sides    = SideDef.FromWad(wad, map + 3, textures, sectors);
                var lines    = LineDef.FromWad(wad, map + 2, vertices, sides);
                var segs     = Seg.FromWad(wad, map + 5, vertices, lines);

                Assert.AreEqual(747, segs.Length);

                Assert.IsTrue(segs[0].Vertex1 == vertices[132]);
                Assert.IsTrue(segs[0].Vertex2 == vertices[133]);
                Assert.AreEqual(ToRadian(4156), segs[0].Angle.ToRadian(), delta);
                Assert.IsTrue(segs[0].LineDef == lines[160]);
                Assert.IsTrue((segs[0].LineDef.Flags & LineFlags.TwoSided) != 0);
                Assert.IsTrue(segs[0].FrontSector == segs[0].LineDef.FrontSide.Sector);
                Assert.IsTrue(segs[0].BackSector == segs[0].LineDef.BackSide.Sector);
                Assert.AreEqual(0, segs[0].Offset.ToDouble(), delta);

                Assert.IsTrue(segs[28].Vertex1 == vertices[390]);
                Assert.IsTrue(segs[28].Vertex2 == vertices[131]);
                Assert.AreEqual(ToRadian(-32768), segs[28].Angle.ToRadian(), delta);
                Assert.IsTrue(segs[28].LineDef == lines[480]);
                Assert.IsTrue((segs[0].LineDef.Flags & LineFlags.TwoSided) != 0);
                Assert.IsTrue(segs[28].FrontSector == segs[28].LineDef.BackSide.Sector);
                Assert.IsTrue(segs[28].BackSector == segs[28].LineDef.FrontSide.Sector);
                Assert.AreEqual(0, segs[28].Offset.ToDouble(), delta);

                Assert.IsTrue(segs[744].Vertex1 == vertices[446]);
                Assert.IsTrue(segs[744].Vertex2 == vertices[374]);
                Assert.AreEqual(ToRadian(-16384), segs[744].Angle.ToRadian(), delta);
                Assert.IsTrue(segs[744].LineDef == lines[452]);
                Assert.IsTrue((segs[744].LineDef.Flags & LineFlags.TwoSided) == 0);
                Assert.IsTrue(segs[744].FrontSector == segs[744].LineDef.FrontSide.Sector);
                Assert.IsTrue(segs[744].BackSector == null);
                Assert.AreEqual(154, segs[744].Offset.ToDouble(), delta);

                Assert.IsTrue(segs[746].Vertex1 == vertices[374]);
                Assert.IsTrue(segs[746].Vertex2 == vertices[368]);
                Assert.AreEqual(ToRadian(-13828), segs[746].Angle.ToRadian(), delta);
                Assert.IsTrue(segs[746].LineDef == lines[451]);
                Assert.IsTrue((segs[746].LineDef.Flags & LineFlags.TwoSided) == 0);
                Assert.IsTrue(segs[746].FrontSector == segs[746].LineDef.FrontSide.Sector);
                Assert.IsTrue(segs[746].BackSector == null);
                Assert.AreEqual(0, segs[746].Offset.ToDouble(), delta);
            }
        }
Esempio n. 23
0
        ////////////////////////////////////////////////////////////
        // Line shoot
        ////////////////////////////////////////////////////////////

        /// <summary>
        /// Called when a thing shoots a special line.
        /// </summary>
        public void ShootSpecialLine(Mobj thing, LineDef line)
        {
            bool ok;

            //	Impacts that other things can activate.
            if (thing.Player == null)
            {
                ok = false;

                switch ((int)line.Special)
                {
                case 46:
                    // Open door impact.
                    ok = true;

                    break;
                }

                if (!ok)
                {
                    return;
                }
            }

            var sa       = this.world.SectorAction;
            var specials = this.world.Specials;

            switch ((int)line.Special)
            {
            case 24:
                // Raise floor.
                sa.DoFloor(line, FloorMoveType.RaiseFloor);
                specials.ChangeSwitchTexture(line, false);

                break;

            case 46:
                // Open door.
                sa.DoDoor(line, VerticalDoorType.Open);
                specials.ChangeSwitchTexture(line, true);

                break;

            case 47:
                // Raise floor near and change.
                sa.DoPlatform(line, PlatformType.RaiseToNearestAndChange, 0);
                specials.ChangeSwitchTexture(line, false);

                break;
            }
        }
Esempio n. 24
0
        private Sector GetNextSector(LineDef line, Sector sector)
        {
            if ((line.Flags & LineFlags.TwoSided) == 0)
            {
                return(null);
            }

            if (line.FrontSector == sector)
            {
                return(line.BackSector);
            }

            return(line.FrontSector);
        }
Esempio n. 25
0
        /// <summary>
        /// Looks for lines in the given block that intercept the given trace
        /// to add to the intercepts list.
        /// A line is crossed if its endpoints are on opposite sidesof the trace.
        /// Returns true if earlyOut and a solid line hit.
        /// </summary>
        private bool AddLineIntercepts(LineDef line)
        {
            int s1;
            int s2;

            // Avoid precision problems with two routines.
            if (this.trace.Dx > Fixed.FromInt(16) ||
                this.trace.Dy > Fixed.FromInt(16) ||
                this.trace.Dx < -Fixed.FromInt(16) ||
                this.trace.Dy < -Fixed.FromInt(16))
            {
                s1 = Geometry.PointOnDivLineSide(line.Vertex1.X, line.Vertex1.Y, this.trace);
                s2 = Geometry.PointOnDivLineSide(line.Vertex2.X, line.Vertex2.Y, this.trace);
            }
            else
            {
                s1 = Geometry.PointOnLineSide(this.trace.X, this.trace.Y, line);
                s2 = Geometry.PointOnLineSide(this.trace.X + this.trace.Dx, this.trace.Y + this.trace.Dy, line);
            }

            if (s1 == s2)
            {
                // Line isn't crossed.
                return(true);
            }

            // Hit the line.
            this.target.MakeFrom(line);

            var frac = this.InterceptVector(this.trace, this.target);

            if (frac < Fixed.Zero)
            {
                // Behind source.
                return(true);
            }

            // Try to early out the check.
            if (this.earlyOut && frac < Fixed.One && line.BackSector == null)
            {
                // Stop checking.
                return(false);
            }

            this.intercepts[this.interceptCount].Make(frac, line);
            this.interceptCount++;

            // Continue.
            return(true);
        }
Esempio n. 26
0
        public static List <LineDef> LineUpVerts(List <LineDef> unsorted)
        {
            var linedUp = new List <LineDef>();

            var prevSelection = unsorted[0];

            linedUp.Add(prevSelection);

            //Line up all linedefs
            while (linedUp.Count < unsorted.Count)
            {
                LineDef nextSelection = null;

                for (var i = 0; i < unsorted.Count; i++)
                {
                    var lineDef = unsorted[i];

                    //flip check
                    if ((lineDef.v1 == prevSelection.v1 && lineDef.v2 != prevSelection.v2) ||
                        (lineDef.v2 == prevSelection.v2 && lineDef.v1 != prevSelection.v1))
                    {
                        var t    = lineDef.v1;
                        var tRef = lineDef.v1Ref;
                        lineDef.v1    = lineDef.v2;
                        lineDef.v1Ref = lineDef.v2Ref;
                        lineDef.v2    = t;
                        lineDef.v2Ref = tRef;
                    }

                    if (lineDef.v1 == prevSelection.v2 && lineDef.v2 != prevSelection.v1)
                    {
                        nextSelection = lineDef;
                        break;
                    }
                }
                if (nextSelection == null)
                {
                    Debug.LogError("Failed to work with some verticies for a floor/ceiling the file format may be off");
                    return(new List <LineDef>());
                }

                prevSelection = nextSelection;

                linedUp.Add(nextSelection);
            }

            return(linedUp);
        }
Esempio n. 27
0
        public void LoadMap01()
        {
            using (var wad = new Wad(WadPath.Doom2))
            {
                var flats    = new DummyFlatLookup(wad);
                var textures = new DummyTextureLookup(wad);
                var map      = wad.GetLumpNumber("MAP01");
                var vertices = Vertex.FromWad(wad, map + 4);
                var sectors  = Sector.FromWad(wad, map + 8, flats);
                var sides    = SideDef.FromWad(wad, map + 3, textures, sectors);
                var lines    = LineDef.FromWad(wad, map + 2, vertices, sides);

                Assert.AreEqual(370, lines.Length);

                Assert.IsTrue(lines[0].Vertex1 == vertices[0]);
                Assert.IsTrue(lines[0].Vertex2 == vertices[1]);
                Assert.IsTrue((int)lines[0].Flags == 1);
                Assert.IsTrue((int)lines[0].Special == 0);
                Assert.IsTrue(lines[0].Tag == 0);
                Assert.IsTrue(lines[0].FrontSide == sides[0]);
                Assert.IsTrue(lines[0].BackSide == null);
                Assert.IsTrue(lines[0].FrontSector == sides[0].Sector);
                Assert.IsTrue(lines[0].BackSector == null);

                Assert.IsTrue(lines[75].Vertex1 == vertices[73]);
                Assert.IsTrue(lines[75].Vertex2 == vertices[74]);
                Assert.IsTrue((int)lines[75].Flags == 4);
                Assert.IsTrue((int)lines[75].Special == 103);
                Assert.IsTrue(lines[75].Tag == 4);
                Assert.IsTrue(lines[75].FrontSide == sides[97]);
                Assert.IsTrue(lines[75].BackSide == sides[98]);
                Assert.IsTrue(lines[75].FrontSector == sides[97].Sector);
                Assert.IsTrue(lines[75].BackSector == sides[98].Sector);

                Assert.IsTrue(lines[369].Vertex1 == vertices[293]);
                Assert.IsTrue(lines[369].Vertex2 == vertices[299]);
                Assert.IsTrue((int)lines[369].Flags == 21);
                Assert.IsTrue((int)lines[369].Special == 0);
                Assert.IsTrue(lines[369].Tag == 0);
                Assert.IsTrue(lines[369].FrontSide == sides[527]);
                Assert.IsTrue(lines[369].BackSide == sides[528]);
                Assert.IsTrue(lines[369].FrontSector == sides[527].Sector);
                Assert.IsTrue(lines[369].BackSector == sides[528].Sector);
            }
        }
Esempio n. 28
0
        public void LoadE1M1()
        {
            using (var wad = new Wad(WadPath.Doom1))
            {
                var flats    = new DummyFlatLookup(wad);
                var textures = new DummyTextureLookup(wad);
                var map      = wad.GetLumpNumber("E1M1");
                var vertices = Vertex.FromWad(wad, map + 4);
                var sectors  = Sector.FromWad(wad, map + 8, flats);
                var sides    = SideDef.FromWad(wad, map + 3, textures, sectors);
                var lines    = LineDef.FromWad(wad, map + 2, vertices, sides);

                Assert.AreEqual(486, lines.Length);

                Assert.IsTrue(lines[0].Vertex1 == vertices[0]);
                Assert.IsTrue(lines[0].Vertex2 == vertices[1]);
                Assert.IsTrue((int)lines[0].Flags == 1);
                Assert.IsTrue((int)lines[0].Special == 0);
                Assert.IsTrue(lines[0].Tag == 0);
                Assert.IsTrue(lines[0].FrontSide == sides[0]);
                Assert.IsTrue(lines[0].BackSide == null);
                Assert.IsTrue(lines[0].FrontSector == sides[0].Sector);
                Assert.IsTrue(lines[0].BackSector == null);

                Assert.IsTrue(lines[136].Vertex1 == vertices[110]);
                Assert.IsTrue(lines[136].Vertex2 == vertices[111]);
                Assert.IsTrue((int)lines[136].Flags == 28);
                Assert.IsTrue((int)lines[136].Special == 63);
                Assert.IsTrue(lines[136].Tag == 3);
                Assert.IsTrue(lines[136].FrontSide == sides[184]);
                Assert.IsTrue(lines[136].BackSide == sides[185]);
                Assert.IsTrue(lines[136].FrontSector == sides[184].Sector);
                Assert.IsTrue(lines[136].BackSector == sides[185].Sector);

                Assert.IsTrue(lines[485].Vertex1 == vertices[309]);
                Assert.IsTrue(lines[485].Vertex2 == vertices[294]);
                Assert.IsTrue((int)lines[485].Flags == 12);
                Assert.IsTrue((int)lines[485].Special == 0);
                Assert.IsTrue(lines[485].Tag == 0);
                Assert.IsTrue(lines[485].FrontSide == sides[664]);
                Assert.IsTrue(lines[485].BackSide == sides[665]);
                Assert.IsTrue(lines[485].FrontSector == sides[664].Sector);
                Assert.IsTrue(lines[485].BackSector == sides[665].Sector);
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Calculate on which side of the line the point is.
        /// </summary>
        /// <returns>
        /// 0 (front) or 1 (back).
        /// </returns>
        public static int PointOnLineSide(Fixed x, Fixed y, LineDef line)
        {
            if (line.Dx == Fixed.Zero)
            {
                if (x <= line.Vertex1.X)
                {
                    return(line.Dy > Fixed.Zero ? 1 : 0);
                }
                else
                {
                    return(line.Dy < Fixed.Zero ? 1 : 0);
                }
            }

            if (line.Dy == Fixed.Zero)
            {
                if (y <= line.Vertex1.Y)
                {
                    return(line.Dx < Fixed.Zero ? 1 : 0);
                }
                else
                {
                    return(line.Dx > Fixed.Zero ? 1 : 0);
                }
            }

            var dx = (x - line.Vertex1.X);
            var dy = (y - line.Vertex1.Y);

            var left  = new Fixed(line.Dy.Data >> Fixed.FracBits) * dx;
            var right = dy * new Fixed(line.Dx.Data >> Fixed.FracBits);

            if (right < left)
            {
                // Front side.
                return(0);
            }
            else
            {
                // Back side.
                return(1);
            }
        }
Esempio n. 30
0
        public void LoadMap01()
        {
            using (var wad = new Wad(WadPath.Doom2))
            {
                var flats    = new FlatLookup(wad, true);
                var textures = new TextureLookup(wad, true);
                var map      = wad.GetLumpNumber("MAP01");
                var vertices = Vertex.FromWad(wad, map + 4);
                var sectors  = Sector.FromWad(wad, map + 8, flats);
                var sides    = SideDef.FromWad(wad, map + 3, textures, sectors);
                var lines    = LineDef.FromWad(wad, map + 2, vertices, sides);
                var reject   = Reject.FromWad(wad, map + 9, sectors);

                foreach (var sector in sectors)
                {
                    Assert.IsFalse(reject.Check(sector, sector));
                }

                foreach (var line in lines)
                {
                    if (line.BackSector != null)
                    {
                        Assert.IsFalse(reject.Check(line.FrontSector, line.BackSector));
                    }
                }

                foreach (var s1 in sectors)
                {
                    foreach (var s2 in sectors)
                    {
                        var result1 = reject.Check(s1, s2);
                        var result2 = reject.Check(s2, s1);
                        Assert.AreEqual(result1, result2);
                    }
                }

                Assert.IsTrue(reject.Check(sectors[10], sectors[49]));
                Assert.IsTrue(reject.Check(sectors[7], sectors[36]));
                Assert.IsTrue(reject.Check(sectors[17], sectors[57]));
            }
        }
Esempio n. 31
0
 internal LineDisplays LineOverlays(string containerName){
     var container = containers[containerName];
     var lines = new LineDisplays();
     LineDef displayLine;
     PositionPoint point1, point2;
     Conductor conductor;
     KeyValuePair<double,double> p1coords;
     KeyValuePair<double,double> p2coords;
     foreach(Equipment equipment in container.Where(x => x.EquipmentType == EquipmentTopoTypes.Conductor)){
         conductor = equipment as Conductor;
         if (conductor != null){
             displayLine = new LineDef();
             point1 = conductor.Terminal1.Location.Position;
             point2 = conductor.Terminal2.Location.Position;
             p1coords = scaleToView(point1.XPosition, point1.YPosition);
             p2coords = scaleToView(point2.XPosition, point2.YPosition);
             displayLine.X1 = p1coords.Key;
             displayLine.X2 = p2coords.Key;
             displayLine.Y1 = p1coords.Value;
             displayLine.Y2 = p2coords.Value;
             displayLine.Description = String.Format("Line Segment {0}", conductor.Name); 
             lines.Add(displayLine);
         }
     }
     return lines;
 }