Ejemplo n.º 1
0
    private void LoadTextureFromWad(string WadFileName, TexInfoClass[] TexturesToLoad)
    {
        if (File.Exists("Assets/Wad/" + WadFileName))
        {
//read in wad header
            BinaryReader wadStream = new BinaryReader(File.Open("Assets/Wad/" + WadFileName, FileMode.Open));
            string       wadType   = new string (wadStream.ReadChars(4));
            if (wadType != "WAD3" && wadType != "WAD2")
            {
                Debug.LogError("Wad file wrong type");
                return;
            }
            int numberOfTexs = (int)wadStream.ReadUInt32();

            wadStream.BaseStream.Position = wadStream.ReadUInt32();                                      //move to start of wad directory


            TexInfoClass[] TexuresInWadFile = new TexInfoClass[numberOfTexs];                                    //this will hold an array of all texture names and  offsets in the wad file

            //for each texture in wad file get ist name of offset in the file
            for (int i = 0; i < TexuresInWadFile.Length; i++)
            {
                TexuresInWadFile [i] = new TexInfoClass();
                TexuresInWadFile [i].IndexOfMipTex = (int)wadStream.ReadUInt32();                   //get offset for texture
                wadStream.BaseStream.Position     += 12;                                            //skip info
                TexuresInWadFile [i].TextureName   = wadStream.LoadCleanString(16);
            }

            //now compare our list of missing textures and load any we find in the TexturesToLoad array
            for (int j = 0; j < TexturesToLoad.Length; j++)
            {
                for (int k = 0; k < TexuresInWadFile.Length; k++)
                {
                    if (TexturesToLoad [j].TextureName == TexuresInWadFile [k].TextureName)
                    {
                        //we found a missing texture so load it

                        miptexLump [TexturesToLoad [j].IndexOfMipTex] = ReadInTexture(TexuresInWadFile [k].IndexOfMipTex, wadStream, WadFileName);
                        if (miptexLump [TexturesToLoad [j].IndexOfMipTex].texture != null)
                        {
                            TexturesToLoad [j].TextureName = null;                                                                                    //might need check for null returned texture
                        }
                        break;
                    }
                }
            }

            wadStream.Close();
        }
        else
        {
            Debug.LogError("Error wad file " + WadFileName.ToString() + " not found");
        }
    }
Ejemplo n.º 2
0
    public void findNullTextures()
    {
        //make a list of textures that need to be loaded from wad files
        TexInfoClass[] texinfo = new TexInfoClass[NumTexLoadFromWad];
        //iterate miptexLump and add a TexInfoClass for each null texture we need to load
        int IndexOfTexinfo = 0;

        for (int j = 0; j < miptexLump.Length; j++)                    //!!!!!!!!!! do this in the load miptexLump method instead!!!!!!!!!!!!!!!!!!
        {
            if (miptexLump [j].texture == null)
            {
                texinfo [IndexOfTexinfo] = new TexInfoClass(miptexLump [j].name, j);
                IndexOfTexinfo++;
            }
        }
        //next get the string of  wads we need
        string[] wadFileNames;
        myParser = new EntityParser(entityLump.rawEntities);

        Dictionary <string, string> mylist = myParser.ReadEntity();
        string tempString;

        if (mylist.ContainsKey("wad"))
        {
            tempString = mylist ["wad"];

            wadFileNames = tempString.Split(';');
            for (int i = 0; i < wadFileNames.Length; i++)
            {
                wadFileNames [i] = wadFileNames [i].Substring(wadFileNames [i].LastIndexOf("\\") + 1);                                                  //remove unwanted text
                if (wadFileNames [i].Length > 3)
                {
                    Debug.Log(wadFileNames [i].ToString());
                    LoadTextureFromWad(wadFileNames [i], texinfo);
                }
            }
        }
        else
        {
            Debug.Log("no textures to load from wad, or no wad key found in bsp");
        }
    }
