summaryrefslogtreecommitdiff
path: root/src/craftdef.cpp
diff options
context:
space:
mode:
authorHybridDog <ovvv@web.de>2019-04-03 13:59:42 +0200
committerSmallJoker <mk939@ymail.com>2019-05-20 20:59:36 +0200
commit1604b949fde0fcb075709f5b451dde5ba06a27d0 (patch)
treeeff68506331bbba03803b2b056244558362abfde /src/craftdef.cpp
parentb1b40fef16a17f4a6da7d4268af8f0921dbe829c (diff)
downloadminetest-1604b949fde0fcb075709f5b451dde5ba06a27d0.tar.gz
minetest-1604b949fde0fcb075709f5b451dde5ba06a27d0.tar.bz2
minetest-1604b949fde0fcb075709f5b451dde5ba06a27d0.zip
Test crafting hash type only once for a recipe
Diffstat (limited to 'src/craftdef.cpp')
-rw-r--r--src/craftdef.cpp77
1 files changed, 29 insertions, 48 deletions
diff --git a/src/craftdef.cpp b/src/craftdef.cpp
index 04e418e29..64e2f742b 100644
--- a/src/craftdef.cpp
+++ b/src/craftdef.cpp
@@ -407,22 +407,6 @@ void CraftDefinitionShaped::decrementInput(CraftInput &input, std::vector<ItemSt
craftDecrementOrReplaceInput(input, output_replacements, replacements, gamedef);
}
-CraftHashType CraftDefinitionShaped::getHashType() const
-{
- assert(hash_inited); // Pre-condition
- bool has_group = false;
- for (const auto &recipe_name : recipe_names) {
- if (isGroupRecipeStr(recipe_name)) {
- has_group = true;
- break;
- }
- }
- if (has_group)
- return CRAFT_HASH_TYPE_COUNT;
-
- return CRAFT_HASH_TYPE_ITEM_NAMES;
-}
-
u64 CraftDefinitionShaped::getHash(CraftHashType type) const
{
assert(hash_inited); // Pre-condition
@@ -440,6 +424,15 @@ void CraftDefinitionShaped::initHash(IGameDef *gamedef)
return;
hash_inited = true;
recipe_names = craftGetItemNames(recipe, gamedef);
+
+ bool has_group = false;
+ for (const auto &recipe_name : recipe_names) {
+ if (isGroupRecipeStr(recipe_name)) {
+ has_group = true;
+ break;
+ }
+ }
+ hash_type = has_group ? CRAFT_HASH_TYPE_COUNT : CRAFT_HASH_TYPE_ITEM_NAMES;
}
std::string CraftDefinitionShaped::dump() const
@@ -527,22 +520,6 @@ void CraftDefinitionShapeless::decrementInput(CraftInput &input, std::vector<Ite
craftDecrementOrReplaceInput(input, output_replacements, replacements, gamedef);
}
-CraftHashType CraftDefinitionShapeless::getHashType() const
-{
- assert(hash_inited); // Pre-condition
- bool has_group = false;
- for (const auto &recipe_name : recipe_names) {
- if (isGroupRecipeStr(recipe_name)) {
- has_group = true;
- break;
- }
- }
- if (has_group)
- return CRAFT_HASH_TYPE_COUNT;
-
- return CRAFT_HASH_TYPE_ITEM_NAMES;
-}
-
u64 CraftDefinitionShapeless::getHash(CraftHashType type) const
{
assert(hash_inited); // Pre-condition
@@ -558,6 +535,15 @@ void CraftDefinitionShapeless::initHash(IGameDef *gamedef)
hash_inited = true;
recipe_names = craftGetItemNames(recipe, gamedef);
std::sort(recipe_names.begin(), recipe_names.end());
+
+ bool has_group = false;
+ for (const auto &recipe_name : recipe_names) {
+ if (isGroupRecipeStr(recipe_name)) {
+ has_group = true;
+ break;
+ }
+ }
+ hash_type = has_group ? CRAFT_HASH_TYPE_COUNT : CRAFT_HASH_TYPE_ITEM_NAMES;
}
std::string CraftDefinitionShapeless::dump() const
@@ -715,14 +701,6 @@ void CraftDefinitionCooking::decrementInput(CraftInput &input, std::vector<ItemS
craftDecrementOrReplaceInput(input, output_replacements, replacements, gamedef);
}
-CraftHashType CraftDefinitionCooking::getHashType() const
-{
- if (isGroupRecipeStr(recipe_name))
- return CRAFT_HASH_TYPE_COUNT;
-
- return CRAFT_HASH_TYPE_ITEM_NAMES;
-}
-
u64 CraftDefinitionCooking::getHash(CraftHashType type) const
{
if (type == CRAFT_HASH_TYPE_ITEM_NAMES) {
@@ -744,6 +722,11 @@ void CraftDefinitionCooking::initHash(IGameDef *gamedef)
return;
hash_inited = true;
recipe_name = craftGetItemName(recipe, gamedef);
+
+ if (isGroupRecipeStr(recipe_name))
+ hash_type = CRAFT_HASH_TYPE_COUNT;
+ else
+ hash_type = CRAFT_HASH_TYPE_ITEM_NAMES;
}
std::string CraftDefinitionCooking::dump() const
@@ -808,14 +791,6 @@ void CraftDefinitionFuel::decrementInput(CraftInput &input, std::vector<ItemStac
craftDecrementOrReplaceInput(input, output_replacements, replacements, gamedef);
}
-CraftHashType CraftDefinitionFuel::getHashType() const
-{
- if (isGroupRecipeStr(recipe_name))
- return CRAFT_HASH_TYPE_COUNT;
-
- return CRAFT_HASH_TYPE_ITEM_NAMES;
-}
-
u64 CraftDefinitionFuel::getHash(CraftHashType type) const
{
if (type == CRAFT_HASH_TYPE_ITEM_NAMES) {
@@ -837,7 +812,13 @@ void CraftDefinitionFuel::initHash(IGameDef *gamedef)
return;
hash_inited = true;
recipe_name = craftGetItemName(recipe, gamedef);
+
+ if (isGroupRecipeStr(recipe_name))
+ hash_type = CRAFT_HASH_TYPE_COUNT;
+ else
+ hash_type = CRAFT_HASH_TYPE_ITEM_NAMES;
}
+
std::string CraftDefinitionFuel::dump() const
{
std::ostringstream os(std::ios::binary);