Skip to content

Commit

Permalink
fixup! cache available recipe list in craft menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mischief committed May 31, 2024
1 parent 7a5c138 commit b1a30d2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 4 additions & 2 deletions 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 @@ -4124,7 +4124,9 @@ class Character : public Creature, public visitable
// is recalculated every turn in Character::recalculate_enchantment_cache
pimpl<enchant_cache> enchantment_cache;

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

Expand Down
16 changes: 8 additions & 8 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,21 +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( cached_recipe_subset->size() > 0 ) {
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() ) );
}

cached_recipe_subset->include( res );

return res;
return *cached_recipe_subset;
}

std::set<itype_id> Character::get_books_for_recipe( const inventory &crafting_inv,
Expand Down
2 changes: 0 additions & 2 deletions src/crafting_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2031,8 +2031,6 @@ 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 b1a30d2

Please sign in to comment.