Ejemplo n.º 1
0
        public DummyFlatLookup(Wad wad)
        {
            var firstFlat = wad.GetLumpNumber("F_START") + 1;
            var lastFlat  = wad.GetLumpNumber("F_END") - 1;
            var count     = lastFlat - firstFlat + 1;

            flats = new Flat[count];

            nameToFlat   = new Dictionary <string, Flat>();
            nameToNumber = new Dictionary <string, int>();

            for (var lump = firstFlat; lump <= lastFlat; lump++)
            {
                if (wad.GetLumpSize(lump) != 4096)
                {
                    continue;
                }

                var number = lump - firstFlat;
                var name   = wad.LumpInfos[lump].Name;
                var flat   = name != "F_SKY1" ? DummyData.GetFlat() : DummyData.GetSkyFlat();

                flats[number]      = flat;
                nameToFlat[name]   = flat;
                nameToNumber[name] = number;
            }

            skyFlatNumber = nameToNumber["F_SKY1"];
            skyFlat       = nameToFlat["F_SKY1"];
        }
Ejemplo n.º 2
0
        private void InitDummy(Wad wad)
        {
            textures      = new List <Texture>();
            nameToTexture = new Dictionary <string, Texture>();
            nameToNumber  = new Dictionary <string, int>();

            for (var n = 1; n <= 2; n++)
            {
                var lumpNumber = wad.GetLumpNumber("TEXTURE" + n);
                if (lumpNumber == -1)
                {
                    break;
                }

                var data  = wad.ReadLump(lumpNumber);
                var count = BitConverter.ToInt32(data, 0);
                for (var i = 0; i < count; i++)
                {
                    var offset  = BitConverter.ToInt32(data, 4 + 4 * i);
                    var name    = Texture.GetName(data, offset);
                    var height  = Texture.GetHeight(data, offset);
                    var texture = Dummy.GetTexture(height);
                    nameToNumber.Add(name, textures.Count);
                    textures.Add(texture);
                    nameToTexture.Add(name, texture);
                }
            }
        }
Ejemplo n.º 3
0
        private void Init(Wad wad)
        {
            textures      = new List <Texture>();
            nameToTexture = new Dictionary <string, Texture>();
            nameToNumber  = new Dictionary <string, int>();

            var patches = LoadPatches(wad);

            for (var n = 1; n <= 2; n++)
            {
                var lumpNumber = wad.GetLumpNumber("TEXTURE" + n);
                if (lumpNumber == -1)
                {
                    break;
                }

                var data  = wad.ReadLump(lumpNumber);
                var count = BitConverter.ToInt32(data, 0);
                for (var i = 0; i < count; i++)
                {
                    var offset  = BitConverter.ToInt32(data, 4 + 4 * i);
                    var texture = Texture.FromData(data, offset, patches);
                    nameToNumber.Add(texture.Name, textures.Count);
                    textures.Add(texture);
                    nameToTexture.Add(texture.Name, texture);
                }
            }
        }
Ejemplo n.º 4
0
        public SfmlAudio(Wad wad)
        {
            buffers    = new SoundBuffer[DoomInfo.SfxNames.Length];
            amplitudes = new short[DoomInfo.SfxNames.Length];
            for (var i = 0; i < DoomInfo.SfxNames.Length; i++)
            {
                var lump = wad.GetLumpNumber("DS" + DoomInfo.SfxNames[i]);

                if (lump == -1)
                {
                    continue;
                }

                var data = wad.ReadLump(lump);

                var sampleRate  = BitConverter.ToUInt16(data, 2);
                var sampleCount = BitConverter.ToInt32(data, 4) - 32;
                var samples     = new short[sampleCount];
                for (var t = 0; t < samples.Length; t++)
                {
                    samples[t] = (short)((data[24 + t] - 128) << 8);
                }

                buffers[i] = new SoundBuffer(samples, 1, sampleRate);

                short max = 0;
                if (sampleCount > 0)
                {
                    var count = Math.Min(sampleRate / 5, sampleCount);
                    for (var t = 0; t < count; t++)
                    {
                        var a = samples[t];
                        if (a == short.MinValue)
                        {
                            max = short.MaxValue;
                            break;
                        }
                        if (a < 0)
                        {
                            a = (short)(-a);
                        }
                        if (a > max)
                        {
                            max = a;
                        }
                    }
                }
                amplitudes[i] = max;
            }

            channels   = new Sound[channelCount];
            sources    = new Mobj[channelCount];
            priorities = new float[channelCount];
            for (var i = 0; i < channels.Length; i++)
            {
                channels[i] = new Sound();
            }
        }
