public static void Postfix(StatDef ___stat, ref float __result, StatRequestModel __state) { //if (Prefs.DevMode) //{ // if (Current.Game != null) // { // if (_stopwatch.IsRunning) // { // _stopwatch.Stop(); // _totalTime += _stopwatch.Elapsed.TotalMilliseconds; // ++_calls; // } // } //} if (Current.Game != null) { if (_cache.TryGetValue(__state, out CacheableTick <float> value)) { value.Value = __result; } else { _cache[__state] = MakeCache(__result); } //if (Prefs.DevMode && Current.Game != null) // _record.Add($"{__state.StatRequest} -- value: {__result: 00.00}"); } }
public static bool Prefix(StatRequest req, bool applyPostProcess, StatDef ___stat, ref float __result, out StatRequestModel __state) { __state = new StatRequestModel(req, applyPostProcess, ___stat); if (_cache.TryGetValue(__state, out var value) && !value.ShouldUpdate(out _)) { return(false); } return(true); }
public static void Postfix(StatDef ___stat, ref float __result, StatRequestModel __state) { if (Current.Game != null) { if (_cache.TryGetValue(__state, out var value)) { value.Value = __result; } else { _cache[__state] = MakeCache(__result); } } }
public static bool Prefix(StatRequest req, bool applyPostProcess, StatDef ___stat, ref float __result, out StatRequestModel __state) { //if (Prefs.DevMode && Current.Game != null) //{ // if (_lastTick != Find.TickManager.TicksGame) // { // //Log.Warning($"Execution time for tick {_lastTick} is {_totalTime}ms for {_calls} of calls. Total number of cache: {_cache.Count}. Cache hit: {_cacheHit}"); // _totalTime = 0; // _calls = 0; // _cacheHit = 0; // _lastTick = Find.TickManager.TicksGame; // //Log.Message($"All requests for tick {_lastTick}\n{string.Join("\n", _record)}"); // _record.Clear(); // } // _stopwatch.Restart(); //} __state = new StatRequestModel(req, applyPostProcess, ___stat); if (_cache.TryGetValue(__state, out CacheableTick <float> value) && !value.ShouldUpdate(out _)) { __result = value.Value; //if (Prefs.DevMode) //{ // lock (_lock) // { // ++_cacheHit; // } //} //if (Prefs.DevMode && Current.Game != null) // _record.Add($"{__state.StatRequest} -- value: {value: 00.00}"); return(false); } return(true); }