コード例 #1
0
ファイル: WadFile.cs プロジェクト: MSylvia/DoomUnity
        public void Merge(WadFile wad)
        {
            if (wad.wadData == null)
            {
                return;
            }

            numLumps += wad.numLumps;

            for (int i = 0; i < wad.directory.Count; i++)
            {
                wad.directory[i].position += wadData.Length;
            }

            if (wad.textureTable != null)
            {
                if (textureTable == null)
                {
                    textureTable = wad.textureTable;
                }
                else
                {
                    textureTable.Merge(wad.textureTable);
                }
            }

            directory.AddRange(wad.directory);

            byte[] newWadData = new byte[wadData.Length + wad.wadData.Length];
            Buffer.BlockCopy(wadData, 0, newWadData, 0, wadData.Length);
            Buffer.BlockCopy(wad.wadData, 0, newWadData, wadData.Length, wad.wadData.Length);
            wadData = newWadData;
        }
コード例 #2
0
ファイル: WadFile.cs プロジェクト: MSylvia/DoomUnity
 public void SetupTextures()
 {
     if (Contains("PNAMES"))
     {
         PatchTable pnames = new PatchTable(GetLump("PNAMES"));
         textureTable = new TextureTable(GetLump("TEXTURE1"), pnames);
         if (Contains("TEXTURE2"))
         {
             textureTable.Add(GetLump("TEXTURE2"), pnames);
         }
     }
 }
コード例 #3
0
 // Merge in an existing texture definition
 public void Merge(TextureTable textureTable)
 {
     foreach (KeyValuePair <string, DoomTexture> entry in textureTable.textures)
     {
         if (textures.ContainsKey(entry.Key))
         {
             textures[entry.Key] = entry.Value;
         }
         else
         {
             textures.Add(entry.Key, entry.Value);
         }
     }
 }
コード例 #4
0
        public static Texture2D BuildTexture(string name, WadFile wad, TextureTable textures, bool trueColor = false)
        {
            if (textureCache == null)
            {
                textureCache = new Dictionary <string, Texture2D>();
            }

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

            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.patchName, wad, trueColor);

                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);
        }