Esempio n. 1
0
        public TextureAnimation(TextureLookup textures, FlatLookup flats)
        {
            try
            {
                Console.Write("Load texture animation info: ");

                var list = new List <TextureAnimationInfo>();

                foreach (var animDef in DoomInfo.TextureAnimation)
                {
                    int picNum;
                    int basePic;

                    if (animDef.IsTexture)
                    {
                        if (textures.GetNumber(animDef.StartName) == -1)
                        {
                            continue;
                        }

                        picNum  = textures.GetNumber(animDef.EndName);
                        basePic = textures.GetNumber(animDef.StartName);
                    }
                    else
                    {
                        if (flats.GetNumber(animDef.StartName) == -1)
                        {
                            continue;
                        }

                        picNum  = flats.GetNumber(animDef.EndName);
                        basePic = flats.GetNumber(animDef.StartName);
                    }

                    var anim = new TextureAnimationInfo(animDef.IsTexture, picNum, basePic, picNum - basePic + 1, animDef.Speed);

                    if (anim.NumPics < 2)
                    {
                        throw new Exception("Bad animation cycle from " + animDef.StartName + " to " + animDef.EndName + "!");
                    }

                    list.Add(anim);
                }

                this.animations = list.ToArray();

                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }
Esempio n. 2
0
        private void Init()
        {
            try
            {
                Console.Write("Load textures: ");

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

                var patches = TextureLookup.LoadPatches();

                for (var n = 1; n <= 2; n++)
                {
                    var name = "TEXTURE" + n;

                    if (!DoomApplication.Instance.FileSystem.Exists(name))
                    {
                        break;
                    }

                    var reader = new BinaryReader(DoomApplication.Instance.FileSystem.Read(name));

                    var data = reader.ReadBytes((int)reader.BaseStream.Length);
                    reader.BaseStream.Position = 0;

                    var count = reader.ReadInt32();

                    for (var i = 0; i < count; i++)
                    {
                        var offset  = reader.ReadInt32();
                        var texture = Texture.FromData(data, offset, patches);
                        this.nameToNumber.Add(texture.Name, this.textures.Count);
                        this.textures.Add(texture);
                        this.nameToTexture.Add(texture.Name, texture);
                    }
                }

                Console.WriteLine("OK (" + this.nameToTexture.Count + " textures)");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }
Esempio n. 3
0
        private static Patch[] LoadPatches()
        {
            var patchNames = TextureLookup.LoadPatchNames();
            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 (!DoomApplication.Instance.FileSystem.Exists(name))
                {
                    if (name == "TFOGF0" || name == "TFOGI0")                     // TNT.WAD uses this sprites as patches...
                    {
                        name = $"SPRITES/{name}";
                    }
                    else if (name == "BOSFA0")                     // PLUTONIA.WAD uses this sprite as patch...
                    {
                        name = $"SPRITES/{name}";
                    }
                    else
                    {
                        name = $"PATCHES/{name}";
                    }

                    if (!DoomApplication.Instance.FileSystem.Exists(name))
                    {
                        continue;
                    }
                }

                var reader = new BinaryReader(DoomApplication.Instance.FileSystem.Read(name));
                patches[i] = Patch.FromData(name, reader.ReadBytes((int)reader.BaseStream.Length));
            }

            return(patches);
        }