示例#1
0
    // Append a texture definition
    public void Add(byte[] lumpData)
    {
        uint amt = BitConverter.ToUInt32(lumpData, 0);

        uint[] offsets = new uint[amt];
        int    i;

        for (i = 0; i < amt; i++)
        {
            offsets[i] = BitConverter.ToUInt32(lumpData, 4 + (i * 4));
        }


        for (i = 0; i < amt; i++)
        {
            int offset = (int)offsets[i];

            uint             patchCount = BitConverter.ToUInt16(lumpData, offset + 20);
            List <DoomPatch> patches    = new List <DoomPatch>();
            for (int j = offset + 22; j < (offset + 22) + (patchCount * 10); j += 10)
            {
                DoomPatch np = new DoomPatch(
                    (int)BitConverter.ToInt16(lumpData, j),
                    (int)BitConverter.ToInt16(lumpData, j + 2),
                    (int)BitConverter.ToUInt16(lumpData, j + 4)
                    );
                patches.Add(np);
            }

            DoomTexture newTex = new DoomTexture(
                WadFile.GetString(lumpData, offset),
                (int)BitConverter.ToUInt16(lumpData, offset + 12),
                (int)BitConverter.ToUInt16(lumpData, offset + 14),
                patches
                );

            if (textures.ContainsKey(newTex.name))
            {
                textures[newTex.name] = newTex;
            }
            else
            {
                //Debug.Log(newTex.name);
                textures.Add(newTex.name, newTex);
            }
        }
    }
示例#2
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);
    }