- Implemented texture caching to reduce the performance hit induced by dynamically cropping apparel
- Dynamically cropping apparel is now compatible with Sized Apparel
This commit is contained in:
AbstractConcept 2023-02-07 19:30:02 -06:00
parent 767317773b
commit 9144029fec
15 changed files with 108 additions and 25 deletions

View file

@ -8,6 +8,30 @@ namespace Rimworld_Animations_Patch
{
public static class ApparelSettingsUtility
{
private static Dictionary<string, ApparelTexture2DPack> cachedApparelTextures = new Dictionary<string, ApparelTexture2DPack>();
public static ApparelTexture2DPack GetCachedApparelTextures(Graphic graphic, BodyTypeDef bodyType)
{
if (ApparelSettings.cropApparel == false) return null;
if (graphic?.path == null) return null;
if (cachedApparelTextures.TryGetValue(graphic.path, out ApparelTexture2DPack pack) == false)
{
pack = new ApparelTexture2DPack();
pack.PackTexturesForBodyType(graphic, bodyType);
cachedApparelTextures.Add(graphic.path, pack);
DebugMode.Message("Cropped textures have been cached for " + graphic.path);
}
return pack;
}
public static void ClearCachedApparelTextures()
{
cachedApparelTextures.Clear();
}
public static List<ThingDef> GetApparelOfInterest()
{
List<ThingDef> thingDefs = new List<ThingDef>();

View file

@ -43,11 +43,8 @@ namespace Rimworld_Animations_Patch
public static Texture2D ApplyMaskToTexture2D(Texture2D mainTex, Texture2D maskTex, bool writeOverMainTex)
{
if (mainTex == null || maskTex == null)
{
DebugMode.Message("mainTex or maskTex is missing!");
return mainTex;
}
if (mainTex == null) { DebugMode.Message("ERROR: Cannot mask texture, mainTex is missing!"); return mainTex; }
if (mainTex == null) { DebugMode.Message("ERROR: Cannot mask texture, maskTex is missing!"); return mainTex; }
Color[] mainArray = GetReadableTexture2D(mainTex).GetPixels();
Color[] maskArray = GetReadableTexture2D(maskTex, mainTex.width, mainTex.height).GetPixels();