예제 #1
0
        public SpriteLookup(Wad wad, bool useDummy)
        {
            try
            {
                Console.Write("Load sprites: ");

                var temp = new Dictionary <string, List <SpriteInfo> >();
                for (var i = 0; i < (int)Sprite.Count; i++)
                {
                    temp.Add(DoomInfo.SpriteNames[i], new List <SpriteInfo>());
                }

                var cache = new Dictionary <int, Patch>();

                foreach (var lump in EnumerateSprites(wad))
                {
                    var name = wad.LumpInfos[lump].Name.Substring(0, 4);

                    if (!temp.ContainsKey(name))
                    {
                        continue;
                    }

                    var list = temp[name];

                    {
                        var frame    = wad.LumpInfos[lump].Name[4] - 'A';
                        var rotation = wad.LumpInfos[lump].Name[5] - '0';

                        while (list.Count < frame + 1)
                        {
                            list.Add(new SpriteInfo());
                        }

                        if (rotation == 0)
                        {
                            for (var i = 0; i < 8; i++)
                            {
                                if (list[frame].Patches[i] == null)
                                {
                                    list[frame].Patches[i] = CachedRead(lump, wad, cache, useDummy);
                                    list[frame].Flip[i]    = false;
                                }
                            }
                        }
                        else
                        {
                            if (list[frame].Patches[rotation - 1] == null)
                            {
                                list[frame].Patches[rotation - 1] = CachedRead(lump, wad, cache, useDummy);
                                list[frame].Flip[rotation - 1]    = false;
                            }
                        }
                    }

                    if (wad.LumpInfos[lump].Name.Length == 8)
                    {
                        var frame    = wad.LumpInfos[lump].Name[6] - 'A';
                        var rotation = wad.LumpInfos[lump].Name[7] - '0';

                        while (list.Count < frame + 1)
                        {
                            list.Add(new SpriteInfo());
                        }

                        if (rotation == 0)
                        {
                            for (var i = 0; i < 8; i++)
                            {
                                if (list[frame].Patches[i] == null)
                                {
                                    list[frame].Patches[i] = CachedRead(lump, wad, cache, useDummy);
                                    list[frame].Flip[i]    = true;
                                }
                            }
                        }
                        else
                        {
                            if (list[frame].Patches[rotation - 1] == null)
                            {
                                list[frame].Patches[rotation - 1] = CachedRead(lump, wad, cache, useDummy);
                                list[frame].Flip[rotation - 1]    = true;
                            }
                        }
                    }
                }

                spriteDefs = new SpriteDef[(int)Sprite.Count];
                for (var i = 0; i < spriteDefs.Length; i++)
                {
                    var list = temp[DoomInfo.SpriteNames[i]];

                    var frames = new SpriteFrame[list.Count];
                    for (var j = 0; j < frames.Length; j++)
                    {
                        list[j].CheckCompletion();

                        var frame = new SpriteFrame(list[j].HasRotation(), list[j].Patches, list[j].Flip);
                        frames[j] = frame;
                    }

                    spriteDefs[i] = new SpriteDef(frames);
                }

                Console.WriteLine("OK (" + cache.Count + " sprites)");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }
예제 #2
0
        public DummySpriteLookup(Wad wad)
        {
            var temp = new Dictionary <string, List <SpriteInfo> >();

            for (var i = 0; i < (int)Sprite.Count; i++)
            {
                temp.Add(DoomInfo.SpriteNames[i], new List <SpriteInfo>());
            }

            var cache = new Dictionary <int, Patch>();

            foreach (var lump in EnumerateSprites(wad))
            {
                var name = wad.LumpInfos[lump].Name.Substring(0, 4);

                if (!temp.ContainsKey(name))
                {
                    continue;
                }

                var list = temp[name];

                {
                    var frame    = wad.LumpInfos[lump].Name[4] - 'A';
                    var rotation = wad.LumpInfos[lump].Name[5] - '0';

                    while (list.Count < frame + 1)
                    {
                        list.Add(new SpriteInfo());
                    }

                    if (rotation == 0)
                    {
                        for (var i = 0; i < 8; i++)
                        {
                            if (list[frame].Patches[i] == null)
                            {
                                list[frame].Patches[i] = DummyData.GetPatch();
                                list[frame].Flip[i]    = false;
                            }
                        }
                    }
                    else
                    {
                        if (list[frame].Patches[rotation - 1] == null)
                        {
                            list[frame].Patches[rotation - 1] = DummyData.GetPatch();
                            list[frame].Flip[rotation - 1]    = false;
                        }
                    }
                }

                if (wad.LumpInfos[lump].Name.Length == 8)
                {
                    var frame    = wad.LumpInfos[lump].Name[6] - 'A';
                    var rotation = wad.LumpInfos[lump].Name[7] - '0';

                    while (list.Count < frame + 1)
                    {
                        list.Add(new SpriteInfo());
                    }

                    if (rotation == 0)
                    {
                        for (var i = 0; i < 8; i++)
                        {
                            if (list[frame].Patches[i] == null)
                            {
                                list[frame].Patches[i] = DummyData.GetPatch();
                                list[frame].Flip[i]    = true;
                            }
                        }
                    }
                    else
                    {
                        if (list[frame].Patches[rotation - 1] == null)
                        {
                            list[frame].Patches[rotation - 1] = DummyData.GetPatch();
                            list[frame].Flip[rotation - 1]    = true;
                        }
                    }
                }
            }

            spriteDefs = new SpriteDef[(int)Sprite.Count];
            for (var i = 0; i < spriteDefs.Length; i++)
            {
                var list = temp[DoomInfo.SpriteNames[i]];

                var frames = new SpriteFrame[list.Count];
                for (var j = 0; j < frames.Length; j++)
                {
                    list[j].CheckCompletion();

                    var frame = new SpriteFrame(list[j].HasRotation(), list[j].Patches, list[j].Flip);
                    frames[j] = frame;
                }

                spriteDefs[i] = new SpriteDef(frames);
            }
        }