Skip to content

Commit

Permalink
cache available recipe list in craft menu
Browse files Browse the repository at this point in the history
when filling in the recipe result pane with information about derived
crafts, get_group_available_recipes and get_available_nested is called
every time the ui is navigated. this makes it slow to scroll through the
recipes or batch craft list, and i don't think is necessary since the
available recipes aren't changing while the menu is open.

stash the available recipes in the character for reuse and then
invalidate the list once we exit the craft menu.

for me, this makes the craft menu much more responsive, especially on
debug/non-lto builds where it is not optimized well.
  • Loading branch information
mischief committed May 31, 2024
1 parent cef5d70 commit 7a5c138
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -4123,6 +4123,9 @@ class Character : public Creature, public visitable
// a cache of all active enchantment values.
// is recalculated every turn in Character::recalculate_enchantment_cache
pimpl<enchant_cache> enchantment_cache;

public:
pimpl<recipe_subset> cached_recipe_subset;
};

Character &get_player_character();
Expand Down
8 changes: 8 additions & 0 deletions src/character_crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,17 @@ recipe_subset Character::get_available_recipes( const inventory &crafting_inv,
recipe_subset Character::get_group_available_recipes() const
{
recipe_subset res;

if( cached_recipe_subset->size() > 0 ) {
return *cached_recipe_subset;
}

for( const Character *guy : get_crafting_group() ) {
res.include( guy->get_available_recipes( crafting_inventory() ) );
}

cached_recipe_subset->include( res );

return res;
}

Expand Down
2 changes: 2 additions & 0 deletions src/crafting_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,8 @@ std::pair<Character *, const recipe *> select_crafter_and_crafting_recipe( int &
}
} while( !done );

crafter->cached_recipe_subset->clear();

return { crafter, chosen };
}

Expand Down

0 comments on commit 7a5c138

Please sign in to comment.