Ejemplo n.º 3
0
		private void LoadTextureFromWad (string WadFileName, TexInfoClass[] TexturesToLoad)
		{
				if (File.Exists ("Assets/Wad/" + WadFileName))
				{
//read in wad header
						BinaryReader wadStream = new BinaryReader (File.Open ("Assets/Wad/" + WadFileName, FileMode.Open));
						string wadType = new string (wadStream.ReadChars (4));
						if (wadType != "WAD3" && wadType != "WAD2")
						{
								Debug.LogError ("Wad file wrong type");
								return;
						}
						int numberOfTexs = (int)wadStream.ReadUInt32 ();
						
						wadStream.BaseStream.Position = wadStream.ReadUInt32 (); //move to start of wad directory
						

						TexInfoClass[] TexuresInWadFile = new TexInfoClass[numberOfTexs];//this will hold an array of all texture names and  offsets in the wad file
			              
						//for each texture in wad file get ist name of offset in the file
						for (int i=0; i<TexuresInWadFile.Length; i++)
						{
								TexuresInWadFile [i] = new TexInfoClass ();
								TexuresInWadFile [i].IndexOfMipTex = (int)wadStream.ReadUInt32 (); //get offset for texture
								wadStream.BaseStream.Position += 12;//skip info 
								TexuresInWadFile [i].TextureName = wadStream.LoadCleanString (16);
						}

						//now compare our list of missing textures and load any we find in the TexturesToLoad array
						for (int j=0; j<TexturesToLoad.Length; j++)
						{
								for (int k=0; k<TexuresInWadFile.Length; k++)
								{
								

										if (TexturesToLoad [j].TextureName == TexuresInWadFile [k].TextureName)
										{
												//we found a missing texture so load it
					
												miptexLump [TexturesToLoad [j].IndexOfMipTex] = ReadInTexture (TexuresInWadFile [k].IndexOfMipTex, wadStream, WadFileName);
												if (miptexLump [TexturesToLoad [j].IndexOfMipTex].texture != null)
														TexturesToLoad [j].TextureName = null;//might need check for null returned texture 
												break;

										}


								}
								
						}	
	
						wadStream.Close ();
			
				}
				else
				{
						Debug.LogError ("Error wad file " + WadFileName.ToString () + " not found");
				}

		}
Ejemplo n.º 4
0
		public void findNullTextures ()
		{
				//make a list of textures that need to be loaded from wad files
				TexInfoClass[] texinfo = new TexInfoClass[NumTexLoadFromWad];
				//iterate miptexLump and add a TexInfoClass for each null texture we need to load
				int IndexOfTexinfo = 0;
		
				for (int j=0; j<miptexLump.Length; j++)//!!!!!!!!!! do this in the load miptexLump method instead!!!!!!!!!!!!!!!!!!
				{
						if (miptexLump [j].texture == null)
						{
								texinfo [IndexOfTexinfo] = new TexInfoClass (miptexLump [j].name, j);
								IndexOfTexinfo++;
						}
				}
				//next get the string of  wads we need
				string[] wadFileNames;
				myParser = new EntityParser (entityLump.rawEntities);
				
				Dictionary<string, string> mylist = myParser.ReadEntity ();
				string tempString;
				if (mylist.ContainsKey ("wad"))
				{
						tempString = mylist ["wad"];
						
						wadFileNames = tempString.Split (';');
						for (int i =0; i<wadFileNames.Length; i++)
						{
								wadFileNames [i] = wadFileNames [i].Substring (wadFileNames [i].LastIndexOf ("\\") + 1);//remove unwanted text
								if (wadFileNames [i].Length > 3)
								{
										Debug.Log (wadFileNames [i].ToString ());
										LoadTextureFromWad (wadFileNames [i], texinfo);
								}
						}
				}
				else
				{
						Debug.Log ("no textures to load from wad, or no wad key found in bsp");
				}
		}