Exemplo n.º 1
0
        public static Texture2D BuildPatch(string name, WadFile wad, bool ignoreCache = false, bool trueColor = false)
        {
            if (!wad.Contains(name.ToUpper()))
            {
                return(null);
            }

            if (patchCache == null)
            {
                patchCache = new Dictionary <string, Texture2D>();
            }

            if (!ignoreCache)
            {
                if (patchCache.ContainsKey(name))
                {
                    return(patchCache[name]);
                }
            }

            Texture2D output = new DoomGraphic(wad.GetLump(name.ToUpper())).ToRenderMap();

            if (trueColor)
            {
                output = new DoomGraphic(wad.GetLump(name.ToUpper())).ToTexture2D(new Palette(wad.GetLump("PLAYPAL")));
            }

            if (!ignoreCache)
            {
                patchCache.Add(name, output);
            }

            return(output);
        }
Exemplo n.º 2
0
        public static Dictionary <string, Material> BuildFlatMaterials(WadFile wad, string[] flats)
        {
            if (paletteLookup == null)
            {
                Init(wad);
            }

            Dictionary <string, Material> output = new Dictionary <string, Material>();

            for (int i = 0; i < flats.Length; i++)
            {
                if (wad.Contains(flats[i]))
                {
                    DoomFlat flat     = new DoomFlat(wad.GetLump(flats[i]));
                    Material material = new Material(Shader.Find("Doom/Flat"));
                    material.SetTexture("_MainTex", flat.ToRenderMap());
                    material.SetTexture("_Palette", paletteLookup);
                    material.SetTexture("_Colormap", colormapLookup);
                    material.enableInstancing = true;
                    output.Add(flats[i].ToUpper(), material);
                }
            }
            return(output);
        }
Exemplo n.º 3
0
        public static MapData Load(WadFile wad, string mapname)
        {
            byte[]  maplump = wad.GetLump(mapname);
            MapData map     = null;

            // Detect map type and treat accordingly
            // First see if the lump is a wad.
            if (maplump.Length != 0)
            {
                if (new string(Encoding.ASCII.GetChars(maplump, 0, 4)) == "PWAD")
                {
                    // Ok! we have a wad representing a map, so we need to dive into it.
                    WadFile mapWad = new WadFile(maplump);
                    if (mapWad.directory[1].name == "THINGS")                       // not a udmf, either Doom or Hexen
                    {
                        if (mapWad.Contains("BEHAVIOR"))
                        {
                            // Hexen
                            throw new Exception("Unsupported map format: Hexen");
                        }
                        else
                        {
                            map = new DoomMapData(mapWad, mapWad.directory[0].name);
                        }
                    }
                    else if (mapWad.directory[1].name == "TEXTMAP")
                    {
                        map = new UDMFMapData(mapWad.GetLumpAsText("TEXTMAP"));
                    }
                    else
                    {
                        throw new Exception("Unknown map format");
                    }
                }
            }
            else
            {
                int mapIndex = wad.GetIndex(mapname);
                if (wad.directory[mapIndex + 1].name == "THINGS")
                {
                    if (wad.directory.Count > mapIndex + 11 && wad.directory[mapIndex + 11].name == "BEHAVIOR")
                    {
                        throw new Exception("Unsupported map format: Hexen");
                    }
                    else
                    {
                        map = new DoomMapData(wad, mapname);
                    }
                }
                else if (wad.directory[mapIndex + 1].name == "TEXTMAP")
                {
                    map = new UDMFMapData(wad.GetLumpAsText(mapIndex + 1));
                }
                else
                {
                    throw new Exception("Unknown map format");
                }
            }
            if (map == null)
            {
                throw new Exception("Error loading map: " + mapname);
            }
            else
            {
                return(map);
            }
        }