milo storage perf fix - nwm update

This commit is contained in:
kepler155c@gmail.com
2020-05-16 10:40:49 -06:00
parent bc0cf883b4
commit 0619eee41c
3 changed files with 74 additions and 43 deletions

View File

@@ -520,6 +520,8 @@ local function rawExport(source, target, item, qty, slot)
if amount > 0 then if amount > 0 then
source.lastUpdate = os.clock() source.lastUpdate = os.clock()
target.lastUpdate = os.clock() target.lastUpdate = os.clock()
else
break
end end
end end
qty = qty - amount qty = qty - amount
@@ -551,6 +553,7 @@ function Storage:export(target, slot, count, item)
if amount ~= pcount then if amount ~= pcount then
-- this *should* only happen if cache is out of sync -- this *should* only happen if cache is out of sync
-- out the target is full
self:updateCache(adapter, item, pcount - amount) self:updateCache(adapter, item, pcount - amount)
end end
@@ -561,28 +564,43 @@ function Storage:export(target, slot, count, item)
end end
count = count - amount count = count - amount
total = total + amount total = total + amount
return amount
end end
-- request from adapters with this item -- request from adapters with this item
for _, adapter in self:onlineAdapters() do for _, adapter in self:onlineAdapters() do
local cache = adapter.cache and adapter.cache[key] local cache = adapter.cache and adapter.cache[key]
if cache then if cache then
provide(adapter, math.min(count, cache.count)) local request = math.min(count, cache.count)
local amount = provide(adapter, request)
-- couldn't provide the amount that was requested
-- either the target must be full - or the cache is invalid
if amount ~= request then
break
end
if count <= 0 then if count <= 0 then
return total return total
end end
end end
end end
_G._syslog('STORAGE warning: %s(%d): %s%s %s failed to export', if slot then -- ignore warning when exporting to all slots
item.displayName or item.name, count, self:_sn(target.name), _G._syslog('STORAGE warning: %s(%d): %s%s %s failed to export',
slot and string.format('[%d]', slot) or '[*]', key) item.displayName or item.name, count, self:_sn(target.name),
slot and string.format('[%d]', slot) or '[*]', key)
end
-- TODO: If there are misses when a slot is specified than something is wrong... -- TODO: If there are misses when a slot is specified than something is wrong...
-- The caller should confirm the quantity beforehand -- The caller should confirm the quantity beforehand
-- If no slot and full amount is not exported, then no need to check rest of adapters -- If no slot and full amount is not exported, then no need to check rest of adapters
-- ... so should not reach here -- ... so should not reach here
-- but... there is the case where exporting to all slots of the target
-- this is valid
return total return total
end end

View File

@@ -99,7 +99,6 @@ function Glasses.create(args)
function gterm.setTextScale() end function gterm.setTextScale() end
function gterm.getPosition() return opts.x, opts.y end function gterm.getPosition() return opts.x, opts.y end
function gterm.setVisible() end
function gterm.raise() function gterm.raise()
local g = canvas.addGroup(pos) local g = canvas.addGroup(pos)
init(g) init(g)
@@ -139,10 +138,6 @@ function Glasses.create(args)
gterm.redraw() gterm.redraw()
end end
--gterm.name = opts.name
--gterm.side = opts.name
--gterm.type = 'glasses'
return gterm return gterm
end end

View File

