Beispiel #1
0
        public static Subsector[] FromWad(string fileName, Seg[] segs)
        {
            var reader = new BinaryReader(DoomApplication.Instance.FileSystem.Read(fileName));
            var length = reader.BaseStream.Length;

            if (length % Subsector.dataSize != 0)
            {
                throw new Exception();
            }

            var data       = reader.ReadBytes((int)reader.BaseStream.Length);
            var count      = length / Subsector.dataSize;
            var subsectors = new Subsector[count];

            for (var i = 0; i < count; i++)
            {
                var offset = Subsector.dataSize * i;
                subsectors[i] = Subsector.FromData(data, offset, segs);
            }

            return(subsectors);
        }
Beispiel #2
0
        public Map(TextureLookup textures, FlatLookup 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 (DoomApplication.Instance.IWad == "doom2" ||
                    DoomApplication.Instance.IWad == "freedoom2" ||
                    DoomApplication.Instance.IWad == "plutonia" ||
                    DoomApplication.Instance.IWad == "tnt")
                {
                    name = "MAP" + options.Map.ToString("00");
                }
                else
                {
                    name = "E" + options.Episode + "M" + options.Map;
                }

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

                var map = $"MAPS/{name}/";

                if (!DoomApplication.Instance.FileSystem.Files().Any(file => file.StartsWith(map)))
                {
                    throw new Exception("Map '" + name + "' was not found!");
                }

                this.vertices   = Vertex.FromWad($"{map}VERTEXES");
                this.sectors    = Sector.FromWad($"{map}SECTORS", flats);
                this.sides      = SideDef.FromWad($"{map}SIDEDEFS", textures, this.sectors);
                this.lines      = LineDef.FromWad($"{map}LINEDEFS", this.vertices, this.sides);
                this.segs       = Seg.FromWad($"{map}SEGS", this.vertices, this.lines);
                this.subsectors = Subsector.FromWad($"{map}SSECTORS", this.segs);
                this.nodes      = Node.FromWad($"{map}NODES", this.subsectors);
                this.things     = MapThing.FromWad($"{map}THINGS");
                this.blockMap   = BlockMap.FromWad($"{map}BLOCKMAP", this.lines);
                this.reject     = Reject.FromWad($"{map}REJECT", this.sectors);

                this.GroupLines();

                this.skyTexture = this.GetSkyTextureByMapName(name);

                if (DoomApplication.Instance.IWad == "doom2" ||
                    DoomApplication.Instance.IWad == "freedoom2" ||
                    DoomApplication.Instance.IWad == "plutonia" ||
                    DoomApplication.Instance.IWad == "tnt")
                {
                    if (DoomApplication.Instance.IWad == "plutonia")
                    {
                        this.title = DoomInfo.MapTitles.Plutonia[options.Map - 1];
                    }
                    else if (DoomApplication.Instance.IWad == "tnt")
                    {
                        this.title = DoomInfo.MapTitles.Tnt[options.Map - 1];
                    }
                    else
                    {
                        this.title = DoomInfo.MapTitles.Doom2[options.Map - 1];
                    }
                }
                else
                {
                    this.title = DoomInfo.MapTitles.Doom[options.Episode - 1][options.Map - 1];
                }

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