improve caching of recipes
This commit is contained in:
1 parent
c400305503
commit
c6a783a922
1 file changed
+20
-16
+20
-16
@@ -333,17 +333,18 @@ function EID:calculateBagOfCrafting(componentsTable)
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
customRNGSeed = Game():GetSeeds():GetStartSeed()
|
customRNGSeed = lastSeedUsed
|
||||||
table.sort(components)
|
table.sort(components)
|
||||||
|
local componentsAsString = table.concat(components, ",")
|
||||||
|
|
||||||
--Check the fixed recipes. Currently, the fixed recipes ignore item unlock status
|
--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
|
if cacheResult ~= nil then
|
||||||
return cacheResult, cacheResult
|
return cacheResult, cacheResult
|
||||||
end
|
end
|
||||||
|
|
||||||
cacheResult = calculatedRecipes[table.concat(components, ",")]
|
cacheResult = calculatedRecipes[componentsAsString]
|
||||||
local lockedResult = lockedRecipes[table.concat(components, ",")]
|
local lockedResult = lockedRecipes[componentsAsString]
|
||||||
|
|
||||||
if cacheResult ~= nil then
|
if cacheResult ~= nil then
|
||||||
return cacheResult, lockedResult
|
return cacheResult, lockedResult
|
||||||
@@ -424,6 +425,7 @@ function EID:calculateBagOfCrafting(componentsTable)
|
|||||||
end
|
end
|
||||||
end
|
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
|
if totalWeight <= 0 then
|
||||||
return 25, 25
|
return 25, 25
|
||||||
end
|
end
|
||||||
@@ -437,12 +439,14 @@ function EID:calculateBagOfCrafting(componentsTable)
|
|||||||
target = target - v
|
target = target - v
|
||||||
if target < 0 then
|
if target < 0 then
|
||||||
if firstOption then
|
if firstOption then
|
||||||
calculatedRecipes[table.concat(components, ",")] = firstOption
|
calculatedRecipes[componentsAsString] = firstOption
|
||||||
lockedRecipes[table.concat(components, ",")] = k
|
lockedRecipes[componentsAsString] = k
|
||||||
return firstOption, k
|
return firstOption, k
|
||||||
else
|
else
|
||||||
--Don't do the 2nd pass if this item is definitely unlocked
|
--Don't do the 2nd pass if this item is definitely unlocked
|
||||||
if EID:isCollectibleUnlockedAnyPool(k) then
|
if EID:isCollectibleUnlockedAnyPool(k) then
|
||||||
|
calculatedRecipes[componentsAsString] = k
|
||||||
|
lockedRecipes[componentsAsString] = k
|
||||||
return k, k
|
return k, k
|
||||||
else
|
else
|
||||||
firstOption = k
|
firstOption = k
|
||||||
@@ -690,6 +694,16 @@ local function getFloorItemsString(showPreviews, roomItems)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function EID:handleBagOfCraftingRendering()
|
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()
|
trackBagHolding()
|
||||||
trackBagActivated()
|
trackBagActivated()
|
||||||
detectBagContentShift()
|
detectBagContentShift()
|
||||||
@@ -730,16 +744,6 @@ function EID:handleBagOfCraftingRendering()
|
|||||||
return false
|
return false
|
||||||
end
|
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
|
--Display the result of the 8 items in our bag
|
||||||
if (showCraftingResult or EID.Config["BagOfCraftingDisplayMode"] == "Preview Only") and #EID.BagItems >= 8 then
|
if (showCraftingResult or EID.Config["BagOfCraftingDisplayMode"] == "Preview Only") and #EID.BagItems >= 8 then
|
||||||
local craftingResult, backupResult = EID:calculateBagOfCrafting(EID.BagItems)
|
local craftingResult, backupResult = EID:calculateBagOfCrafting(EID.BagItems)
|
||||||
|
|||||||
Reference in new issue
Block a user