Beispiel #1
0
        public static Seg[] FromWad(Wad wad, int lump, Vertex[] vertices, LineDef[] lines)
        {
            var length = wad.GetLumpSize(lump);

            if (length % Seg.DataSize != 0)
            {
                throw new Exception();
            }

            var data  = wad.ReadLump(lump);
            var count = length / Seg.DataSize;
            var segs  = new Seg[count];;

            for (var i = 0; i < count; i++)
            {
                var offset = Seg.DataSize * i;
                segs[i] = Seg.FromData(data, offset, vertices, lines);
            }

            return(segs);
        }
Beispiel #2
0
        public Map(Wad wad, TextureLookup textures, FlatLookup flats, World world)
        {
            this.textures = textures;
            this.flats    = flats;
            this.world    = world;

            var options = world.Options;

            string name;

            if (wad.Names.Contains("doom") || wad.Names.Contains("doom1"))
            {
                name = "E" + options.Episode + "M" + options.Map;
            }
            else
            {
                name = "MAP" + options.Map.ToString("00");
            }

            var map = wad.GetLumpNumber(name);

            vertices   = Vertex.FromWad(wad, map + 4);
            sectors    = Sector.FromWad(wad, map + 8, flats);
            sides      = SideDef.FromWad(wad, map + 3, textures, sectors);
            lines      = LineDef.FromWad(wad, map + 2, vertices, sides);
            segs       = Seg.FromWad(wad, map + 5, vertices, lines);
            subsectors = Subsector.FromWad(wad, map + 6, segs);
            nodes      = Node.FromWad(wad, map + 7, subsectors);
            things     = MapThing.FromWad(wad, map + 1);
            blockMap   = BlockMap.FromWad(wad, map + 10, lines);
            reject     = Reject.FromWad(wad, map + 9, sectors);

            GroupLines();

            skyTexture = GetSkyTextureByMapName(name);
        }
Beispiel #3
0
        /// <summary>
        /// Calculate on which side of the line the point is.
        /// </summary>
        /// <returns>
        /// 0 (front) or 1 (back).
        /// </returns>
        public static int PointOnSegSide(Fixed x, Fixed y, Seg line)
        {
            var lx = line.Vertex1.X;
            var ly = line.Vertex1.Y;

            var ldx = line.Vertex2.X - lx;
            var ldy = line.Vertex2.Y - ly;

            if (ldx == Fixed.Zero)
            {
                if (x <= lx)
                {
                    return(ldy > Fixed.Zero ? 1 : 0);
                }
                else
                {
                    return(ldy < Fixed.Zero ? 1 : 0);
                }
            }

            if (ldy == Fixed.Zero)
            {
                if (y <= ly)
                {
                    return(ldx < Fixed.Zero ? 1 : 0);
                }
                else
                {
                    return(ldx > Fixed.Zero ? 1 : 0);
                }
            }

            var dx = (x - lx);
            var dy = (y - ly);

            // Try to quickly decide by looking at sign bits.
            if (((ldy.Data ^ ldx.Data ^ dx.Data ^ dy.Data) & 0x80000000) != 0)
            {
                if (((ldy.Data ^ dx.Data) & 0x80000000) != 0)
                {
                    // Left is negative.
                    return(1);
                }
                else
                {
                    return(0);
                }
            }

            var left  = new Fixed(ldy.Data >> Fixed.FracBits) * dx;
            var right = dy * new Fixed(ldx.Data >> Fixed.FracBits);

            if (right < left)
            {
                // Front side.
                return(0);
            }
            else
            {
                // Back side.
                return(1);
            }
        }
Beispiel #4
0
        public Map(Wad wad, ITextureLookup textures, IFlatLookup flats, TextureAnimation animation, World world)
        {
            try
            {
                this.textures  = textures;
                this.flats     = flats;
                this.animation = animation;
                this.world     = world;

                var options = world.Options;

                string name;
                if (wad.GameMode == GameMode.Commercial)
                {
                    name = "MAP" + options.Map.ToString("00");
                }
                else
                {
                    name = "E" + options.Episode + "M" + options.Map;
                }

                Console.Write("Load map '" + name + "': ");

                var map = wad.GetLumpNumber(name);

                if (map == -1)
                {
                    throw new Exception("Map '" + name + "' was not found!");
                }

                vertices   = Vertex.FromWad(wad, map + 4);
                sectors    = Sector.FromWad(wad, map + 8, flats);
                sides      = SideDef.FromWad(wad, map + 3, textures, sectors);
                lines      = LineDef.FromWad(wad, map + 2, vertices, sides);
                segs       = Seg.FromWad(wad, map + 5, vertices, lines);
                subsectors = Subsector.FromWad(wad, map + 6, segs);
                nodes      = Node.FromWad(wad, map + 7, subsectors);
                things     = MapThing.FromWad(wad, map + 1);
                blockMap   = BlockMap.FromWad(wad, map + 10, lines);
                reject     = Reject.FromWad(wad, map + 9, sectors);

                GroupLines();

                skyTexture = GetSkyTextureByMapName(name);

                if (options.GameMode == GameMode.Commercial)
                {
                    switch (options.MissionPack)
                    {
                    case MissionPack.Plutonia:
                        title = DoomInfo.MapTitles.Plutonia[options.Map - 1];
                        break;

                    case MissionPack.Tnt:
                        title = DoomInfo.MapTitles.Tnt[options.Map - 1];
                        break;

                    default:
                        title = DoomInfo.MapTitles.Doom2[options.Map - 1];
                        break;
                    }
                }
                else
                {
                    title = DoomInfo.MapTitles.Doom[options.Episode - 1][options.Map - 1];
                }

                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }