Ejemplo n.º 1
0
        public ColorMap(Wad wad)
        {
            try
            {
                Console.Write("Load color map: ");

                var raw = wad.ReadLump("COLORMAP");
                var num = raw.Length / 256;
                data = new byte[num][];
                for (var i = 0; i < num; i++)
                {
                    data[i] = new byte[256];
                    var offset = 256 * i;
                    for (var c = 0; c < 256; c++)
                    {
                        data[i][c] = raw[offset + c];
                    }
                }

                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }
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
        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.º 4
0
        private static IEnumerable <int> EnumerateSprites(Wad wad)
        {
            var spriteSection = false;

            for (var lump = wad.LumpInfos.Count - 1; lump >= 0; lump--)
            {
                var name = wad.LumpInfos[lump].Name;

                if (name.StartsWith("S"))
                {
                    if (name.EndsWith("_END"))
                    {
                        spriteSection = true;
                        continue;
                    }
                    else if (name.EndsWith("_START"))
                    {
                        spriteSection = false;
                        continue;
                    }
                }

                if (spriteSection)
                {
                    if (wad.LumpInfos[lump].Size > 0)
                    {
                        yield return(lump);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static BlockMap FromWad(Wad wad, int lump, LineDef[] lines)
        {
            var data = wad.ReadLump(lump);

            var table = new short[data.Length / 2];

            for (var i = 0; i < table.Length; i++)
            {
                var offset = 2 * i;
                table[i] = BitConverter.ToInt16(data, offset);
            }

            var originX = Fixed.FromInt(table[0]);
            var originY = Fixed.FromInt(table[1]);
            var width   = table[2];
            var height  = table[3];

            return(new BlockMap(
                       originX,
                       originY,
                       width,
                       height,
                       table,
                       lines));
        }
Ejemplo n.º 6
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.º 7
0
 public void Dispose()
 {
     if (wad != null)
     {
         wad.Dispose();
         wad = null;
     }
 }
Ejemplo n.º 8
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.º 9
0
 public static Patch FromWad(Wad wad, string name)
 {
     //* test for fullscreen graphics
     if (name == "TITLE")
     {
         return(FromDataRaw(name, wad.ReadLump(name)));
     }
     return(FromData(name, wad.ReadLump(name)));
 }
Ejemplo n.º 10
0
        public void Dispose()
        {
            if (wad != null)
            {
                wad.Dispose();
                wad = null;
            }

            Console.WriteLine("Wad files are disposed.");
        }
Ejemplo n.º 11
0
 public GameContent(string[] wadPaths)
 {
     wad       = new Wad(wadPaths);
     palette   = new Palette(wad);
     colorMap  = new ColorMap(wad);
     textures  = new TextureLookup(wad);
     flats     = new FlatLookup(wad);
     sprites   = new SpriteLookup(wad);
     animation = new TextureAnimation(textures, flats);
 }
Ejemplo n.º 12
0
        private static Patch CachedRead(int lump, Wad wad, Dictionary <int, Patch> cache)
        {
            if (!cache.ContainsKey(lump))
            {
                var name = wad.LumpInfos[lump].Name;
                cache.Add(lump, Patch.FromData(name, wad.ReadLump(lump)));
            }

            return(cache[lump]);
        }
Ejemplo n.º 13
0
        private static string[] LoadPatchNames(Wad wad)
        {
            var data  = wad.ReadLump("PNAMES");
            var count = BitConverter.ToInt32(data, 0);
            var names = new string[count];

            for (var i = 0; i < names.Length; i++)
            {
                names[i] = DoomInterop.ToString(data, 4 + 8 * i, 8);
            }
            return(names);
        }
Ejemplo n.º 14
0
        private static int CountLump(Wad wad, string name)
        {
            var count = 0;

            foreach (var lump in wad.LumpInfos)
            {
                if (lump.Name == name)
                {
                    count++;
                }
            }
            return(count);
        }
Ejemplo n.º 15
0
        public TextureLookup(Wad wad, bool useDummy)
        {
            if (!useDummy)
            {
                Init(wad);
            }
            else
            {
                InitDummy(wad);
            }

            InitSwitchList();
        }
Ejemplo n.º 16
0
        public static SfmlMusic GetSfmlMusicInstance(Config config, Wad wad)
        {
            var sfPath = Path.Combine(GetExeDirectory(), "TimGM6mb.sf2");

            if (File.Exists(sfPath))
            {
                return(new SfmlMusic(config, wad, sfPath));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 17
0
        public static SfmlMusic GetSfmlMusicInstance(Config config, Wad wad)
        {
            var sfPath = Path.Combine(GetExeDirectory(), config.audio_soundfont);

            if (File.Exists(sfPath))
            {
                return(new SfmlMusic(config, wad, sfPath));
            }
            else
            {
                Console.WriteLine("SoundFont '" + config.audio_soundfont + "' was not found!");
                return(null);
            }
        }
Ejemplo n.º 18
0
        public static SfmlMusic GetSfmlMusicInstance(Config config, Wad wad)
        {
            return(null);
            // TODO: load music

            /*var sfPath = Path.Combine(GetExeDirectory(), "TimGM6mb.sf2");
             * if (File.Exists(sfPath))
             * {
             *  return new SfmlMusic(config, wad, sfPath);
             * }
             * else
             * {
             *  return null;
             * }*/
        }
Ejemplo n.º 19
0
        public FlatLookup(Wad wad, bool useDummy)
        {
            flats        = new List <Flat>();
            nameToFlat   = new Dictionary <string, Flat>();
            nameToNumber = new Dictionary <string, int>();

            if (!useDummy)
            {
                Init(wad);
            }
            else
            {
                InitDummy(wad);
            }
        }
Ejemplo n.º 20
0
 public CommonResource(params string[] wadPaths)
 {
     try
     {
         wad      = new Wad(wadPaths);
         palette  = new Palette(wad);
         colorMap = new ColorMap(wad);
         textures = new TextureLookup(wad);
         flats    = new FlatLookup(wad);
         sprites  = new SpriteLookup(wad);
     }
     catch (Exception e)
     {
         ExceptionDispatchInfo.Capture(e).Throw();
     }
 }
Ejemplo n.º 21
0
        public ColorMap(Wad wad)
        {
            var raw = wad.ReadLump("COLORMAP");
            var num = raw.Length / 256;

            data = new byte[num][];
            for (var i = 0; i < num; i++)
            {
                data[i] = new byte[256];
                var offset = 256 * i;
                for (var c = 0; c < 256; c++)
                {
                    data[i][c] = raw[offset + c];
                }
            }
        }
Ejemplo n.º 22
0
        public FlatLookup(Wad wad, bool useDummy)
        {
            if (!useDummy)
            {
                var fStartCount  = CountLump(wad, "F_START");
                var fEndCount    = CountLump(wad, "F_END");
                var ffStartCount = CountLump(wad, "FF_START");
                var ffEndCount   = CountLump(wad, "FF_END");

                // Usual case.
                var standard =
                    fStartCount == 1 &&
                    fEndCount == 1 &&
                    ffStartCount == 0 &&
                    ffEndCount == 0;

                // A trick to add custom flats is used.
                // https://www.doomworld.com/tutorials/fx2.php
                var customFlatTrick =
                    fStartCount == 1 &&
                    fEndCount >= 2;

                // Need deutex to add flats.
                var deutexMerge =
                    fStartCount + ffStartCount >= 2 &&
                    fEndCount + ffEndCount >= 2;

                if (standard || customFlatTrick)
                {
                    InitStandard(wad);
                }
                else if (deutexMerge)
                {
                    InitDeuTexMerge(wad);
                }
                else
                {
                    throw new Exception("Faild to read flats.");
                }
            }
            else
            {
                InitDummy(wad);
            }
        }
Ejemplo n.º 23
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.º 24
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.º 25
0
        public static Sector[] FromWad(Wad wad, int lump, FlatLookup flats)
        {
            var length = wad.GetLumpSize(lump);

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

            var data    = wad.ReadLump(lump);
            var count   = length / dataSize;
            var sectors = new Sector[count];;

            for (var i = 0; i < count; i++)
            {
                var offset = dataSize * i;
                sectors[i] = FromData(data, offset, i, flats);
            }

            return(sectors);
        }
Ejemplo n.º 26
0
        public static SideDef[] FromWad(Wad wad, int lump, TextureLookup textures, Sector[] sectors)
        {
            var length = wad.GetLumpSize(lump);

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

            var data  = wad.ReadLump(lump);
            var count = length / dataSize;
            var sides = new SideDef[count];;

            for (var i = 0; i < count; i++)
            {
                var offset = dataSize * i;
                sides[i] = FromData(data, offset, textures, sectors);
            }

            return(sides);
        }
Ejemplo n.º 27
0
        public static LineDef[] FromWad(Wad wad, int lump, Vertex[] vertices, SideDef[] sides)
        {
            var length = wad.GetLumpSize(lump);

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

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

            for (var i = 0; i < count; i++)
            {
                var offset = 14 * i;
                lines[i] = FromData(data, offset, vertices, sides);
            }

            return(lines);
        }
Ejemplo n.º 28
0
        public static MapThing[] FromWad(Wad wad, int lump)
        {
            var length = wad.GetLumpSize(lump);

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

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

            for (var i = 0; i < count; i++)
            {
                var offset = DataSize * i;
                things[i] = FromData(data, offset);
            }

            return(things);
        }
Ejemplo n.º 29
0
        private void InitDummy(Wad wad)
        {
            foreach (var lump in EnumerateFlats(wad))
            {
                var name = wad.LumpInfos[lump].Name;

                if (nameToFlat.ContainsKey(name))
                {
                    continue;
                }

                var flat = name != "F_SKY1" ? Dummy.GetFlat() : Dummy.GetSkyFlat();

                nameToNumber.Add(name, flats.Count);
                flats.Add(flat);
                nameToFlat.Add(name, flat);
            }

            skyFlatNumber = nameToNumber["F_SKY1"];
            skyFlat       = nameToFlat["F_SKY1"];
        }
Ejemplo n.º 30
0
        public static Subsector[] FromWad(Wad wad, int lump, Seg[] segs)
        {
            var length = wad.GetLumpSize(lump);

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

            var data       = wad.ReadLump(lump);
            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);
        }