コード例 #1
0
        public PatchTable(byte[] lumpData)
        {
            patches = new List <string>();

            for (int i = 0; i < (int)BitConverter.ToUInt32(lumpData, 0); i++)
            {
                patches.Add(WadFile.GetString(lumpData, 4 + (i * 8)));
            }
        }
コード例 #2
0
ファイル: DoomMapData.cs プロジェクト: MSylvia/DoomUnity
        public DoomMapData(WadFile wad, string name)
        {
            this.format = MapFormat.Doom;
            int index = wad.GetIndex(name);

            LoadThings(wad.GetLump(index + 1));
            LoadLinedefs(wad.GetLump(index + 2));
            LoadSidedefs(wad.GetLump(index + 3));
            LoadVertices(wad.GetLump(index + 4));
            LoadSectors(wad.GetLump(index + 8));
        }
コード例 #3
0
ファイル: DoomMapData.cs プロジェクト: raynler/DoomUnity
        public DoomMapData(WadFile wad, string name)
        {
            bounds = new NodeBounds();

            this.format = MapFormat.Doom;
            int index = wad.GetIndex(name);

            LoadThings(wad.GetLump(index + 1));
            LoadLinedefs(wad.GetLump(index + 2));
            LoadSidedefs(wad.GetLump(index + 3));
            LoadVertices(wad.GetLump(index + 4));
            LoadSegs(wad.GetLump(index + 5));
            LoadSubsectors(wad.GetLump(index + 6));
            LoadNodes(wad.GetLump(index + 7));
            LoadSectors(wad.GetLump(index + 8));
        }
コード例 #4
0
        // Append a texture definition from wad
        public void Add(byte[] lumpData, PatchTable patchTable)
        {
            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),
                        patchTable.patches[(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);
                }
            }
        }
コード例 #5
0
        public static Sprite BuildSprite(string name, WadFile wad)
        {
            if (spriteCache == null)
            {
                spriteCache = new Dictionary <string, Sprite>();
            }

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

            Sprite output = new DoomGraphic(wad.GetLump(name.ToUpper())).ToSprite();

            spriteCache.Add(name, output);

            return(output);
        }
コード例 #6
0
        public static Dictionary <string, Material> BuildTextureMaterials(WadFile wad, string[] textures)
        {
            if (paletteLookup == null)
            {
                Init(wad);
            }

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

            for (int i = 0; i < textures.Length; i++)
            {
                if (textures[i] != "-" && wad.textureTable.Contains(textures[i].ToUpper()) && !output.ContainsKey(textures[i].ToUpper()))
                {
                    output.Add(textures[i].ToUpper(), BuildTextureMaterial(wad, textures[i]));
                }
            }
            return(output);
        }
コード例 #7
0
        public static Material BuildTextureMaterial(WadFile wad, string textureName)
        {
            if (paletteLookup == null)
            {
                Init(wad);
            }

            if (wad.textureTable.Contains(textureName.ToUpper()))
            {
                DoomTexture texture  = wad.textureTable.Get(textureName.ToUpper());
                Material    material = new Material(Shader.Find("Doom/Texture"));
                material.SetTexture("_MainTex", DoomGraphic.BuildTexture(textureName.ToUpper(), wad));
                material.SetTexture("_Palette", paletteLookup);
                material.SetTexture("_Colormap", colormapLookup);
                material.enableInstancing = true;
                return(material);
            }
            return(null);
        }
コード例 #8
0
        public static void PlaySoundAtPoint(WadFile wad, string name, Vector3 point)
        {
            if (soundCache == null)
            {
                soundCache = new Dictionary <string, AudioClip>();
            }

            AudioClip clip;

            if (soundCache.ContainsKey(name))
            {
                clip = soundCache[name];
            }
            else
            {
                clip = new DoomSound(wad.GetLump(name), name).ToAudioClip();
                soundCache.Add(name, clip);
            }

            AudioSource.PlayClipAtPoint(clip, point);
        }
コード例 #9
0
        public static Dictionary <string, MapInfo> Load(string data, WadFile wad)
        {
            MapInfoLump minfol = JsonUtility.FromJson <MapInfoLump>(data);

            if (minfol.baseMapinfo == null)
            {
                return(ReadData(minfol));
            }
            else
            {
                Dictionary <string, MapInfo> baseMapinfo = ReadData(JsonUtility.FromJson <MapInfoLump>(wad.GetLumpAsText(minfol.baseMapinfo)));
                Dictionary <string, MapInfo> repMapinfo  = ReadData(minfol);
                foreach (KeyValuePair <string, MapInfo> entry in repMapinfo)
                {
                    if (baseMapinfo.ContainsKey(entry.Key))
                    {
                        if (entry.Value.name != null)
                        {
                            baseMapinfo[entry.Key].name = entry.Value.name;
                        }
                        if (entry.Value.music != null)
                        {
                            baseMapinfo[entry.Key].music = entry.Value.music;
                        }
                        if (entry.Value.sky != null)
                        {
                            baseMapinfo[entry.Key].sky = entry.Value.sky;
                        }
                    }
                    else
                    {
                        baseMapinfo.Add(entry.Key, entry.Value);
                    }
                }
                return(baseMapinfo);
            }
        }
コード例 #10
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);
        }
コード例 #11
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);
        }
コード例 #12
0
 public static Texture2D BuildPatch(DoomPatch patch, WadFile wad, bool trueColor = false)
 {
     return(BuildPatch(patch.patchName, wad, false, trueColor));
 }
コード例 #13
0
ファイル: DoomMapData.cs プロジェクト: raynler/DoomUnity
 private string FixString(string input)
 {
     return(WadFile.FixString(input));
 }
コード例 #14
0
 public DoomMeshGenerator(WadFile wad, MapData map, NodeTriangulation nodeTri)
 {
     this.wad     = wad;
     this.map     = map;
     this.nodeTri = nodeTri;
 }
コード例 #15
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);
            }
        }
コード例 #16
0
 static void Init(WadFile wad)
 {
     paletteLookup  = new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture();
     colormapLookup = new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture();
 }