public void Minimize(bool force)
        {
            Vector2 scaleSize = new Vector2(32, 32);

            if (texInfo.texture != null && (texInfo.texture.width > scaleSize.x || texInfo.texture.height > scaleSize.y || force))
            {
                Loader.Log("Freeing " + texInfo.texture.name);
                string cached = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "/ScaledTexCache/" + Path.GetFileName(texInfo.texture.name) + "_hash_" + hash;
                if (File.Exists(cached))
                {
                    Loader.Log("Loaded From cache @" + cached);
                    byte[] cache = System.IO.File.ReadAllBytes(cached);
                    texInfo.texture.LoadImage(cache);
                }
                else
                {
                    Loader.Log("Caching @" + cached);
                    TextureConverter.Reload(texInfo, true, scaleSize, cached);
                }
            }
            else
            {
                //Loader.Log("null: "+(texInfo.texture != null)+" "+ (texInfo.texture.width > scaleSize.x || texInfo.texture.height > scaleSize.y)+" "+force);
            }
        }
Beispiel #2
0
        internal static GameDatabase.TextureInfo Load(UrlDir.UrlFile urlFile)
        {
            UrlDir.UrlFile file       = urlFile;
            string         hash       = TexRefCnt.GetMD5String(file.fullPath);
            string         urlReplace = TexPatchLoader.GetReplacement(file.url);

            if (urlReplace != null)
            {
                //   file = getReplacementFile(urlReplace);
                //   hash = TexRefCnt.GetMD5String(file.fullPath);
                GameDatabase.TextureInfo dummy = new GameDatabase.TextureInfo(file, new Texture2D(2, 2), false, false, false);
                dummy.name         = file.url;
                dummy.texture.name = dummy.name;
                return(dummy);
            }

            GameDatabase.TextureInfo texInfo = new GameDatabase.TextureInfo(file, null, false, false, false);
            bool   hasMipmaps = updateToStockSettings(texInfo);
            string cached     = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "/ScaledTexCache/" + Path.GetFileName(file.url) + "_hash_" + hash;

            Loader.Log("hash: " + hash);

            if (texHashDictionary.ContainsKey(hash))
            {
                Loader.Log("Loaded From hash");
                texInfo.texture = texHashDictionary[hash];
            }
            else if (File.Exists(cached))
            {
                Loader.Log("Loaded From cache @" + cached);
                byte[]        cache  = System.IO.File.ReadAllBytes(cached);
                TextureFormat format = texInfo.isCompressed ? TextureFormat.DXT5 : TextureFormat.ARGB32;
                texInfo.texture = new Texture2D(32, 32, format, hasMipmaps);
                if (texInfo.file.fileExtension == "dds")
                {
                    //texInfo.isReadable = true;
                }
                texInfo.texture.Apply(hasMipmaps, !texInfo.isReadable);
                texInfo.texture.LoadImage(cache);
                texHashDictionary[hash] = texInfo.texture;
                //add texture reference.
                TexRefCnt texRef = new TexRefCnt(texInfo, hash, true);
                texInfo.texture.name = file.url;
            }
            else
            {
                TextureConverter.Reload(texInfo, false, default(Vector2), null, hasMipmaps);
                texHashDictionary[hash] = texInfo.texture;
                TexRefCnt texRef = new TexRefCnt(texInfo, hash, false);
                texInfo.texture.name = file.url;
            }

            Loader.Log(texInfo.file.fileExtension + " c: " + texInfo.isCompressed + " n: " + texInfo.isNormalMap + " r: " + texInfo.isReadable + " m: " + (texInfo.texture.mipmapCount > 1));

            texInfo.name = urlFile.url;
            Loader.Log(texInfo.name + " -> " + texInfo.texture.name);
            return(texInfo);
        }
 public void Reload()
 {
     if (texInfo.texture != null)
     {
         Loader.Log("Reloading " + texInfo.texture.name);
         string cached = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "/TexCache/" + Path.GetFileName(texInfo.texture.name) + "_hash_" + hash;
         if (File.Exists(cached))
         {
             Loader.Log("Loaded From cache @" + cached);
             byte[] cache = System.IO.File.ReadAllBytes(cached);
             texInfo.texture.LoadImage(cache);
         }
         else
         {
             Loader.Log("Caching @" + cached);
             TextureConverter.Reload(texInfo, true, default(Vector2), cached);
         }
     }
 }
Beispiel #4
0
        internal static GameDatabase.TextureInfo Load(UrlDir.UrlFile urlFile)
        {
            string hash         = GetMD5String(urlFile.fullPath);
            bool   hasMipmaps   = urlFile.fileExtension == "png" ? false : true;
            bool   isNormalMap  = urlFile.name.EndsWith("NRM");
            bool   isReadable   = urlFile.fileExtension == "dds" || isNormalMap ? false : true;
            bool   isCompressed = urlFile.fileExtension == "tga" ? false : true;

            GameDatabase.TextureInfo texInfo = new GameDatabase.TextureInfo(urlFile, null, isNormalMap, isReadable, isCompressed);
            texInfo.name = urlFile.url;

            string cached = Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "/ScaledTexCache/" + texInfo.file.name + "_hash_" + hash;

            /*
             * if (texHashDictionary.ContainsKey(hash))
             * {
             *  texInfo.texture = texHashDictionary[hash];
             *
             *  foreach(UrlDir.UrlConfig config in GameDatabase.Instance.root.AllConfigs)
             *  {
             *      ConfigNode model = config.config.GetNode("MODEL");
             *      if (config.type == "PART" && model != null)
             *      {
             *          int i = 0;
             *          string value = model.GetValue("texture", i);
             *          while(value != null)
             *          {
             *              String replace = @"(.*),\s*" + Regex.Escape(urlFile.url);
             *              if (Regex.IsMatch(value, replace))
             *              {
             *                  model.SetValue("texture", Regex.Replace(value, replace, "$1, " + texInfo.texture.name), i);
             *              }
             *              i++;
             *              value = model.GetValue("texture", i);
             *          }
             *
             *      }
             *  }
             *
             * }
             * else */
            if (File.Exists(cached))
            {
                Loader.Log("Loaded From cache @" + cached);
                byte[]        cache  = System.IO.File.ReadAllBytes(cached);
                TextureFormat format = isCompressed ? TextureFormat.DXT5 : TextureFormat.ARGB32;
                texInfo.texture = new Texture2D(32, 32, format, hasMipmaps);
                texInfo.texture.Apply(hasMipmaps, !isReadable);
                texInfo.texture.LoadImage(cache);
                texHashDictionary[hash] = texInfo.texture;
                //add texture reference.

                texInfo.texture.name = texInfo.name;
                TexRefCnt texRef = new TexRefCnt(texInfo, hash, true);
            }
            else
            {
                TextureConverter.Reload(texInfo, false, default(Vector2), null, hasMipmaps);
                texHashDictionary[hash] = texInfo.texture;
                texInfo.texture.name    = texInfo.name;
                TexRefCnt texRef = new TexRefCnt(texInfo, hash, false);
            }

            return(texInfo);
        }