milo perf
This commit is contained in:
@@ -150,7 +150,7 @@ UI:setPage(page)
|
||||
Event.onInterval(5, function()
|
||||
if not Milo:isCraftingPaused() and context.storage:isOnline() then
|
||||
Milo:resetCraftingStatus()
|
||||
Milo:refreshItems()
|
||||
--Milo:refreshItems()
|
||||
|
||||
for _, task in ipairs(context.tasks) do
|
||||
local s, m = pcall(function() task:cycle(context) end)
|
||||
|
||||
@@ -60,6 +60,7 @@ local page = UI.Page {
|
||||
{ heading = ' Qty', key = 'count' , width = 4, justify = 'right' },
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
},
|
||||
values = { },
|
||||
sortColumn = 'displayName',
|
||||
help = '^(s)tack, ^(a)ll'
|
||||
},
|
||||
@@ -103,17 +104,6 @@ local page = UI.Page {
|
||||
[ 'control-a' ] = 'eject_all',
|
||||
|
||||
q = 'quit',
|
||||
|
||||
[ 'control-1' ] = 'eject_1',
|
||||
[ 'control-2' ] = 'eject_1',
|
||||
[ 'control-3' ] = 'eject_1',
|
||||
[ 'control-4' ] = 'eject_1',
|
||||
[ 'control-5' ] = 'eject_1',
|
||||
[ 'control-6' ] = 'eject_1',
|
||||
[ 'control-7' ] = 'eject_1',
|
||||
[ 'control-8' ] = 'eject_1',
|
||||
[ 'control-9' ] = 'eject_1',
|
||||
[ 'control-0' ] = 'eject_1',
|
||||
},
|
||||
displayMode = 0,
|
||||
}
|
||||
@@ -178,10 +168,6 @@ debug('got response')
|
||||
return response
|
||||
end
|
||||
|
||||
function page.statusBar:draw()
|
||||
return UI.Window.draw(self)
|
||||
end
|
||||
|
||||
function page.grid:getRowTextColor(row, selected)
|
||||
if row.is_craftable then
|
||||
return colors.yellow
|
||||
@@ -195,12 +181,6 @@ end
|
||||
function page.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.count = row.count > 0 and Util.toBytes(row.count) or ''
|
||||
if row.low then
|
||||
row.low = Util.toBytes(row.low)
|
||||
end
|
||||
if row.limit then
|
||||
row.limit = Util.toBytes(row.limit)
|
||||
end
|
||||
return row
|
||||
end
|
||||
|
||||
@@ -224,6 +204,7 @@ function page:eventHandler(event)
|
||||
local item = self.grid:getSelected()
|
||||
if item then
|
||||
self:setStatus('requesting stack ...')
|
||||
-- TODO: send a stack request - have server figure out stack size
|
||||
local response = self:sendRequest({ request = 'transfer', item = item, count = 64 })
|
||||
item.count = response.count
|
||||
self.grid:draw()
|
||||
@@ -233,6 +214,7 @@ function page:eventHandler(event)
|
||||
local item = self.grid:getSelected()
|
||||
if item then
|
||||
self:setStatus('requesting all ...')
|
||||
-- TODO: let server figure out count
|
||||
local response = self:sendRequest({ request = 'transfer', item = item, count = item.count })
|
||||
item.count = response.count
|
||||
self.grid:draw()
|
||||
@@ -264,7 +246,6 @@ function page:eventHandler(event)
|
||||
[1] = 'I',
|
||||
[2] = 'C',
|
||||
}
|
||||
|
||||
event.button.value = (event.button.value + 1) % 3
|
||||
self.displayMode = event.button.value
|
||||
event.button.text = values[event.button.value]
|
||||
@@ -306,13 +287,17 @@ function page:applyFilter()
|
||||
self.grid:setValues(t)
|
||||
end
|
||||
|
||||
_G.p4 = Event
|
||||
|
||||
debug(options.slot)
|
||||
if options.slot.value then
|
||||
debug('Transfer items initialized')
|
||||
Event.addRoutine(function()
|
||||
while true do
|
||||
debug('sleeping')
|
||||
os.sleep(1.5)
|
||||
local neural = device.neuralInterface
|
||||
debug(neural)
|
||||
if neural and neural.getInventory then
|
||||
local item = neural.getInventory().getItem(options.slot.value)
|
||||
if item then
|
||||
@@ -321,6 +306,8 @@ if options.slot.value then
|
||||
-- local item =
|
||||
-- TODO: update count for this one item
|
||||
-- page.grid:draw() page:sync()
|
||||
else
|
||||
debug('empty')
|
||||
end
|
||||
else
|
||||
debug('missing Introspection module')
|
||||
|
||||
@@ -16,6 +16,8 @@ function Storage:init(args)
|
||||
listCount = 0,
|
||||
activity = { },
|
||||
storageOnline = true,
|
||||
hits = 0,
|
||||
misses = 0,
|
||||
}
|
||||
Util.merge(self, defaults)
|
||||
Util.merge(self, args)
|
||||
@@ -29,6 +31,7 @@ debug('%s: %s', e, tostring(dev))
|
||||
end)
|
||||
Event.onInterval(15, function()
|
||||
self:showStorage()
|
||||
debug('STORAGE: cache: %d/%d', self.hits, self.misses)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -43,7 +46,7 @@ function Storage:showStorage()
|
||||
if #t > 0 then
|
||||
debug('Storage:')
|
||||
for _, k in pairs(t) do
|
||||
debug(' %s: %s', online and ' online' or 'offline', k)
|
||||
debug(' offline: ' .. k)
|
||||
end
|
||||
debug('')
|
||||
end
|
||||
@@ -71,6 +74,7 @@ function Storage:initStorage()
|
||||
elseif device[k] and device[k].list and device[k].size and device[k].pullItems then
|
||||
v.adapter = InventoryAdapter.wrap({ side = k })
|
||||
v.adapter.online = true
|
||||
v.adapter.dirty = true
|
||||
end
|
||||
if v.mtype == 'storage' then
|
||||
online = online and not not (v.adapter and v.adapter.online)
|
||||
@@ -132,6 +136,10 @@ end
|
||||
|
||||
function Storage:refresh(throttle)
|
||||
self.dirty = true
|
||||
debug('STORAGE: Forcing full refresh')
|
||||
for _, adapter in self:onlineAdapters() do
|
||||
adapter.dirty = true
|
||||
end
|
||||
return self:listItems(throttle)
|
||||
end
|
||||
|
||||
@@ -144,33 +152,35 @@ self.listCount = self.listCount + 1
|
||||
--debug(self.listCount)
|
||||
|
||||
-- todo: only listItems from dirty remotes
|
||||
|
||||
local ct = os.clock()
|
||||
local cache = { }
|
||||
local items = { }
|
||||
throttle = throttle or Util.throttle()
|
||||
|
||||
for _, adapter in self:onlineAdapters() do
|
||||
adapter:listItems(throttle)
|
||||
if adapter.dirty then
|
||||
debug('STORAGE: refresh: ' .. adapter.name)
|
||||
adapter:listItems(throttle)
|
||||
adapter.dirty = false
|
||||
end
|
||||
local rcache = adapter.cache or { }
|
||||
|
||||
-- TODO: add a method in each adapter that only updates a passed cache
|
||||
for key,v in pairs(rcache) do
|
||||
if v.count > 0 then
|
||||
local entry = cache[key]
|
||||
if not entry then
|
||||
entry = Util.shallowCopy(v)
|
||||
entry.count = v.count
|
||||
entry.key = key
|
||||
cache[key] = entry
|
||||
table.insert(items, entry)
|
||||
else
|
||||
entry.count = entry.count + v.count
|
||||
end
|
||||
|
||||
throttle()
|
||||
local entry = cache[key]
|
||||
if not entry then
|
||||
entry = Util.shallowCopy(v)
|
||||
entry.count = v.count
|
||||
entry.key = key
|
||||
cache[key] = entry
|
||||
table.insert(items, entry)
|
||||
else
|
||||
entry.count = entry.count + v.count
|
||||
end
|
||||
|
||||
throttle()
|
||||
end
|
||||
end
|
||||
debug('STORAGE: refresh in ' .. (os.clock() - ct))
|
||||
|
||||
self.dirty = false
|
||||
self.cache = cache
|
||||
@@ -185,6 +195,29 @@ end
|
||||
function Storage:provide(item, qty, slot, direction)
|
||||
local total = 0
|
||||
|
||||
local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
||||
for _, adapter in self:onlineAdapters() do
|
||||
if adapter.cache and adapter.cache[key] then
|
||||
local amount = adapter:provide(item, qty, slot, direction or self.localName)
|
||||
if amount > 0 then
|
||||
self.hits = self.hits + 1
|
||||
debug('EXT: %s(%d): %s -> %s%s',
|
||||
item.name, amount, adapter.name, direction or self.localName,
|
||||
slot and string.format('[%d]', slot) or '')
|
||||
self.dirty = true
|
||||
adapter.dirty = true
|
||||
end
|
||||
qty = qty - amount
|
||||
total = total + amount
|
||||
if qty <= 0 then
|
||||
return total
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
debug('miss: %s - %d', key, qty)
|
||||
self.misses = self.misses + 1
|
||||
|
||||
for _, adapter in self:onlineAdapters() do
|
||||
local amount = adapter:provide(item, qty, slot, direction or self.localName)
|
||||
if amount > 0 then
|
||||
@@ -241,6 +274,14 @@ debug('INS: %s(%d): %s[%d] -> %s',
|
||||
adapter.dirty = true
|
||||
local entry = self.activity[key] or 0
|
||||
self.activity[key] = entry + amount
|
||||
|
||||
--[[
|
||||
local cached = adapter.cache[key]
|
||||
if cached then
|
||||
cached.count = cached.count + amount
|
||||
else
|
||||
end
|
||||
]]
|
||||
end
|
||||
qty = qty - amount
|
||||
total = total + amount
|
||||
|
||||
@@ -6,6 +6,7 @@ local Autocraft = {
|
||||
priority = 100,
|
||||
}
|
||||
|
||||
-- TODO: fix/test
|
||||
function Autocraft:cycle(context)
|
||||
local list = { }
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ local device = _G.device
|
||||
|
||||
local context = Milo:getContext()
|
||||
|
||||
-- TODO: allow change of machine
|
||||
|
||||
local itemPage = UI.Page {
|
||||
titleBar = UI.TitleBar {
|
||||
title = 'Limit Resource',
|
||||
|
||||
@@ -89,23 +89,15 @@ local listingPage = UI.Page {
|
||||
accelerators = {
|
||||
r = 'refresh',
|
||||
[ 'control-r' ] = 'refresh',
|
||||
q = 'quit',
|
||||
|
||||
[ 'control-e' ] = 'eject',
|
||||
[ 'control-s' ] = 'eject_stack',
|
||||
[ 'control-a' ] = 'eject_all',
|
||||
|
||||
[ 'control-1' ] = 'eject_1',
|
||||
[ 'control-2' ] = 'eject_1',
|
||||
[ 'control-3' ] = 'eject_1',
|
||||
[ 'control-4' ] = 'eject_1',
|
||||
[ 'control-5' ] = 'eject_1',
|
||||
[ 'control-6' ] = 'eject_1',
|
||||
[ 'control-7' ] = 'eject_1',
|
||||
[ 'control-8' ] = 'eject_1',
|
||||
[ 'control-9' ] = 'eject_1',
|
||||
[ 'control-0' ] = 'eject_1',
|
||||
[ 'control-m' ] = 'machines',
|
||||
[ 'control-l' ] = 'resume',
|
||||
|
||||
q = 'quit',
|
||||
},
|
||||
displayMode = 0,
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ local function client(socket)
|
||||
end
|
||||
debug('remote: ' .. data.request)
|
||||
if data.request == 'list' then
|
||||
local items = Milo:refreshItems()
|
||||
local items = Milo:listItems()
|
||||
Milo:mergeResources(items)
|
||||
socket:write(items)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user