Lots of new optimizations utilizing prepatcher
To start, this mod now requires Prepatcher and Fishery. New optimizations include: gene ticking improvements, world object improvements, hediff optimizations, world pawn gc optimizations, better mothballing, dds support, ContentFinder caching, additions and changes to reflection caching, as well as various other additions. Multiplayer support has been improved too, but should be considered highly experimental. The WorkGiver_DoBill bug is fixed in this build. Multiple patches aiming to improve RimWorld's load time have been added too.
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
// Copyright (c) 2023 bradson
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using PerformanceFish.ModCompatibility;
|
||||
using PerformanceFish.Prepatching;
|
||||
using PerformanceFish.System;
|
||||
|
||||
namespace PerformanceFish;
|
||||
|
||||
/// <summary>
|
||||
/// Gets called before CreateModClasses(), after rimworld finishes loading assemblies
|
||||
/// </summary>
|
||||
public static class OnAssembliesLoaded
|
||||
{
|
||||
public static bool Loaded { get; private set; }
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
Loaded = true;
|
||||
|
||||
TryPatchGraphicsSetter();
|
||||
TryPatchPerformanceOptimizer();
|
||||
|
||||
TryInitialize(EqualityComparerOptimization.Optimization.Initialize);
|
||||
|
||||
PerformanceFishMod.AllPatchClasses = PerformanceFishMod.InitializeAllPatchClasses<IHasFishPatch>();
|
||||
PerformanceFishMod.AllPrepatchClasses ??= PerformanceFishMod.InitializeAllPatchClasses<ClassWithFishPrepatches>();
|
||||
|
||||
TryInitialize(AnalyzerFixes.Patch, true);
|
||||
|
||||
_ = FishSettings.Instance;
|
||||
|
||||
Parallel.ForEach(PerformanceFishMod.AllPatchClasses, static patchClass =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!patchClass.RequiresLoadedGameForPatching)
|
||||
patchClass.Patches.PatchAll();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($"{PerformanceFishMod.NAME} encountered an exception while trying to initialize {
|
||||
patchClass.GetType().Name}:\n{ex}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void TryPatchGraphicsSetter()
|
||||
{
|
||||
if (ActiveMods.GraphicsSetter && GraphicsSetter.TryPatch() is null)
|
||||
{
|
||||
Log.Error($"Failed to apply compatibility patch for {
|
||||
GraphicsSetter.Mod?.Name ?? "Graphics Settings+"}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void TryPatchPerformanceOptimizer()
|
||||
{
|
||||
if (ActiveMods.PerformanceOptimizer && !PerformanceOptimizer.TryPatch())
|
||||
{
|
||||
Log.Error($"Failed to apply compatibility patch for {
|
||||
PerformanceOptimizer.ModContentPack?.Name ?? "Performance Optimizer"}");
|
||||
}
|
||||
}
|
||||
|
||||
private static async void TryInitialize(Action action, bool async = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (async)
|
||||
await Task.Run(action).ConfigureAwait(false);
|
||||
else
|
||||
action();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($"{PerformanceFishMod.NAME} encountered an exception while trying to initialize {
|
||||
action.Method.FullDescription()}:\n{ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user