From c6a783a922d1ba338304e0509a9bdb56b0164f4b Mon Sep 17 00:00:00 2001 From: Buurazu Date: Sun, 5 Dec 2021 00:29:19 -0500 Subject: [PATCH] improve caching of recipes --- eid_bagofcrafting.lua | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/eid_bagofcrafting.lua b/eid_bagofcrafting.lua index fbc70d87..649aeb5f 100644 --- a/eid_bagofcrafting.lua +++ b/eid_bagofcrafting.lua @@ -333,17 +333,18 @@ function EID:calculateBagOfCrafting(componentsTable) return 0 end - customRNGSeed = Game():GetSeeds():GetStartSeed() + customRNGSeed = lastSeedUsed table.sort(components) + local componentsAsString = table.concat(components, ",") --Check the fixed recipes. Currently, the fixed recipes ignore item unlock status - local cacheResult = EID.XMLRecipes[table.concat(components, ",")] + local cacheResult = EID.XMLRecipes[componentsAsString] if cacheResult ~= nil then return cacheResult, cacheResult end - cacheResult = calculatedRecipes[table.concat(components, ",")] - local lockedResult = lockedRecipes[table.concat(components, ",")] + cacheResult = calculatedRecipes[componentsAsString] + local lockedResult = lockedRecipes[componentsAsString] if cacheResult ~= nil then return cacheResult, lockedResult @@ -424,6 +425,7 @@ function EID:calculateBagOfCrafting(componentsTable) end end end + --unsure if this emergency Breakfast would ever occur, without massively modified item pools at least, but it's in the game's code if totalWeight <= 0 then return 25, 25 end @@ -437,12 +439,14 @@ function EID:calculateBagOfCrafting(componentsTable) target = target - v if target < 0 then if firstOption then - calculatedRecipes[table.concat(components, ",")] = firstOption - lockedRecipes[table.concat(components, ",")] = k + calculatedRecipes[componentsAsString] = firstOption + lockedRecipes[componentsAsString] = k return firstOption, k else --Don't do the 2nd pass if this item is definitely unlocked if EID:isCollectibleUnlockedAnyPool(k) then + calculatedRecipes[componentsAsString] = k + lockedRecipes[componentsAsString] = k return k, k else firstOption = k @@ -690,6 +694,16 @@ local function getFloorItemsString(showPreviews, roomItems) end function EID:handleBagOfCraftingRendering() + local curSeed = Game():GetSeeds():GetStartSeed() + --reset our calculated recipes when the game seed changes + if (curSeed ~= lastSeedUsed) then + calculatedRecipes = {} + lockedRecipes = {} + calcResultCache = {} + randResultCache = {} + end + lastSeedUsed = curSeed + trackBagHolding() trackBagActivated() detectBagContentShift() @@ -730,16 +744,6 @@ function EID:handleBagOfCraftingRendering() return false end - local curSeed = Game():GetSeeds():GetStartSeed() - --reset our calculated recipes when the game seed changes - if (curSeed ~= lastSeedUsed) then - calculatedRecipes = {} - lockedRecipes = {} - calcResultCache = {} - randResultCache = {} - end - lastSeedUsed = curSeed - --Display the result of the 8 items in our bag if (showCraftingResult or EID.Config["BagOfCraftingDisplayMode"] == "Preview Only") and #EID.BagItems >= 8 then local craftingResult, backupResult = EID:calculateBagOfCrafting(EID.BagItems) @@ -861,7 +865,7 @@ function EID:handleBagOfCraftingRendering() mostValuable[i] = itemQuery[i] end end - + if (#mostValuable >= 8) then combinations(mostValuable, nil, nil, nil, randResults, newResults) end --do random pulls for some more recipe choices