milo performance update
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
local itemDB = require('core.itemDB')
|
local itemDB = require('core.itemDB')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
|
|
||||||
|
local parallel = _G.parallel
|
||||||
|
|
||||||
local ImportTask = {
|
local ImportTask = {
|
||||||
name = 'importer',
|
name = 'importer',
|
||||||
priority = 20,
|
priority = 20,
|
||||||
@@ -11,63 +13,73 @@ local function filter(a)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ImportTask:cycle(context)
|
function ImportTask:cycle(context)
|
||||||
for node in context.storage:filterActive('machine', filter) do
|
local tasks = { }
|
||||||
local s, m = pcall(function()
|
|
||||||
for _, entry in pairs(node.imports) do
|
|
||||||
|
|
||||||
local function itemMatchesFilter(item)
|
for node in context.storage:filterActive('machine', filter) do
|
||||||
if not entry.ignoreDamage and not entry.ignoreNbtHash then
|
table.insert(tasks, function()
|
||||||
local key = itemDB:makeKey(item)
|
local s, m = pcall(function()
|
||||||
return entry.filter[key]
|
for _, entry in pairs(node.imports) do
|
||||||
|
|
||||||
|
local function itemMatchesFilter(item)
|
||||||
|
if not entry.ignoreDamage and not entry.ignoreNbtHash then
|
||||||
|
local key = itemDB:makeKey(item)
|
||||||
|
return entry.filter[key]
|
||||||
|
end
|
||||||
|
|
||||||
|
for key in pairs(entry.filter) do
|
||||||
|
local v = itemDB:splitKey(key)
|
||||||
|
if item.name == v.name and
|
||||||
|
(entry.ignoreDamage or item.damage == v.damage) and
|
||||||
|
(entry.ignoreNbtHash or item.nbtHash == v.nbtHash) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for key in pairs(entry.filter) do
|
local function matchesFilter(item)
|
||||||
local v = itemDB:splitKey(key)
|
if not entry.filter then
|
||||||
if item.name == v.name and
|
|
||||||
(entry.ignoreDamage or item.damage == v.damage) and
|
|
||||||
(entry.ignoreNbtHash or item.nbtHash == v.nbtHash) then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if entry.blacklist then
|
||||||
|
return not itemMatchesFilter(item)
|
||||||
|
end
|
||||||
|
|
||||||
|
return itemMatchesFilter(item)
|
||||||
|
end
|
||||||
|
|
||||||
|
local list = node.adapter.list()
|
||||||
|
|
||||||
|
local function importSlot(slotNo)
|
||||||
|
local item = itemDB:get(list[slotNo], function()
|
||||||
|
return node.adapter.getItemMeta(slotNo)
|
||||||
|
end)
|
||||||
|
if item and matchesFilter(item) then
|
||||||
|
context.storage:import(node, slotNo, item.count, item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(entry.slot) == 'number' then
|
||||||
|
if list[entry.slot] then
|
||||||
|
importSlot(entry.slot)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for i in pairs(list) do
|
||||||
|
importSlot(i)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
local function matchesFilter(item)
|
if not s and m then
|
||||||
if not entry.filter then
|
_G._debug('IMPORTER error: ' .. m)
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if entry.blacklist then
|
|
||||||
return not itemMatchesFilter(item)
|
|
||||||
end
|
|
||||||
|
|
||||||
return itemMatchesFilter(item)
|
|
||||||
end
|
|
||||||
|
|
||||||
local list = node.adapter.list()
|
|
||||||
|
|
||||||
local function importSlot(slotNo)
|
|
||||||
local item = itemDB:get(list[slotNo], function()
|
|
||||||
return node.adapter.getItemMeta(slotNo)
|
|
||||||
end)
|
|
||||||
if item and matchesFilter(item) then
|
|
||||||
context.storage:import(node, slotNo, item.count, item)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if type(entry.slot) == 'number' then
|
|
||||||
if list[entry.slot] then
|
|
||||||
importSlot(entry.slot)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for i in pairs(list) do
|
|
||||||
importSlot(i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end)
|
end)
|
||||||
if not s and m then
|
end
|
||||||
_G._debug('IMPORTER error: ' .. m)
|
|
||||||
end
|
if #tasks > 0 then
|
||||||
|
parallel.waitForAll(table.unpack(tasks))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -446,7 +446,9 @@ Unlocked Slots : %d of %d (%d%%)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
UI:setPage(page)
|
Event.onTimeout(0, function()
|
||||||
|
UI:setPage(page)
|
||||||
|
end)
|
||||||
return page
|
return page
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
local Event = require('event')
|
||||||
local Milo = require('milo')
|
local Milo = require('milo')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
|
|
||||||
@@ -76,10 +77,14 @@ end
|
|||||||
|
|
||||||
function task:cycle(context)
|
function task:cycle(context)
|
||||||
for node in context.storage:filterActive('trashcan', filter) do
|
for node in context.storage:filterActive('trashcan', filter) do
|
||||||
for k in pairs(node.adapter.list()) do
|
Event.onTimeout(0, function() -- run on a background thread
|
||||||
local direction = node.dropDirection or 'down'
|
pcall(function()
|
||||||
node.adapter.drop(k, 64, direction)
|
for k in pairs(node.adapter.list()) do
|
||||||
end
|
local direction = node.dropDirection or 'down'
|
||||||
|
node.adapter.drop(k, 64, direction)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user