Example #1
0
 DoomTexture GetInfo(string name, bool tryUpper = true)
 {
     if (textureTable.Contains(name))
     {
         return(textureTable.Get(name.ToUpper()));
     }
     else
     {
         if (wad.Contains(name))
         {
             DataType type = wad.DetectType(name);
             if (type == DataType.DoomFlat)
             {
                 return(new DoomTexture(name, 64, 64, null));
             }
             else if (type == DataType.PNG)
             {
                 Texture2D image = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                 ImageConversion.LoadImage(image, wad.GetLump(name));
                 image.filterMode = FilterMode.Point;
                 return(new DoomTexture(name, image.width, image.height, null));
             }
             else
             {
                 throw new Exception("Unknown texture type: " + name);
             }
         }
         else
         {
             if (tryUpper)
             {
                 return(GetInfo(name.ToUpper(), false));
             }
             throw new Exception("Cannot find texture: " + name);
         }
     }
 }
Example #2
0
 DoomTexture GetInfo(string name)
 {
     return(textureTable.Get(name.ToUpper()));
 }
Example #3
0
    public static Texture2D BuildTexture(string name, WadFile wad, TextureTable textures)
    {
        if (textureCache == null)
        {
            textureCache = new Dictionary <string, Texture2D>();
        }

        if (textureCache.ContainsKey(name))
        {
            return(textureCache[name]);
        }

        PatchTable pnames = new PatchTable(wad.GetLump("PNAMES"));

        DoomTexture texture = textures.Get(name.ToUpper());


        Texture2D output = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false, true);

        for (int i = 0; i < texture.patches.Count; i++)
        {
            DoomPatch p       = texture.patches[i];
            Texture2D patch2d = DoomGraphic.BuildPatch(p.patchIndex, pnames, wad);

            if (patch2d == null)
            {
                return(null);
            }

            int copyX = (p.originX < 0)?-p.originX:0;
            int copyY = (p.originY < 0)?-p.originY:0;

            int pasteX = (p.originX > 0)?p.originX:0;
            int pasteY = (p.originY > 0)?p.originY:0;

            int copyWidth = patch2d.width - copyX;
            if (copyWidth > output.width - pasteX)
            {
                copyWidth = output.width - pasteX;
            }

            int copyHeight = patch2d.height - copyY;
            if (copyHeight > output.height - pasteY)
            {
                copyHeight = output.height - pasteY;
            }

            for (int a = 0; a < copyWidth; a++)
            {
                for (int b = 0; b < copyHeight; b++)
                {
                    Color col = patch2d.GetPixel(copyX + a, copyY + b);
                    if (col.a != 0f)
                    {
                        output.SetPixel(pasteX + a, pasteY + b, col);
                    }
                }
            }
        }

        output.Apply();
        output.wrapMode   = TextureWrapMode.Repeat;
        output.filterMode = FilterMode.Point;

        textureCache.Add(name, output);

        return(output);
    }