diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-04-02 19:13:27 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-04-02 19:13:27 -0400 |
commit | 546b58778c9e1e983f1682f1b89cbc353939d9ea (patch) | |
tree | 7bc289cf525e01ff7a59056734623237b9598723 | |
parent | f58cdde981f7dfabb5783c80b29f4996d76cec30 (diff) | |
download | SMAPI-546b58778c9e1e983f1682f1b89cbc353939d9ea.tar.gz SMAPI-546b58778c9e1e983f1682f1b89cbc353939d9ea.tar.bz2 SMAPI-546b58778c9e1e983f1682f1b89cbc353939d9ea.zip |
switch to 'processing tick' for tick caching
This is incremented on each low-level tick (whether it's a game update, synchronized async operation, etc). That mainly avoids the cache persisting across the entire save loading process while it's being synchronized.
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 8 | ||||
-rw-r--r-- | src/SMAPI/Framework/Utilities/TickCacheDictionary.cs | 5 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 7fd5bcd3..d0f5ffb4 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -158,9 +158,12 @@ namespace StardewModdingAPI.Framework /// <remarks>This is only intended for use by external code like the Error Handler mod.</remarks> internal static SCore Instance { get; private set; } - /// <summary>The number of update ticks which have already executed. This is similar to <see cref="Game1.ticks"/>, but incremented more consistently for every tick.</summary> + /// <summary>The number of game update ticks which have already executed. This is similar to <see cref="Game1.ticks"/>, but incremented more consistently for every tick.</summary> internal static uint TicksElapsed { get; private set; } + /// <summary>A specialized form of <see cref="TicksElapsed"/> which is incremented each time SMAPI performs a processing tick (whether that's a game update, one wait cycle while synchronizing code, etc).</summary> + internal static uint ProcessTicksElapsed { get; private set; } + /********* ** Public methods @@ -558,6 +561,7 @@ namespace StardewModdingAPI.Framework finally { SCore.TicksElapsed++; + SCore.ProcessTicksElapsed++; } } @@ -631,6 +635,8 @@ namespace StardewModdingAPI.Framework this.Reflection.GetMethod(Game1.game1, "UpdateTitleScreen").Invoke(Game1.currentGameTime); // run game logic to change music on load, etc while (Game1.currentLoader?.MoveNext() == true) { + SCore.ProcessTicksElapsed++; + // raise load stage changed switch (Game1.currentLoader.Current) { diff --git a/src/SMAPI/Framework/Utilities/TickCacheDictionary.cs b/src/SMAPI/Framework/Utilities/TickCacheDictionary.cs index 5921e089..d0f276d2 100644 --- a/src/SMAPI/Framework/Utilities/TickCacheDictionary.cs +++ b/src/SMAPI/Framework/Utilities/TickCacheDictionary.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using StardewValley; namespace StardewModdingAPI.Framework.Utilities { @@ -28,10 +27,10 @@ namespace StardewModdingAPI.Framework.Utilities public TValue GetOrSet(TKey cacheKey, Func<TValue> get) { // clear cache on new tick - if (SCore.TicksElapsed != this.LastGameTick) + if (SCore.ProcessTicksElapsed != this.LastGameTick) { this.Cache.Clear(); - this.LastGameTick = SCore.TicksElapsed; + this.LastGameTick = SCore.ProcessTicksElapsed; } // fetch value |