Ejemplo n.º 1
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]);
                }
            }
        }
Ejemplo n.º 2
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]);
                }
            }
        }
Ejemplo n.º 3
0
 public Line(Vertex start, Vertex end, SideDef side, bool isFrontSide, LineDef definition)
 {
     Start       = start;
     End         = end;
     Side        = side;
     IsFrontSide = isFrontSide;
     Definition  = definition;
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
 public LineDef(int v1, int v2, int flags, int special, int tag, SideDef side0, SideDef side1)
 {
     V1      = v1;
     V2      = v2;
     Flags   = flags;
     Special = special;
     Tag     = tag;
     Side0   = side0;
     Side1   = side1;
 }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
        public static SideDef ParseSideDef(IHaveAssignments block)
        {
            var parsedBlock = new SideDef();

            block.GetValueFor("OffsetX").SetOptionalInteger(value => parsedBlock.OffsetX            = value, "SideDef", "OffsetX");
            block.GetValueFor("OffsetY").SetOptionalInteger(value => parsedBlock.OffsetY            = value, "SideDef", "OffsetY");
            block.GetValueFor("TextureTop").SetOptionalString(value => parsedBlock.TextureTop       = value, "SideDef", "TextureTop");
            block.GetValueFor("TextureBottom").SetOptionalString(value => parsedBlock.TextureBottom = value, "SideDef", "TextureBottom");
            block.GetValueFor("TextureMiddle").SetOptionalString(value => parsedBlock.TextureMiddle = value, "SideDef", "TextureMiddle");
            block.GetValueFor("Sector").SetRequiredInteger(value => parsedBlock.Sector  = value, "SideDef", "Sector");
            block.GetValueFor("Comment").SetOptionalString(value => parsedBlock.Comment = value, "SideDef", "Comment");
            return(parsedBlock);
        }
Ejemplo n.º 9
0
 private static void Write(StreamWriter writer, SideDef sidedef)
 {
     writer.WriteLine("sidedef");
     writer.WriteLine("{");
     WriteProperty(writer, "offsetX", sidedef.OffsetX, 0);
     WriteProperty(writer, "offsetY", sidedef.OffsetY, 0);
     WriteProperty(writer, "textureTop", sidedef.TextureTop, Texture.None);
     WriteProperty(writer, "textureBottom", sidedef.TextureBottom, Texture.None);
     WriteProperty(writer, "textureMiddle", sidedef.TextureMiddle, Texture.None);
     WriteProperty(writer, "sector", sidedef.Sector);
     WriteProperty(writer, "comment", sidedef.Comment, "");
     writer.WriteLine("}");
 }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
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);
            }
        }
        static SideDef ProcessSideDef(ASTNode block)
        {
            var sideDef = new SideDef();

            foreach (var assignment in block.Children.Skip(1))
            {
                var id = GetAssignmentIdentifier(assignment);
                switch (id.ToLower())
                {
                case "offsetx":
                    sideDef.OffsetX = ReadInt(assignment, "SideDef.OffsetX");
                    break;

                case "offsety":
                    sideDef.OffsetY = ReadInt(assignment, "SideDef.OffsetY");
                    break;

                case "texturetop":
                    sideDef.TextureTop = ReadString(assignment, "SideDef.TextureTop");
                    break;

                case "texturebottom":
                    sideDef.TextureBottom = ReadString(assignment, "SideDef.TextureBottom");
                    break;

                case "texturemiddle":
                    sideDef.TextureMiddle = ReadString(assignment, "SideDef.TextureMiddle");
                    break;

                case "sector":
                    sideDef.Sector = ReadInt(assignment, "SideDef.Sector");
                    break;

                case "comment":
                    sideDef.Comment = ReadString(assignment, "SideDef.Comment");
                    break;

                default:
                    sideDef.UnknownProperties.Add(new UnknownProperty(id, ReadRawValue(assignment)));
                    break;
                }
            }
            return(sideDef);
        }
Ejemplo n.º 13
0
        static SideDef ProcessSideDef(Block block)
        {
            var sideDef = new SideDef();

            foreach (var assignment in block.Fields)
            {
                switch (assignment.Name.ToLower())
                {
                case "offsetx":
                    sideDef.OffsetX = ReadIntValue(assignment, "SideDef.OffsetX");
                    break;

                case "offsety":
                    sideDef.OffsetY = ReadIntValue(assignment, "SideDef.OffsetY");
                    break;

                case "texturetop":
                    sideDef.TextureTop = ReadStringValue(assignment, "SideDef.TextureTop");
                    break;

                case "texturebottom":
                    sideDef.TextureBottom = ReadStringValue(assignment, "SideDef.TextureBottom");
                    break;

                case "texturemiddle":
                    sideDef.TextureMiddle = ReadStringValue(assignment, "SideDef.TextureMiddle");
                    break;

                case "sector":
                    sideDef.Sector = ReadIntValue(assignment, "SideDef.Sector");
                    break;

                case "comment":
                    sideDef.Comment = ReadStringValue(assignment, "SideDef.Comment");
                    break;

                default:
                    sideDef.UnknownProperties.Add(new UnknownProperty(assignment.Name, assignment.ValueAsString()));
                    break;
                }
            }
            return(sideDef);
        }
