From a2794e3e4742b0e63c96ddb7cc570544fd85f3e8 Mon Sep 17 00:00:00 2001 From: LoafyLemon Date: Sun, 9 Jul 2023 01:18:45 +0100 Subject: [PATCH] Performance * Improve wardrobe performance by caching last 100 generated icon references --- game/scripts/wardrobe/wardrobe.rpy | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/game/scripts/wardrobe/wardrobe.rpy b/game/scripts/wardrobe/wardrobe.rpy index a6b79f33..b58bda2a 100644 --- a/game/scripts/wardrobe/wardrobe.rpy +++ b/game/scripts/wardrobe/wardrobe.rpy @@ -33,6 +33,10 @@ init python: _lock = False + @functools.lru_cache(maxsize=100) + def create_wardrobe_icon(d, size=(96, 96), fit="contain", anchor=(0.5, 0.5), align=(0.5, 0.5), yoffset=0, crop=None): + return Transform(d, size=size, fit=fit, anchor=anchor, align=align, yoffset=yoffset, crop=crop) + style loading_text: color "#ffffff" size 64 @@ -162,7 +166,7 @@ label wardrobe_menu(): category_items = OrderedDict(sorted(iter(list(wardrobe_subcategories.get(current_category, {}).items())), key=lambda x: wardrobe_subcategories_sorted.get(x[0], 0), reverse=True)) current_subcategory = list(category_items.keys())[0] if category_items else "" menu_items = [x for x in category_items.get(current_subcategory, []) if x.unlocked==True] - icon_items = [Transform(x.icon, size=(96, 96), fit="contain", anchor=(0.5, 0.5), align=(0.5, 0.5)) for x in menu_items] + icon_items = [create_wardrobe_icon(x.icon) for x in menu_items] current_item = char_active.get_equipped_item(menu_items) last_track = renpy.music.get_playing() @@ -198,11 +202,11 @@ label wardrobe_menu(): if current_category == "outfits": $ _outfit = char_active.create_outfit(temp=True) $ menu_items = [x for x in reversed(category_items.get(current_subcategory, [])) if x.unlocked==True] - $ icon_items = [Transform(x.image, crop=(220, 0, 680, 1200), size=(96, 168), fit="contain", anchor=(0.5, 1.0), align=(0.5, 1.0), yoffset=-6) for x in menu_items] + $ icon_items = [create_wardrobe_icon(x.image, crop=(220, 0, 680, 1200), size=(96, 168), fit="contain", anchor=(0.5, 1.0), align=(0.5, 1.0), yoffset=-6) for x in menu_items] $ current_item = next( (x for x in char_active.outfits if _outfit == x), None) else: $ menu_items = [x for x in category_items.get(current_subcategory, []) if x.unlocked==True] - $ icon_items = [Transform(x.icon, size=(96, 96), fit="contain", anchor=(0.5, 0.5), align=(0.5, 0.5)) for x in menu_items] + $ icon_items = [create_wardrobe_icon(x.icon) for x in menu_items] $ current_item = char_active.get_equipped_item(menu_items) $ char_active.wear("all") @@ -223,13 +227,13 @@ label wardrobe_menu(): if current_subcategory == "import": $ menu_items = list_outfit_files() - $ icon_items = [Transform(f"outfits/{x}", size=(96, 168), fit="contain", anchor=(0.5, 1.0), align=(0.5, 1.0), yoffset=-6) for x in menu_items] + $ icon_items = [create_wardrobe_icon(f"outfits/{x}", size=(96, 168), fit="contain", anchor=(0.5, 1.0), align=(0.5, 1.0), yoffset=-6) for x in menu_items] else: $ menu_items = [x for x in reversed(category_items.get(current_subcategory)) if x.unlocked==True] - $ icon_items = [Transform(x.image, crop=(220, 0, 680, 1200), size=(96, 168), fit="contain", anchor=(0.5, 1.0), align=(0.5, 1.0), yoffset=-6) for x in menu_items] + $ icon_items = [create_wardrobe_icon(x.image, crop=(220, 0, 680, 1200), size=(96, 168), fit="contain", anchor=(0.5, 1.0), align=(0.5, 1.0), yoffset=-6) for x in menu_items] else: $ menu_items = [x for x in category_items.get(current_subcategory) if x.unlocked==True] - $ icon_items = [Transform(x.icon, size=(96, 96), fit="contain", anchor=(0.5, 0.5), align=(0.5, 0.5)) for x in menu_items] + $ icon_items = [create_wardrobe_icon(x.icon) for x in menu_items] $ current_item = char_active.get_equipped_item(menu_items) elif _choice[0] == "equip": @@ -310,7 +314,7 @@ label wardrobe_menu(): outfit.is_stale() menu_items = [x for x in category_items.get(current_subcategory) if x.unlocked==True] - icon_items = [Transform(x.icon, size=(96, 96), fit="contain", anchor=(0.5, 0.5), align=(0.5, 0.5)) for x in menu_items] + icon_items = [create_wardrobe_icon(x.icon) for x in menu_items] elif _choice[0] == "touch": if wardrobe_check_touch(_choice[1]): @@ -346,9 +350,9 @@ label wardrobe_menu(): char_active.create_outfit() renpy.notify("Outfit Saved.") - menu_items = [x for x in reversed(category_items.get(current_subcategory)) if x.unlocked==True] - icon_items = [Transform(x.image, crop=(220, 0, 680, 1200), size=(96, 168), fit="contain", anchor=(0.5, 1.0), align=(0.5, 1.0), yoffset=-6) for x in menu_items] - current_item = next( (x for x in char_active.outfits if _outfit == x), None) + menu_items = [x for x in reversed(category_items.get(current_subcategory)) if x.unlocked==True] + icon_items = [create_wardrobe_icon(x.image, crop=(220, 0, 680, 1200), size=(96, 168), fit="contain", anchor=(0.5, 1.0), align=(0.5, 1.0), yoffset=-6) for x in menu_items] + current_item = next( (x for x in char_active.outfits if _outfit == x), None) elif _choice[0] == "deloutfit": python: @@ -357,7 +361,7 @@ label wardrobe_menu(): if _confirmed: _choice[1].delete() menu_items = [x for x in reversed(category_items.get(current_subcategory)) if x.unlocked==True] - icon_items = [Transform(x.image, crop=(220, 0, 680, 1200), size=(96, 168), fit="contain", anchor=(0.5, 1.0), align=(0.5, 1.0), yoffset=-6) for x in menu_items] + icon_items = [create_wardrobe_icon(x.image, crop=(220, 0, 680, 1200), size=(96, 168), fit="contain", anchor=(0.5, 1.0), align=(0.5, 1.0), yoffset=-6) for x in menu_items] renpy.notify("Outfit Deleted.") elif _choice[0] == "export":