Ejemplo n.º 5
0
        private void InitStandard(Wad wad)
        {
            try
            {
                Console.Write("Load flats: ");

                var firstFlat = wad.GetLumpNumber("F_START") + 1;
                var lastFlat  = wad.GetLumpNumber("F_END") - 1;
                var count     = lastFlat - firstFlat + 1;

                flats = new Flat[count];

                nameToFlat   = new Dictionary <string, Flat>();
                nameToNumber = new Dictionary <string, int>();

                for (var lump = firstFlat; lump <= lastFlat; lump++)
                {
                    if (wad.GetLumpSize(lump) != 4096 && wad.GetLumpSize(lump) != 4)
                    {
                        continue;
                    }

                    var number = lump - firstFlat;
                    var name   = wad.LumpInfos[lump].Name;
                    var flat   = new Flat(name, wad.ReadLump(lump));

                    flats[number]      = flat;
                    nameToFlat[name]   = flat;
                    nameToNumber[name] = number;
                }

                skyFlatNumber = nameToNumber["F_SKY1"];
                skyFlat       = nameToFlat["F_SKY1"];

                Console.WriteLine("OK (" + nameToFlat.Count + " flats)");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }
Ejemplo n.º 6
0
        private static Patch[] LoadPatches(Wad wad)
        {
            var patchNames = LoadPatchNames(wad);
            var patches    = new Patch[patchNames.Length];

            for (var i = 0; i < patches.Length; i++)
            {
                var name = patchNames[i];

                // This check is necessary to avoid crash in DOOM1.WAD.
                if (wad.GetLumpNumber(name) == -1)
                {
                    continue;
                }

                var data = wad.ReadLump(name);
                patches[i] = Patch.FromData(name, data);
            }
            return(patches);
        }
Ejemplo n.º 7
0
        private void Init(Wad wad)
        {
            try
            {
                Console.Write("Load textures: ");

                textures      = new List <Texture>();
                nameToTexture = new Dictionary <string, Texture>();
                nameToNumber  = new Dictionary <string, int>();

                var patches = LoadPatches(wad);

                for (var n = 1; n <= 2; n++)
                {
                    var lumpNumber = wad.GetLumpNumber("TEXTURE" + n);
                    if (lumpNumber == -1)
                    {
                        break;
                    }

                    var data  = wad.ReadLump(lumpNumber);
                    var count = BitConverter.ToInt32(data, 0);
                    for (var i = 0; i < count; i++)
                    {
                        var offset  = BitConverter.ToInt32(data, 4 + 4 * i);
                        var texture = Texture.FromData(data, offset, patches);
                        nameToNumber.TryAdd(texture.Name, textures.Count);
                        textures.Add(texture);
                        nameToTexture.TryAdd(texture.Name, texture);
                    }
                }

                Console.WriteLine("OK (" + textures.Count + " textures)");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public static void ReadDeHackEdLump(Wad wad)
        {
            var lump = wad.GetLumpNumber("DEHACKED");

            if (lump != -1)
            {
                // Ensure the static members are initialized.
                DoomInfo.Strings.PRESSKEY.GetHashCode();

                try
                {
                    Console.Write("Load DeHackEd patch from WAD: ");

                    ProcessLines(ReadLines(wad.ReadLump(lump)));

                    Console.WriteLine("OK");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed");
                    throw new Exception("Failed to apply DeHackEd patch!", e);
                }
            }
        }
Ejemplo n.º 10
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);
            }
        }