Ejemplo n.º 14
0
        public void LoadMap01()
        {
            using (var wad = new Wad(WadPath.Doom2))
            {
                var flats    = new FlatLookup(wad, true);
                var textures = new TextureLookup(wad, false);
                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);

                Assert.AreEqual(529, sides.Length);

                Assert.AreEqual(0, sides[0].TextureOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[0].RowOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[0].TopTexture);
                Assert.AreEqual(0, sides[0].BottomTexture);
                Assert.AreEqual("BRONZE1", textures[sides[0].MiddleTexture].Name);
                Assert.IsTrue(sides[0].Sector == sectors[9]);

                Assert.AreEqual(0, sides[312].TextureOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[312].RowOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[312].TopTexture);
                Assert.AreEqual(0, sides[312].BottomTexture);
                Assert.AreEqual("DOORTRAK", textures[sides[312].MiddleTexture].Name);
                Assert.IsTrue(sides[312].Sector == sectors[31]);

                Assert.AreEqual(24, sides[512].TextureOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[512].RowOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[512].TopTexture);
                Assert.AreEqual(0, sides[512].BottomTexture);
                Assert.AreEqual("SUPPORT2", textures[sides[512].MiddleTexture].Name);
                Assert.IsTrue(sides[512].Sector == sectors[52]);

                Assert.AreEqual(0, sides[528].TextureOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[528].RowOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[528].TopTexture);
                Assert.AreEqual(0, sides[528].BottomTexture);
                Assert.AreEqual(0, sides[528].MiddleTexture);
                Assert.IsTrue(sides[528].Sector == sectors[11]);
            }
        }
Ejemplo n.º 15
0
        public void LoadE1M1()
        {
            using (var wad = new Wad(WadPath.Doom1))
            {
                var flats    = new FlatLookup(wad, true);
                var textures = new TextureLookup(wad, false);
                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);

                Assert.AreEqual(666, sides.Length);

                Assert.AreEqual(0, sides[0].TextureOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[0].RowOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[0].TopTexture);
                Assert.AreEqual(0, sides[0].BottomTexture);
                Assert.AreEqual("DOOR3", textures[sides[0].MiddleTexture].Name);
                Assert.IsTrue(sides[0].Sector == sectors[30]);

                Assert.AreEqual(32, sides[480].TextureOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[480].RowOffset.ToDouble(), delta);
                Assert.AreEqual("EXITSIGN", textures[sides[480].TopTexture].Name);
                Assert.AreEqual(0, sides[480].BottomTexture);
                Assert.AreEqual(0, sides[480].MiddleTexture);
                Assert.IsTrue(sides[480].Sector == sectors[70]);

                Assert.AreEqual(0, sides[650].TextureOffset.ToDouble(), delta);
                Assert.AreEqual(88, sides[650].RowOffset.ToDouble(), delta);
                Assert.AreEqual("STARTAN3", textures[sides[650].TopTexture].Name);
                Assert.AreEqual("STARTAN3", textures[sides[650].BottomTexture].Name);
                Assert.AreEqual(0, sides[650].MiddleTexture);
                Assert.IsTrue(sides[650].Sector == sectors[1]);

                Assert.AreEqual(0, sides[665].TextureOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[665].RowOffset.ToDouble(), delta);
                Assert.AreEqual(0, sides[665].TopTexture);
                Assert.AreEqual(0, sides[665].BottomTexture);
                Assert.AreEqual(0, sides[665].MiddleTexture);
                Assert.IsTrue(sides[665].Sector == sectors[23]);
            }
        }
Ejemplo n.º 16
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]));
            }
        }
