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
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
+4 -4
View File
@@ -54,8 +54,8 @@ EID.UserConfig = {
-- Default = Keyboard.KEY_F2
["HideKey"] = Keyboard.KEY_F2,
-- Set the controller binding to toggle the descriptions
-- Use the Controller enum at the top of this file, or a number
-- Of note are Controller.STICK_LEFT and Controller.STICK_RIGHT, which aren't used in-game with default controls
-- 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 (pushing the sticks in), which aren't used in-game with default controls
-- Default = none (-1)
["HideButton"] = -1,
-- 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
["CraftingResultKey"] = Keyboard.KEY_F4,
-- 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
-- Of note are Controller.STICK_LEFT and Controller.STICK_RIGHT, which aren't used in-game with default controls
-- 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 (pushing the sticks in), which aren't used in-game with default controls
-- Default = none (-1)
["CraftingResultButton"] = -1,
+1 -1
View File
@@ -8,7 +8,7 @@ local game = Game()
require("eid_config")
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.DefaultConfig.Version = EID.Config.Version
EID.isHidden = false