From 43841e9d3d6357a8e3ffaecc6865ad2759fe765e Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Tue, 18 May 2021 23:18:24 +0200 Subject: [PATCH] Slightly improved performance of Bag of Crafting calculation --- main.lua | 20 ++++++++++++++------ metadata.xml | 6 +++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/main.lua b/main.lua index d2635234..45388ee2 100644 --- a/main.lua +++ b/main.lua @@ -359,18 +359,27 @@ end local randResultCache = {} EID.bagOfCraftingOffset = 0 +EID.bagOfCraftingCurPickupCount = -1 +EID.bagOfCraftingLastQuery = {} local function handleBagOfCraftingRendering() local results = {} local bagItems = {} -- TODO: Get content of Bag local floorItems = {} - for i, entity in ipairs(Isaac.FindByType(5, -1, -1, true, false)) do - local craftingIDs = EID:getBagOfCraftingID(entity.Variant, entity.SubType) - if craftingIDs ~= nil then - for _,v in ipairs(craftingIDs) do - table.insert(floorItems, v) + local pickups = Isaac.FindByType(5, -1, -1, true, false) + if EID.bagOfCraftingCurPickupCount ~= #pickups then + for i, entity in ipairs(pickups) do + local craftingIDs = EID:getBagOfCraftingID(entity.Variant, entity.SubType) + if craftingIDs ~= nil then + for _,v in ipairs(craftingIDs) do + table.insert(floorItems, v) + end end end + EID.bagOfCraftingLastQuery = floorItems + EID.bagOfCraftingCurPickupCount = #pickups + else + floorItems = EID.bagOfCraftingLastQuery end -- Calculate result from pickups on floor if #floorItems < 8 then @@ -380,7 +389,6 @@ local function handleBagOfCraftingRendering() local queryString = table.concat(floorItems,",") if randResultCache[queryString] == nil then local randResults = {} - for i = 0, 250 do local newTable = {} local tableCopy = {table.unpack(floorItems)} diff --git a/metadata.xml b/metadata.xml index 163ac554..2cfc4f78 100644 --- a/metadata.xml +++ b/metadata.xml @@ -48,7 +48,7 @@ This mod displays detailed information about all items, trinkets, cards, runes a [td]by LuanRoger, NotZin02[/td] [td]by TST_Gogo_, Gothika_47[/td] [td]by Mert Dutal[/td] - [td]by Rickyy[/td] + [td]by Rickyy, Kennyluz[/td] [/tr] [/table] @@ -77,7 +77,7 @@ https://moddingofisaac.com/mod/1079/external-item-descriptions - Nicolas Delvaux for creating an awesome [b]French[/b] language pack - Denkishi and 2G for creating the fantastic [b]Italian[/b] language pack - Lidia Arroyo Purroy for creating the amazing [b]Spanish[/b] language Pack -- Rickyy for creating the incredible [b]Polish[/b] language pack +- Rickyy and Kennyluz for creating the incredible [b]Polish[/b] language pack - Marcelino Cruz for creating the [b]Portuguese[/b] language pack - LuanRoger and NotZin02 for creating the [b]Brazilian - Portuguese[/b] language pack - hell2pay, fly_6, TrJ-VoRoN and Sekaz for creating the [b]Russian[/b] language pack @@ -86,7 +86,7 @@ https://moddingofisaac.com/mod/1079/external-item-descriptions - Jake for the sweet [b]German[/b] language pack - [url=https://steamcommunity.com/id/whytefang/]adc[/url] for creating an awesome new Languagepack and providing ideas for new functionalities - 3.42 + 3.43 Public