Exemple #1
0
        public void Awake()
        {
            try
            {
                //printPathRecursive(GameDatabase.Instance.root);



                NativeBridge.Setup(Config.Current.GetCacheDirectory());
#if DISABLED_DEBUG
                foreach (var file in System.IO.Directory.GetFiles(Config.Current.GetCacheDirectory()))
                {
                    try
                    {
                        System.IO.File.Delete(file);
                    }
                    catch (Exception) { }
                }
#endif

                Managers.InternalManager.Setup(processAndGetInternals());
                StartupDelayed.PartsToManage = processAndGetParts().ToList();

                // Delay removal from file"system" till all are resolved, so we don't have problems with textures that are used multiple times...
                // we have to remove it, or GameDatabase would reload it...
                foreach (var ft in createdTextures)
                {
                    ft.parent.files.Remove(ft);
                }
                ("LoadOnDemand.Startup done.").Log();

                foreach (var el in GameDatabase.Instance.databaseTexture)
                {
                    if (el.texture == null)
                    {
                        ("NULLTEX FOUND: " + el.name).Log();
                    }
                }
                foreach (var imgs in GameDatabase.Instance.root.AllFiles.Where(f => f.fileType == UrlDir.FileType.Texture))
                {
                    ("REM_IMG: " + imgs.fullPath).Log();
                    // Todo: Details about them incl their meta-data & size would be nice...
                }
            }
            catch (Exception err)
            {
                ActivityGUI.SetWarning(err);
                throw;
            }
        }
Exemple #2
0
        public void Awake()
        {
            try
            {
                if (Config.Disabled)
                {
                    return;
                }

                // Finds loaded instances and remove all models that were not properly loaded on the fly...
                foreach (var partData in PartsToManage)
                {
                    partData.Part = PartLoader.getPartInfoByName(partData.Name);
                    if (partData.Part == null)
                    {
                        ("PartSkipped, was probably not sucessfully loaded:" + partData.Name).Log();
                    }
                    else
                    {
                        Managers.PartManager.Setup(partData);
                    }
                }
                PartsToManage = null;
                Managers.TextureManager.FinalizeSetup();
                Config.Current.CommitChanges();
                ("LoadOnDemand.StartupDelayed done.").Log();
#if true
                // Todo: Lets dumpe this always, for now...
                ("Dumping collected informations! ").Log();

                dumpManagedInternals();
                dumpManagedParts();

                calcSizeOfMissedImages();
#endif
            }
            catch (Exception err)
            {
                ActivityGUI.SetWarning(err);
                throw;
            }
        }
