Merge pull request #255 from Buurazu/master

Improve recipe caching
This commit is contained in:
wofsauge authored and GitHub committed 2021-12-05 13:44:09 +01:00
commit 3957d88a37
3 files changed
+26 -22

No files matched your search

+21 -17
View File
@@ -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)
@@ -861,7 +865,7 @@ function EID:handleBagOfCraftingRendering()
mostValuable[i] = itemQuery[i] mostValuable[i] = itemQuery[i]
end end
end end
if (#mostValuable >= 8) then combinations(mostValuable, nil, nil, nil, randResults, newResults) end if (#mostValuable >= 8) then combinations(mostValuable, nil, nil, nil, randResults, newResults) end
--do random pulls for some more recipe choices --do random pulls for some more recipe choices
+4 -4
View File
@@ -54,8 +54,8 @@ EID.UserConfig = {
-- Default = Keyboard.KEY_F2 -- Default = Keyboard.KEY_F2
["HideKey"] = Keyboard.KEY_F2, ["HideKey"] = Keyboard.KEY_F2,
-- Set the controller binding to toggle the descriptions -- Set the controller binding to toggle the descriptions
-- Use the Controller enum at the top of this file, or a number -- Use the Controller names here: https://github.com/wofsauge/External-Item-Descriptions/blob/master/mod_config_menu.lua#L1 or a number
-- Of note are Controller.STICK_LEFT and Controller.STICK_RIGHT, which aren't used in-game with default controls -- Of note are Controller.STICK_LEFT and Controller.STICK_RIGHT (pushing the sticks in), which aren't used in-game with default controls
-- Default = none (-1) -- Default = none (-1)
["HideButton"] = -1, ["HideButton"] = -1,
-- Initial displaystate. Can be used to change the toggle behavior of the "Hide Key" event -- Initial displaystate. Can be used to change the toggle behavior of the "Hide Key" event
@@ -237,8 +237,8 @@ EID.UserConfig = {
-- Default = Keyboard.KEY_F3 -- Default = Keyboard.KEY_F3
["CraftingResultKey"] = Keyboard.KEY_F4, ["CraftingResultKey"] = Keyboard.KEY_F4,
-- Set the controller binding to toggle viewing the description of the item ready to be crafted in the bag -- Set the controller binding to toggle viewing the description of the item ready to be crafted in the bag
-- Use the Controller enum at the top of this file, or a number -- Use the Controller names here: https://github.com/wofsauge/External-Item-Descriptions/blob/master/mod_config_menu.lua#L1 or a number
-- Of note are Controller.STICK_LEFT and Controller.STICK_RIGHT, which aren't used in-game with default controls -- Of note are Controller.STICK_LEFT and Controller.STICK_RIGHT (pushing the sticks in), which aren't used in-game with default controls
-- Default = none (-1) -- Default = none (-1)
["CraftingResultButton"] = -1, ["CraftingResultButton"] = -1,
+1 -1
View File
@@ -8,7 +8,7 @@ local game = Game()
require("eid_config") require("eid_config")
EID.Config = EID.UserConfig EID.Config = EID.UserConfig
EID.Config.Version = "3.2" EID.Config.Version = "3.2" -- note: changing this will reset everyone's settings to default!
EID.ModVersion = "4.1" EID.ModVersion = "4.1"
EID.DefaultConfig.Version = EID.Config.Version EID.DefaultConfig.Version = EID.Config.Version
EID.isHidden = false EID.isHidden = false