예제 #1
0
        public override void Entry(IModHelper help)
        {
            AssemblyPath = help.DirectoryPath;

            var ConfigPath = Path.Combine(help.DirectoryPath, ConfigName);

            using (var tempStream = new MemoryStream()) {
                SerializeConfig.Save(tempStream);

                SerializeConfig.Load(ConfigPath);

                if (IsVersionOutdated(Config.ConfigVersion))
                {
                    Debug.WarningLn("config.toml is out of date, rewriting it.");
                    SerializeConfig.Load(tempStream);
                    Config.ConfigVersion = Config.CurrentVersion;
                }
            }
            SerializeConfig.Save(ConfigPath);

            ConfigureHarmony();
            help.Events.Input.ButtonPressed += OnButtonPressed;

            help.ConsoleCommands.Add("spritemaster_stats", "Dump SpriteMaster Statistics", (_, _1) => { ManagedTexture2D.DumpStats(); });
            help.ConsoleCommands.Add("spritemaster_memory", "Dump SpriteMaster Memory", (_, _1) => { Debug.DumpMemory(); });

            //help.ConsoleCommands.Add("night", "make it dark", (_, _1) => { help.ConsoleCommands.Trigger("world_settime", new string[] { "2100" }); });

            help.Events.GameLoop.DayStarted += OnDayStarted;
            // GC after major events
            help.Events.GameLoop.SaveLoaded += (_, _1) => Garbage.Collect(compact: true, blocking: true, background: false);

            MemoryPressureThread.Start();
            GarbageCollectThread.Start();
        }
        internal static void OnApplyChangesPost(GraphicsDeviceManager __instance)
        {
            var @this = __instance;

            var device = @this.GraphicsDevice;

            try {
                FieldInfo getPrivateField(object obj, string name, bool instance = true)
                {
                    return(obj.GetType().GetField(name, BindingFlags.NonPublic | BindingFlags.Public | (instance ? BindingFlags.Instance : BindingFlags.Static)));
                }

                var capabilitiesProperty = getPrivateField(device, "_profileCapabilities");

                var capabilitiesMember = capabilitiesProperty.GetValue(device);

                var capabilitiesList = new [] {
                    getPrivateField(capabilitiesMember, "HiDef", instance: false).GetValue(capabilitiesMember),
                    capabilitiesMember
                };

                foreach (var capabilities in capabilitiesList)
                {
                    if (capabilities == null)
                    {
                        continue;
                    }
                    var maxTextureSizeProperty = getPrivateField(capabilities, "MaxTextureSize");
                    for (var currentDimension = Config.AbsoluteMaxTextureDimension; currentDimension >= Config.BaseMaxTextureDimension; currentDimension >>= 1)
                    {
                        maxTextureSizeProperty.SetValue(capabilities, currentDimension);
                        getPrivateField(capabilities, "MaxTextureAspectRatio").SetValue(capabilities, currentDimension / 2);
                        try {
                            Config.ClampDimension = currentDimension;
                            //Math.Min(i, Config.PreferredMaxTextureDimension);
                            using (var testTexture = new Texture2D(@this.GraphicsDevice, currentDimension, currentDimension)) {
                                /* do nothing. We want to dispose of it immediately. */
                            }
                            Garbage.Collect(compact: true, blocking: true, background: false);
                            break;
                        }
                        catch {
                            Config.ClampDimension = Config.BaseMaxTextureDimension;
                            maxTextureSizeProperty.SetValue(capabilities, Config.BaseMaxTextureDimension);
                            getPrivateField(capabilities, "MaxTextureAspectRatio").SetValue(capabilities, Config.BaseMaxTextureDimension / 2);
                        }
                        Garbage.Collect(compact: true, blocking: true, background: false);
                    }
                }
            }
            catch (Exception ex) {
                ex.PrintWarning();
            }
        }
예제 #3
0
        public override void Entry(IModHelper help)
        {
            AssemblyPath = help.DirectoryPath;

            var ConfigPath = Path.Combine(help.DirectoryPath, ConfigName);

            using (var tempStream = new MemoryStream()) {
                SerializeConfig.Save(tempStream);

                if (!Config.IgnoreConfig)
                {
                    SerializeConfig.Load(ConfigPath);
                }

                if (IsVersionOutdated(Config.ConfigVersion))
                {
                    Debug.WarningLn("config.toml is out of date, rewriting it.");
                    SerializeConfig.Load(tempStream);
                    Config.ConfigVersion = Config.CurrentVersion;
                }
            }

            if (Config.ShowIntroMessage && !Config.SkipIntro)
            {
                help.Events.GameLoop.GameLaunched += (_, _1) => {
                    Game1.drawLetterMessage("Welcome to SpriteMaster!\nSpriteMaster must resample sprites as it sees them and thus some lag will likely be apparent at the start of the game, upon entering new areas, and when new sprites are seen.\n\nPlease be patient and do not take this as an indication that your computer is incapable of running SpriteMaster.\n\nEnjoy!".Replace("\n", "^"));
                };
                Config.ShowIntroMessage = false;
            }

            SerializeConfig.Save(ConfigPath);

            ConfigureHarmony();
            help.Events.Input.ButtonPressed += OnButtonPressed;

            help.ConsoleCommands.Add("spritemaster_stats", "Dump SpriteMaster Statistics", (_, _1) => { ManagedTexture2D.DumpStats(); });
            help.ConsoleCommands.Add("spritemaster_memory", "Dump SpriteMaster Memory", (_, _1) => { Debug.DumpMemory(); });

            //help.ConsoleCommands.Add("night", "make it dark", (_, _1) => { help.ConsoleCommands.Trigger("world_settime", new string[] { "2100" }); });

            help.Events.GameLoop.DayStarted += OnDayStarted;
            // GC after major events
            help.Events.GameLoop.SaveLoaded += (_, _1) => Garbage.Collect(compact: true, blocking: true, background: false);

            if (MemoryPressureThread != null)
            {
                MemoryPressureThread.Start();
            }
            if (GarbageCollectThread != null)
            {
                GarbageCollectThread.Start();
            }
        }
예제 #4
0
        // SMAPI/CP won't do this, so we do. Purge the cached textures for the previous season on a season change.
        private static void OnDayStarted(object _, DayStartedEventArgs _1)
        {
            // Do a full GC at the start of each day
            Garbage.Collect(compact: true, blocking: true, background: false);

            var season = SDate.Now().Season.ToLower();

            if (season != CurrentSeason)
            {
                CurrentSeason = season;
                ScaledTexture.SpriteMap.SeasonPurge(season);
            }
        }
예제 #5
0
        internal static void OnPresent()
        {
            if (TriggerGC)
            {
                ScaledTexture.PurgeTextures((Config.RequiredFreeMemory * Config.RequiredFreeMemoryHysterisis).NearestLong() * 1024 * 1024);
                //Garbage.Collect();
                Garbage.Collect(compact: true, blocking: true, background: false);

                TriggerGC = false;
            }

            if (Config.AsyncScaling.CanFetchAndLoadSameFrame || !PushedUpdateThisFrame)
            {
                ScaledTexture.ProcessPendingActions();
            }
            RemainingTexelFetchBudget = Config.AsyncScaling.ScalingBudgetPerFrameTexels;
            FetchedThisFrame          = false;
            PushedUpdateThisFrame     = false;
            ++CurrentFrame;
        }