@@ -7,6 +7,7 @@
]] ]]
local Config = require('opus.config') local Config = require('opus.config')
local Event = require('opus.event')
local Glasses = require('neural.glasses') local Glasses = require('neural.glasses')
local Util = require('opus.util') local Util = require('opus.util')
@@ -39,14 +40,26 @@ local events = {
glasses_scroll = 'mouse_scroll', glasses_scroll = 'mouse_scroll',
} }
local function hook(e, eventData) local timer
local x = math.floor(eventData[2] / xs) local function writeConfig()
local y = math.floor(eventData[3] / ys) if timer then
local clicked Event.off(timer)
end
timer = Event.onTimeout(5, function()
_syslog('writing config')
Config.update('nwm', config)
timer = nil
end)
end
Event.on(Util.keys(events), function(e, button, x, y)
x = math.floor(x / xs)
y = math.floor((y - 1) / ys)
if dragging then if dragging then
if e == 'glasses_up' then if e == 'glasses_up' then
dragging = nil dragging = nil
elseif e == 'glasses_drag' then elseif e == 'glasses_drag' then
local dx = x - dragging.ax local dx = x - dragging.ax
local dy = y - dragging.ay local dy = y - dragging.ay
@@ -55,7 +68,7 @@ local function hook(e, eventData)
dragging.tab.wmargs.x = dragging.wx + dx dragging.tab.wmargs.x = dragging.wx + dx
dragging.tab.wmargs.y = dragging.wy + dy dragging.tab.wmargs.y = dragging.wy + dy
Config.update('nwm', config) writeConfig()
end end
return return
end end
@@ -73,7 +86,7 @@ local function hook(e, eventData)
resizing.tab.titleBar.reposition2(resizing.dx, resizing.dy - 1, resizing.dw, 1) resizing.tab.titleBar.reposition2(resizing.dx, resizing.dy - 1, resizing.dw, 1)
resizing.tab.titleBar:draw(resizing.tab.title) resizing.tab.titleBar:draw(resizing.tab.title)
Config.update('nwm', config) writeConfig()
end end
resizing = nil resizing = nil
@@ -92,6 +105,8 @@ local function hook(e, eventData)
return return
end end
local clicked
for _,tab in ipairs(kernel.routines) do for _,tab in ipairs(kernel.routines) do
if tab.gwindow then if tab.gwindow then
local wx, wy = tab.gwindow.getPosition() local wx, wy = tab.gwindow.getPosition()
@@ -102,6 +117,7 @@ local function hook(e, eventData)
x = x - wx x = x - wx
y = y - wy y = y - wy
break break
elseif x >= wx and x <= wx + ww and y == wy then elseif x >= wx and x <= wx + ww and y == wy then
if e == 'glasses_click' then if e == 'glasses_click' then
if x == wx + ww - 1 then if x == wx + ww - 1 then
@@ -113,12 +129,14 @@ local function hook(e, eventData)
else else
dragging = { tab = tab, ax = x, ay = y, wx = wx, wy = wy } dragging = { tab = tab, ax = x, ay = y, wx = wx, wy = wy }
end end
return
elseif e == 'glasses_scroll' then elseif e == 'glasses_scroll' then
tab.wmargs.opacity = Util.clamp(tab.wmargs.opacity - (eventData[1] * 5), 0, 255) tab.wmargs.opacity = Util.clamp(tab.wmargs.opacity - (button * 5), 0, 255)
Config.update('nwm', config) writeConfig()
tab.gwindow.setOpacity(tab.wmargs.opacity) tab.gwindow.setOpacity(tab.wmargs.opacity)
end end
return
end end
end end
end end
@@ -131,10 +149,10 @@ local function hook(e, eventData)
kernel.raise(clicked.uid) kernel.raise(clicked.uid)
end end
clicked:resume(events[e], eventData[1], x, y) clicked:resume(events[e], button, x, y)
end end
return true return true
end end)
function multishell.openTab(env, tab) function multishell.openTab(env, tab)
if not tab.wmargs then if not tab.wmargs then
@@ -148,7 +166,7 @@ function multishell.openTab(env, tab)
args = tab.args, args = tab.args,
} }
table.insert(config.session, tab.wmargs) table.insert(config.session, tab.wmargs)
Config.update('nwm', config) writeConfig()
else else
tab.path = tab.wmargs.path tab.path = tab.wmargs.path
tab.args = tab.wmargs.args tab.args = tab.wmargs.args
@@ -194,7 +212,7 @@ function multishell.openTab(env, tab)
tab.titleBar = titleBar tab.titleBar = titleBar
tab.onExit = tab.onExit or function(self) tab.onExit = tab.onExit or function(self)
Util.removeByValue(config.session, tab.wmargs) Util.removeByValue(config.session, tab.wmargs)
Config.update('nwm', config) writeConfig()
self.gwindow.destroy() self.gwindow.destroy()
self.titleBar.destroy() self.titleBar.destroy()
end end
@@ -211,29 +229,29 @@ function multishell.setTitle(tabId, title)
end end
end end
local hookEvents = Util.keys(events) Event.addRoutine(function()
kernel.hook(hookEvents, hook) term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.clear()
print('Scroll on a titlebar adjusts opacity\n')
print('Run a program')
pcall(function()
while true do
_G.write('> ')
local p = _G.read(nil, nil, shell.complete)
if p and #Util.trim(p) > 0 then
multishell.openTab(_ENV, {
path = 'sys/apps/shell.lua',
args = { p },
})
end
end
end)
Event.exitPullEvents()
end)
for _,v in pairs(config.session) do for _,v in pairs(config.session) do
multishell.openTab(_ENV, { wmargs = v }) multishell.openTab(_ENV, { wmargs = v })
end end
term.setBackgroundColor(colors.black) Event.pullEvents()
term.setTextColor(colors.white)
term.clear()
print('Scroll on a titlebar adjusts opacity\n')
print('Run a program')
pcall(function()
while true do
_G.write('> ')
local p = _G.read(nil, nil, shell.complete)
if p and #Util.trim(p) > 0 then
multishell.openTab(_ENV, {
path = 'sys/apps/shell.lua',
args = { p },
})
end
end
end)
kernel.unhook(hookEvents, hook)