Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache available recipe list in craft menu #74178

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -3517,7 +3517,7 @@ class Character : public Creature, public visitable
/**
* Return all available recipes for any member of `this` crafter's group. Using `this` inventory.
*/
recipe_subset get_group_available_recipes() const;
recipe_subset &get_group_available_recipes() const;
/**
* Returns the set of book types in crafting_inv that provide the
* given recipe.
Expand Down Expand Up @@ -4123,6 +4123,11 @@ 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;

private:
/* cached recipes, which are invalidated if the turn changes */
mutable time_point cached_recipe_turn;
pimpl<recipe_subset> cached_recipe_subset;
};

Character &get_player_character();
Expand Down
16 changes: 12 additions & 4 deletions src/character_crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <utility>
#include <vector>

#include "cached_options.h"
#include "character.h"
#include "inventory.h"
#include "item.h"
Expand Down Expand Up @@ -181,13 +182,20 @@ recipe_subset Character::get_available_recipes( const inventory &crafting_inv,
return res;
}

recipe_subset Character::get_group_available_recipes() const
recipe_subset &Character::get_group_available_recipes() const
{
recipe_subset res;
if( !test_mode && calendar::turn == cached_recipe_turn && cached_recipe_subset->size() > 0 ) {
return *cached_recipe_subset;
}

cached_recipe_turn = calendar::turn;
cached_recipe_subset->clear();

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

return *cached_recipe_subset;
}

std::set<itype_id> Character::get_books_for_recipe( const inventory &crafting_inv,
Expand Down
Loading