Ejemplo n.º 17
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);
                var nodes      = Node.FromWad(wad, map + 7, subsectors);

                Assert.AreEqual(193, nodes.Length);

                Assert.AreEqual(64, nodes[0].X.ToDouble(), delta);
                Assert.AreEqual(1024, nodes[0].Y.ToDouble(), delta);
                Assert.AreEqual(0, nodes[0].Dx.ToDouble(), delta);
                Assert.AreEqual(-64, nodes[0].Dy.ToDouble(), delta);
                Assert.AreEqual(1173, nodes[0].Bbox[0][Box.Top].ToDouble(), delta);
                Assert.AreEqual(960, nodes[0].Bbox[0][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(-64, nodes[0].Bbox[0][Box.Left].ToDouble(), delta);
                Assert.AreEqual(64, nodes[0].Bbox[0][Box.Right].ToDouble(), delta);
                Assert.AreEqual(1280, nodes[0].Bbox[1][Box.Top].ToDouble(), delta);
                Assert.AreEqual(1024, nodes[0].Bbox[1][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(64, nodes[0].Bbox[1][Box.Left].ToDouble(), delta);
                Assert.AreEqual(128, nodes[0].Bbox[1][Box.Right].ToDouble(), delta);
                Assert.AreEqual(32770, nodes[0].Children[0] + 0x10000);
                Assert.AreEqual(32771, nodes[0].Children[1] + 0x10000);

                Assert.AreEqual(640, nodes[57].X.ToDouble(), delta);
                Assert.AreEqual(856, nodes[57].Y.ToDouble(), delta);
                Assert.AreEqual(-88, nodes[57].Dx.ToDouble(), delta);
                Assert.AreEqual(-16, nodes[57].Dy.ToDouble(), delta);
                Assert.AreEqual(856, nodes[57].Bbox[0][Box.Top].ToDouble(), delta);
                Assert.AreEqual(840, nodes[57].Bbox[0][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(552, nodes[57].Bbox[0][Box.Left].ToDouble(), delta);
                Assert.AreEqual(640, nodes[57].Bbox[0][Box.Right].ToDouble(), delta);
                Assert.AreEqual(856, nodes[57].Bbox[1][Box.Top].ToDouble(), delta);
                Assert.AreEqual(760, nodes[57].Bbox[1][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(536, nodes[57].Bbox[1][Box.Left].ToDouble(), delta);
                Assert.AreEqual(704, nodes[57].Bbox[1][Box.Right].ToDouble(), delta);
                Assert.AreEqual(32829, nodes[57].Children[0] + 0x10000);
                Assert.AreEqual(56, nodes[57].Children[1]);

                Assert.AreEqual(96, nodes[192].X.ToDouble(), delta);
                Assert.AreEqual(1280, nodes[192].Y.ToDouble(), delta);
                Assert.AreEqual(32, nodes[192].Dx.ToDouble(), delta);
                Assert.AreEqual(0, nodes[192].Dy.ToDouble(), delta);
                Assert.AreEqual(1280, nodes[192].Bbox[0][Box.Top].ToDouble(), delta);
                Assert.AreEqual(-960, nodes[192].Bbox[0][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(-1304, nodes[192].Bbox[0][Box.Left].ToDouble(), delta);
                Assert.AreEqual(2072, nodes[192].Bbox[0][Box.Right].ToDouble(), delta);
                Assert.AreEqual(2688, nodes[192].Bbox[1][Box.Top].ToDouble(), delta);
                Assert.AreEqual(1280, nodes[192].Bbox[1][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(-1304, nodes[192].Bbox[1][Box.Left].ToDouble(), delta);
                Assert.AreEqual(2072, nodes[192].Bbox[1][Box.Right].ToDouble(), delta);
                Assert.AreEqual(147, nodes[192].Children[0]);
                Assert.AreEqual(191, nodes[192].Children[1]);
            }
        }
Ejemplo n.º 18
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);
                var nodes      = Node.FromWad(wad, map + 7, subsectors);

                Assert.AreEqual(238, nodes.Length);

                Assert.AreEqual(1784, nodes[0].X.ToDouble(), delta);
                Assert.AreEqual(-3448, nodes[0].Y.ToDouble(), delta);
                Assert.AreEqual(-240, nodes[0].Dx.ToDouble(), delta);
                Assert.AreEqual(64, nodes[0].Dy.ToDouble(), delta);
                Assert.AreEqual(-3104, nodes[0].Bbox[0][Box.Top].ToDouble(), delta);
                Assert.AreEqual(-3448, nodes[0].Bbox[0][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(1520, nodes[0].Bbox[0][Box.Left].ToDouble(), delta);
                Assert.AreEqual(2128, nodes[0].Bbox[0][Box.Right].ToDouble(), delta);
                Assert.AreEqual(-3384, nodes[0].Bbox[1][Box.Top].ToDouble(), delta);
                Assert.AreEqual(-3448, nodes[0].Bbox[1][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(1544, nodes[0].Bbox[1][Box.Left].ToDouble(), delta);
                Assert.AreEqual(1784, nodes[0].Bbox[1][Box.Right].ToDouble(), delta);
                Assert.AreEqual(32768, nodes[0].Children[0] + 0x10000);
                Assert.AreEqual(32769, nodes[0].Children[1] + 0x10000);

                Assert.AreEqual(928, nodes[57].X.ToDouble(), delta);
                Assert.AreEqual(-3360, nodes[57].Y.ToDouble(), delta);
                Assert.AreEqual(0, nodes[57].Dx.ToDouble(), delta);
                Assert.AreEqual(256, nodes[57].Dy.ToDouble(), delta);
                Assert.AreEqual(-3104, nodes[57].Bbox[0][Box.Top].ToDouble(), delta);
                Assert.AreEqual(-3360, nodes[57].Bbox[0][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(928, nodes[57].Bbox[0][Box.Left].ToDouble(), delta);
                Assert.AreEqual(1344, nodes[57].Bbox[0][Box.Right].ToDouble(), delta);
                Assert.AreEqual(-3104, nodes[57].Bbox[1][Box.Top].ToDouble(), delta);
                Assert.AreEqual(-3360, nodes[57].Bbox[1][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(704, nodes[57].Bbox[1][Box.Left].ToDouble(), delta);
                Assert.AreEqual(928, nodes[57].Bbox[1][Box.Right].ToDouble(), delta);
                Assert.AreEqual(32825, nodes[57].Children[0] + 0x10000);
                Assert.AreEqual(56, nodes[57].Children[1]);

                Assert.AreEqual(2176, nodes[237].X.ToDouble(), delta);
                Assert.AreEqual(-2304, nodes[237].Y.ToDouble(), delta);
                Assert.AreEqual(0, nodes[237].Dx.ToDouble(), delta);
                Assert.AreEqual(-256, nodes[237].Dy.ToDouble(), delta);
                Assert.AreEqual(-2048, nodes[237].Bbox[0][Box.Top].ToDouble(), delta);
                Assert.AreEqual(-4064, nodes[237].Bbox[0][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(-768, nodes[237].Bbox[0][Box.Left].ToDouble(), delta);
                Assert.AreEqual(2176, nodes[237].Bbox[0][Box.Right].ToDouble(), delta);
                Assert.AreEqual(-2048, nodes[237].Bbox[1][Box.Top].ToDouble(), delta);
                Assert.AreEqual(-4864, nodes[237].Bbox[1][Box.Bottom].ToDouble(), delta);
                Assert.AreEqual(2176, nodes[237].Bbox[1][Box.Left].ToDouble(), delta);
                Assert.AreEqual(3808, nodes[237].Bbox[1][Box.Right].ToDouble(), delta);
                Assert.AreEqual(131, nodes[237].Children[0]);
                Assert.AreEqual(236, nodes[237].Children[1]);
            }
        }
Ejemplo n.º 19
0
        async Task Game()
        {
            Lump[] lumps;

            try
            {
                using (var iwad = File.Open(@"E:\Steam\steamapps\common\DOOM 3 BFG Edition\base\wads\DOOM2.WAD", FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    byte[] rec = new byte[16];
                    await iwad.ReadAsync(rec, 0, 12);

                    int num = BitConverter.ToInt32(rec, 4);
                    int ofs = BitConverter.ToInt32(rec, 8);
                    iwad.Seek((long)ofs, SeekOrigin.Begin);

                    // Read the lump table:
                    byte[] dir = new byte[16 * num];
                    await iwad.ReadAsync(dir, 0, 16 *num);

                    lumps = new Lump[num];
                    for (int i = 0; i < num; ++i)
                    {
                        // Read the lump data from the table:
                        int    position = BitConverter.ToInt32(dir, i * 16 + 0);
                        int    size     = BitConverter.ToInt32(dir, i * 16 + 4);
                        string name     = Encoding.ASCII.GetString(dir, i * 16 + 8, 8).TrimEnd(new char[] { '\0' });

                        byte[] data;
                        if (size > 0)
                        {
                            data = new byte[size];

                            iwad.Seek((long)position, SeekOrigin.Begin);
                            await iwad.ReadAsync(data, 0, size);
                        }
                        else
                        {
                            data = null;
                        }

                        // Record the lump and its data:
                        lumps[i] = new Lump(name, position, size, data);
                    }
                }

                int ml = FindLump(lumps, mapLumpName);

                // Find center of map:
                var minPos = new Vertex(Int16.MaxValue, Int16.MaxValue);
                var maxPos = new Vertex(Int16.MinValue, Int16.MinValue);

                // Read vertexes:
                var vertexesLump = lumps[ml + (int)MapLump.VERTEXES];
                int numVertexes  = vertexesLump.Size / (2 + 2);
                vertexes = new Vertex[numVertexes];
                for (int i = 0; i < numVertexes; ++i)
                {
                    short x = BitConverter.ToInt16(vertexesLump.Data, i * 2 * sizeof(Int16));
                    short y = BitConverter.ToInt16(vertexesLump.Data, i * 2 * sizeof(Int16) + sizeof(Int16));

                    if (x < minPos.X)
                    {
                        minPos = new Vertex(x, minPos.Y);
                    }
                    if (y < minPos.Y)
                    {
                        minPos = new Vertex(minPos.X, y);
                    }
                    if (x > maxPos.X)
                    {
                        maxPos = new Vertex(x, maxPos.Y);
                    }
                    if (y > maxPos.Y)
                    {
                        maxPos = new Vertex(maxPos.X, y);
                    }

                    vertexes[i] = new Vertex(x, y);
                }

                // Calculate center:
                int mapw   = (maxPos.X - minPos.X);
                int maph   = (maxPos.Y - minPos.Y);
                var center = new Vertex(mapw / 2 + minPos.X, maph / 2 + minPos.Y);
                MapCoordToVector3(new Vertex3(center, 64), out centerPos);

                cameraDistance = Math.Max(mapw, maph) / scale;
                cameraHeight   = cameraDistance * 0.8f;

                // Read sectors:
                var sectorsLump = lumps[ml + (int)MapLump.SECTORS];

                const int sectorSize = (sizeof(short) * 5) + (8 * 2);
                int       numSectors = sectorsLump.Size / sectorSize;

                sectors = new Sector[numSectors];
                for (int i = 0; i < numSectors; ++i)
                {
                    short  floorheight   = BitConverter.ToInt16(sectorsLump.Data, (i * sectorSize) + (sizeof(short) * 0));
                    short  ceilingheight = BitConverter.ToInt16(sectorsLump.Data, (i * sectorSize) + (sizeof(short) * 1));
                    string floorpic      = Encoding.ASCII.GetString(sectorsLump.Data, (i * sectorSize) + 0 + (sizeof(short) * 2), 8).ASCIIZ();
                    string ceilingpic    = Encoding.ASCII.GetString(sectorsLump.Data, (i * sectorSize) + 8 + (sizeof(short) * 2), 8).ASCIIZ();
                    short  lightlevel    = BitConverter.ToInt16(sectorsLump.Data, (i * sectorSize) + 16 + (sizeof(short) * 2));
                    short  special       = BitConverter.ToInt16(sectorsLump.Data, (i * sectorSize) + 16 + (sizeof(short) * 3));
                    short  tag           = BitConverter.ToInt16(sectorsLump.Data, (i * sectorSize) + 16 + (sizeof(short) * 4));

                    sectors[i] = new Sector(floorheight, ceilingheight, floorpic, ceilingpic, lightlevel, special, tag);
                }

                // Read sidedefs:
                var sidedefsLump = lumps[ml + (int)MapLump.SIDEDEFS];

                const int sidedefSize = (sizeof(short) * 3) + (8 * 3);
                int       numSidedefs = sidedefsLump.Size / sidedefSize;

                sidedefs = new SideDef[numSidedefs];
                for (int i = 0; i < numSidedefs; ++i)
                {
                    short  textureoffset = BitConverter.ToInt16(sidedefsLump.Data, (i * sidedefSize) + (sizeof(short) * 0));
                    short  rowoffset     = BitConverter.ToInt16(sidedefsLump.Data, (i * sidedefSize) + (sizeof(short) * 1));
                    string toptexture    = Encoding.ASCII.GetString(sidedefsLump.Data, (i * sidedefSize) + 0 + (sizeof(short) * 2), 8).ASCIIZ();
                    string bottomtexture = Encoding.ASCII.GetString(sidedefsLump.Data, (i * sidedefSize) + 8 + (sizeof(short) * 2), 8).ASCIIZ();
                    string midtexture    = Encoding.ASCII.GetString(sidedefsLump.Data, (i * sidedefSize) + 16 + (sizeof(short) * 2), 8).ASCIIZ();
                    // Front sector, towards viewer.
                    short sector = BitConverter.ToInt16(sidedefsLump.Data, (i * sidedefSize) + 24 + (sizeof(short) * 2));

                    sidedefs[i] = new SideDef(textureoffset, rowoffset, toptexture, bottomtexture, midtexture, sectors[sector]);
                }

                // Read linedefs:
                var linedefsLump = lumps[ml + (int)MapLump.LINEDEFS];

                const int linedefSize = sizeof(short) * 7;
                int       numLineDefs = linedefsLump.Size / linedefSize;

                linedefs = new LineDef[numLineDefs];

                var verts = new ListSet <Vertex3>(numVertexes * 4);
                var quads = new List <Quad>(numLineDefs * 3);
                for (int i = 0; i < numLineDefs; ++i)
                {
                    short v1       = BitConverter.ToInt16(linedefsLump.Data, (i * linedefSize) + (sizeof(short) * 0));
                    short v2       = BitConverter.ToInt16(linedefsLump.Data, (i * linedefSize) + (sizeof(short) * 1));
                    short flags    = BitConverter.ToInt16(linedefsLump.Data, (i * linedefSize) + (sizeof(short) * 2));
                    short special  = BitConverter.ToInt16(linedefsLump.Data, (i * linedefSize) + (sizeof(short) * 3));
                    short tag      = BitConverter.ToInt16(linedefsLump.Data, (i * linedefSize) + (sizeof(short) * 4));
                    short sidenum0 = BitConverter.ToInt16(linedefsLump.Data, (i * linedefSize) + (sizeof(short) * 5));
                    short sidenum1 = BitConverter.ToInt16(linedefsLump.Data, (i * linedefSize) + (sizeof(short) * 6));

                    // Look up SideDefs:
                    SideDef side0, side1;
                    if (sidenum0 >= 0)
                    {
                        side0 = sidedefs[sidenum0];

                        if (sidenum1 < 0)
                        {
                            // One-sided:
                            side1 = null;

                            quads.Add(new Quad(
                                          verts.AddReturnIndex(new Vertex3(vertexes[v1], side0.Sector.Floorheight)),
                                          verts.AddReturnIndex(new Vertex3(vertexes[v1], side0.Sector.Ceilingheight)),
                                          verts.AddReturnIndex(new Vertex3(vertexes[v2], side0.Sector.Ceilingheight)),
                                          verts.AddReturnIndex(new Vertex3(vertexes[v2], side0.Sector.Floorheight))
                                          ));
                        }
                        else
                        {
                            // Two-sided:
                            side1 = sidedefs[sidenum1];

                            if (side1.Sector.Floorheight < side0.Sector.Floorheight)
                            {
                                quads.Add(new Quad(
                                              verts.AddReturnIndex(new Vertex3(vertexes[v1], side0.Sector.Floorheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v1], side1.Sector.Floorheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v2], side1.Sector.Floorheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v2], side0.Sector.Floorheight))
                                              ));
                            }
                            else if (side1.Sector.Floorheight >= side0.Sector.Floorheight)
                            {
                                quads.Add(new Quad(
                                              verts.AddReturnIndex(new Vertex3(vertexes[v1], side0.Sector.Floorheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v1], side1.Sector.Floorheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v2], side1.Sector.Floorheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v2], side0.Sector.Floorheight))
                                              ));
                            }

                            if (side1.Sector.Ceilingheight < side0.Sector.Ceilingheight)
                            {
                                quads.Add(new Quad(
                                              verts.AddReturnIndex(new Vertex3(vertexes[v1], side1.Sector.Ceilingheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v1], side0.Sector.Ceilingheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v2], side0.Sector.Ceilingheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v2], side1.Sector.Ceilingheight))
                                              ));
                            }
                            else if (side1.Sector.Ceilingheight >= side0.Sector.Ceilingheight)
                            {
                                quads.Add(new Quad(
                                              verts.AddReturnIndex(new Vertex3(vertexes[v1], side0.Sector.Ceilingheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v1], side1.Sector.Ceilingheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v2], side1.Sector.Ceilingheight)),
                                              verts.AddReturnIndex(new Vertex3(vertexes[v2], side0.Sector.Ceilingheight))
                                              ));
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("FAIL");
                    }

                    linedefs[i] = new LineDef(v1, v2, flags, special, tag, side0, side1);
                }

                quadIndices = quads.ToArray();


                // Read segs:
                const int segSize = sizeof(short) * 6;

                var segsLump = lumps[ml + (int)MapLump.SEGS];
                int numSegs  = segsLump.Size / segSize;

                segs = new LineSeg[numSegs];
                for (int i = 0; i < numSegs; ++i)
                {
                    short v1      = BitConverter.ToInt16(segsLump.Data, (i * segSize) + (sizeof(short) * 0));
                    short v2      = BitConverter.ToInt16(segsLump.Data, (i * segSize) + (sizeof(short) * 1));
                    short angle   = BitConverter.ToInt16(segsLump.Data, (i * segSize) + (sizeof(short) * 2));
                    short linedef = BitConverter.ToInt16(segsLump.Data, (i * segSize) + (sizeof(short) * 3));
                    short side    = BitConverter.ToInt16(segsLump.Data, (i * segSize) + (sizeof(short) * 4));
                    short offset  = BitConverter.ToInt16(segsLump.Data, (i * segSize) + (sizeof(short) * 5));

                    var ldef = linedefs[linedef];
                    var sdef = ldef.Side0;
                    if (side != 0)
                    {
                        sdef = ldef.Side1;
                    }

                    segs[i] = new LineSeg(v1, v2, angle, ldef, sdef, offset);
                }

                // Read subsectors:
                const int subsectorSize = sizeof(short) * 2;

                var subsectorsLump = lumps[ml + (int)MapLump.SSECTORS];
                var numSubsectors  = subsectorsLump.Size / subsectorSize;

                subsectors = new SubSector[numSubsectors];
                for (int i = 0; i < numSubsectors; ++i)
                {
                    short numsegs  = BitConverter.ToInt16(subsectorsLump.Data, (i * subsectorSize) + (sizeof(short) * 0));
                    short firstseg = BitConverter.ToInt16(subsectorsLump.Data, (i * subsectorSize) + (sizeof(short) * 1));

                    // Pull out all the LineSegs for this subsector:
                    var mysegs = new LineSeg[numsegs];
                    Array.Copy(segs, firstseg, mysegs, 0, numsegs);
                    subsectors[i] = new SubSector(mysegs);

                    // Assert that all line segs in this subsector are in the same sector:
                    var sector = subsectors[i].Segs[0].Side.Sector;
                    Debug.Assert(subsectors[i].Segs.All(s => s.Side.Sector == sector));
                }


                // Build floor + ceil polygons from subsectors:
                var fPolys = new List <Polygon>(numSubsectors);
                var cPolys = new List <Polygon>(numSubsectors);

                int fIndices = 0, cIndices = 0;
                for (int i = 0; i < numSubsectors; ++i)
                {
                    var sg = subsectors[i].Segs;

                    List <int> flind = new List <int>(sg.Length * 2);
                    List <int> ceind = new List <int>(sg.Length * 2);

                    for (int j = 0; j < sg.Length; ++j)
                    {
                        var seg = sg[j];
                        if (seg.Side == seg.Line.Side0)
                        {
                            flind.Add(verts.AddReturnIndex(new Vertex3(vertexes[seg.V1], seg.Side.Sector.Floorheight)));
                            flind.Add(verts.AddReturnIndex(new Vertex3(vertexes[seg.V2], seg.Side.Sector.Floorheight)));
                            ceind.Add(verts.AddReturnIndex(new Vertex3(vertexes[seg.V1], seg.Side.Sector.Ceilingheight)));
                            ceind.Add(verts.AddReturnIndex(new Vertex3(vertexes[seg.V2], seg.Side.Sector.Ceilingheight)));
                        }
                        else
                        {
                            flind.Add(verts.AddReturnIndex(new Vertex3(vertexes[seg.V2], seg.Side.Sector.Floorheight)));
                            flind.Add(verts.AddReturnIndex(new Vertex3(vertexes[seg.V1], seg.Side.Sector.Floorheight)));
                            ceind.Add(verts.AddReturnIndex(new Vertex3(vertexes[seg.V2], seg.Side.Sector.Ceilingheight)));
                            ceind.Add(verts.AddReturnIndex(new Vertex3(vertexes[seg.V1], seg.Side.Sector.Ceilingheight)));
                        }
                    }

                    fPolys.Add(new Polygon(flind.ToArray(), fIndices));
                    fIndices += flind.Count;

                    cPolys.Add(new Polygon(ceind.ToArray(), cIndices));
                    cIndices += ceind.Count;
                }

                // Generate vectors and quad indices for OpenGL:
                quadVerts = new Vector3[verts.Count];
                for (int i = 0; i < verts.Count; ++i)
                {
                    MapCoordToVector3(verts[i], out quadVerts[i]);
                }

                floorPolys = fPolys.ToArray();
                ceilPolys  = cPolys.ToArray();

                // Read things:
                var       thingsLump = lumps[ml + (int)MapLump.THINGS];
                const int thingSize  = sizeof(short) * 5;

                int numThings = thingsLump.Size / thingSize;
                for (int i = 0; i < numThings; ++i)
                {
                    short x       = BitConverter.ToInt16(thingsLump.Data, (i * thingSize) + (sizeof(short) * 0));
                    short y       = BitConverter.ToInt16(thingsLump.Data, (i * thingSize) + (sizeof(short) * 1));
                    short angle   = BitConverter.ToInt16(thingsLump.Data, (i * thingSize) + (sizeof(short) * 2));
                    short type    = BitConverter.ToInt16(thingsLump.Data, (i * thingSize) + (sizeof(short) * 3));
                    short options = BitConverter.ToInt16(thingsLump.Data, (i * thingSize) + (sizeof(short) * 4));

#if false
                    // Player #1 start:
                    if (type == 1)
                    {
                        MapCoordToVector3(x, y, 0, out centerPos);
                    }
#endif
                }

                // Game loop:
                while (true)
                {
                    // Create a new Frame to update:
                    next = new Frame();

                    // Set up the frame state to render:
                    //next.bg = new Color4((float)rnd.NextDouble(), (float)rnd.NextDouble(), (float)rnd.NextDouble(), 1.0f);

                    // Set this as the next frame ready to be rendered:
                    Interlocked.Exchange(ref ready, next);
                    // Wait for the frame to be rendered:
                    rendered.WaitOne(16);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Exit();
                return;
            }
        }
Ejemplo n.º 20
0
 public virtual void CreateSideDef(SideDef side)
 {
 }
Ejemplo n.º 21
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 blockMap = BlockMap.FromWad(wad, map + 10, lines);

                {
                    var minX = vertices.Select(v => v.X.ToDouble()).Min();
                    var maxX = vertices.Select(v => v.X.ToDouble()).Max();
                    var minY = vertices.Select(v => v.Y.ToDouble()).Min();
                    var maxY = vertices.Select(v => v.Y.ToDouble()).Max();

                    Assert.AreEqual(blockMap.OriginX.ToDouble(), minX, 64);
                    Assert.AreEqual(blockMap.OriginY.ToDouble(), minY, 64);
                    Assert.AreEqual((blockMap.OriginX + BlockMap.MapBlockSize * blockMap.Width).ToDouble(), maxX, 128);
                    Assert.AreEqual((blockMap.OriginY + BlockMap.MapBlockSize * blockMap.Height).ToDouble(), maxY, 128);
                }

                var spots = new List <Tuple <int, int> >();
                for (var blockY = -2; blockY < blockMap.Height + 2; blockY++)
                {
                    for (var blockX = -2; blockX < blockMap.Width + 2; blockX++)
                    {
                        spots.Add(Tuple.Create(blockX, blockY));
                    }
                }

                var random = new Random(666);

                for (var i = 0; i < 50; i++)
                {
                    var ordered = spots.OrderBy(spot => random.NextDouble()).ToArray();

                    var total = 0;

                    foreach (var spot in ordered)
                    {
                        var blockX = spot.Item1;
                        var blockY = spot.Item2;

                        var minX  = double.MaxValue;
                        var maxX  = double.MinValue;
                        var minY  = double.MaxValue;
                        var maxY  = double.MinValue;
                        var count = 0;

                        blockMap.IterateLines(
                            blockX,
                            blockY,
                            line =>
                        {
                            if (count != 0)
                            {
                                minX = Math.Min(Math.Min(line.Vertex1.X.ToDouble(), line.Vertex2.X.ToDouble()), minX);
                                maxX = Math.Max(Math.Max(line.Vertex1.X.ToDouble(), line.Vertex2.X.ToDouble()), maxX);
                                minY = Math.Min(Math.Min(line.Vertex1.Y.ToDouble(), line.Vertex2.Y.ToDouble()), minY);
                                maxY = Math.Max(Math.Max(line.Vertex1.Y.ToDouble(), line.Vertex2.Y.ToDouble()), maxY);
                            }
                            count++;
                            return(true);
                        },
                            i + 1);

                        if (count > 1)
                        {
                            Assert.IsTrue(minX <= (blockMap.OriginX + BlockMap.MapBlockSize * (blockX + 1)).ToDouble());
                            Assert.IsTrue(maxX >= (blockMap.OriginX + BlockMap.MapBlockSize * blockX).ToDouble());
                            Assert.IsTrue(minY <= (blockMap.OriginY + BlockMap.MapBlockSize * (blockY + 1)).ToDouble());
                            Assert.IsTrue(maxY >= (blockMap.OriginY + BlockMap.MapBlockSize * blockY).ToDouble());
                        }

                        total += count;
                    }

                    Assert.AreEqual(lines.Length, total);
                }
            }
        }