Exemple #3
0
        public void Awake()
        {
            try
            {
                if (Config.Disabled)
                {
                    return;
                }
                // Finds loaded instances and remove all models that were not properly loaded on the fly...
                foreach (var partData in PartsToManage)
                {
                    partData.Part = PartLoader.getPartInfoByName(partData.Name);
                    if (partData.Part == null)
                    {
                        ("PartSkipped, was probably not sucessfully loaded:" + partData.Name).Log();
                    }
                    else
                    {
                        Managers.PartManager.Setup(partData);
                    }
                }
                PartsToManage = null;
                Managers.TextureManager.FinalizeSetup();
                Config.Current.CommitChanges();
                ("LoadOnDemand.StartupDelayed done.").Log();
#if true
                // Todo: Lets dumpe this always, for now...
                ("Dumping collected informations! ").Log();
                foreach (var i in Managers.InternalManager.iManagedInternals)
                {
                    ("Internal: " + i.Key).Log();
                    foreach (var t in i.Value.Textures)
                    {
                        ("  - " + t.name).Log();
                    }
                }
                foreach (var p in Managers.PartManager.iManagedParts)
                {
                    ("Part: " + p.Key + ", " + p.Value.Part.partPath).Log();
                    ("  - Internals: " + String.Join(", ", p.Value.Internals)).Log();
                    foreach (var t in p.Value.Textures)
                    {
                        ("  - " + t.name).Log();
                    }
                }
                "Dumping missed texture informations.".Log();
                Func <int, String>             toSizeString = bytes => (bytes > 0) ? ((bytes / (1024f * 1024f)) + " MB") : "N/A";
                Func <int, TextureFormat, int> bpp          = (pixels, fmt) =>
                {
                    switch (fmt)
                    {
                    case TextureFormat.RGB24:
                    case TextureFormat.RGBA32:
                    case TextureFormat.ARGB32:
                        return(pixels * 4);

                    case TextureFormat.DXT1:
                        return(pixels / 2);

                    case TextureFormat.DXT5:
                        return(pixels);

                    default:
                        return(0);
                    }
                };
                long total_missed = 0;

                /*foreach (var imgs in GameDatabase.Instance.root.AllFiles.Where(f => f.fileType == UrlDir.FileType.Texture))
                 * {
                 *  try
                 *  {
                 *      var tex = GameDatabase.Instance.GetTexture(imgs.url, false);
                 *      var bytes = bpp(tex.width * tex.height, tex.format);
                 *      ("MISSED TEXTURE: " + imgs.fullPath + " (" + tex.width + "x" + tex.height + "@" + tex.format.ToString() + "=> " + toSizeString(bytes) + ")").Log();
                 *      total_missed += bytes;
                 *  }
                 *  catch (Exception) { }
                 * }*/
                foreach (var ti in GameDatabase.Instance.databaseTexture)
                {
                    if (!Managers.TextureManager.IsManaged(ti))
                    {
                        var tex   = ti.texture;
                        var bytes = bpp(tex.width * tex.height, tex.format);
                        ("MISSED TEXTURE: " + ti.name + " (" + tex.width + "x" + tex.height + "@" + tex.format.ToString() + "=> " + toSizeString(bytes) + ")").Log();
                        total_missed += bytes;
                    }
                }
                ("TOTAL SIZE OF MISSED TEXTURES: " + toSizeString((int)total_missed)).Log();

                /*
                 * foreach (var el in UnityEngine.Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object)))
                 * {
                 *  ("RES " + el.GetType().FullName + " aka " + el.name).Log();
                 * }*/
#endif
            }
            catch (Exception err)
            {
                ActivityGUI.SetWarning(err);
                throw;
            }
        }
Exemple #4
0
        public void Awake()
        {
            try
            {
                // Makes LOD ignore GameDatabase's "force reload all", especially since tihs kinda breaks the KspAddon(..., true)
                if (System.Threading.Interlocked.Exchange(ref didRun, 1) != 0)
                {
                    return;
                }
                //printPathRecursive(GameDatabase.Instance.root);

                NativeBridge.Setup(Config.Current.GetCacheDirectory());
#if DISABLED_DEBUG
                foreach (var file in System.IO.Directory.GetFiles(Config.Current.GetCacheDirectory()))
                {
                    try
                    {
                        System.IO.File.Delete(file);
                    }
                    catch (Exception) { }
                }
#endif

                Managers.InternalManager.Setup(processAndGetInternals());
                StartupDelayed.PartsToManage = processAndGetParts().ToList();

                // Delay removal from file"system" till all are resolved, so we don't have problems with textures that are used multiple times...
                // we have to remove it, or GameDatabase would reload it...
                foreach (var ft in createdTextures)
                {
                    ft.parent.files.Remove(ft);
                }
                ("LoadOnDemand.Startup done.").Log();


                /*
                 * - The following updates GameDatabase's "last loaded at" to "Now", to prevent files changed before that to be force-reloaded.
                 * - KSP should do that anyway, since there isn't any drawback & any file has to be loaded initially, but this allows us to do it for them.
                 * - ATM hasn't found a way without using reflection as well, and this one is way less invasiv.
                 * - Todo: ForceReload (eg changing file and using Debug-UI's "reload all") will break LOD, since it can't handle refs becoming invalid. Fixable, though and rearely matters anyway.
                 */
                typeof(GameDatabase)
                .GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
                .Single(field => field.FieldType == typeof(DateTime))
                .SetValue(GameDatabase.Instance, DateTime.Now);

                foreach (var el in GameDatabase.Instance.databaseTexture)
                {
                    if (el.texture == null)
                    {
                        ("NULLTEX FOUND: " + el.name).Log();
                    }
                }
                foreach (var imgs in GameDatabase.Instance.root.AllFiles.Where(isFileATexture))
                {
                    ("REM_IMG: " + imgs.fullPath).Log();
                    // Todo: Details about them incl their meta-data & size would be nice...
                }
            }
            catch (Exception err)
            {
                ActivityGUI.SetWarning(err);
                throw;
            }
        }