bugfix builder - refined storage performance

This commit is contained in:
kepler155c@gmail.com 2017-04-14 23:41:04 -04:00
parent 60487d951d
commit dc555a0b1e
5 changed files with 120 additions and 76 deletions

View File

@ -96,12 +96,14 @@ function subDB:seedDB()
dmg = 0, dmg = 0,
id = "minecraft:potatoes", id = "minecraft:potatoes",
}, },
--[[
[ "minecraft:dirt:1" ] = { [ "minecraft:dirt:1" ] = {
sdmg = 0, sdmg = 0,
sid = "minecraft:dirt", sid = "minecraft:dirt",
dmg = 1, dmg = 1,
id = "minecraft:dirt", id = "minecraft:dirt",
}, },
]]--
[ "minecraft:unlit_redstone_torch:0" ] = { [ "minecraft:unlit_redstone_torch:0" ] = {
sdmg = 0, sdmg = 0,
sid = "minecraft:redstone", sid = "minecraft:redstone",
@ -174,6 +176,12 @@ function subDB:seedDB()
dmg = 4, dmg = 4,
id = "minecraft:double_wooden_slab", id = "minecraft:double_wooden_slab",
}, },
[ "minecraft:double_wooden_slab:5" ] = {
sdmg = 5,
sid = "minecraft:planks",
dmg = 5,
id = "minecraft:double_wooden_slab",
},
[ "minecraft:lit_redstone_lamp:0" ] = { [ "minecraft:lit_redstone_lamp:0" ] = {
sdmg = 0, sdmg = 0,
sid = "minecraft:redstone_lamp", sid = "minecraft:redstone_lamp",
@ -186,12 +194,24 @@ function subDB:seedDB()
dmg = 1, dmg = 1,
id = "minecraft:double_stone_slab", id = "minecraft:double_stone_slab",
}, },
[ "minecraft:double_stone_slab:2" ] = {
sdmg = 0,
sid = "minecraft:planks",
dmg = 2,
id = "minecraft:double_stone_slab",
},
[ "minecraft:double_stone_slab:3" ] = { [ "minecraft:double_stone_slab:3" ] = {
sdmg = 0, sdmg = 0,
sid = "minecraft:cobblestone", sid = "minecraft:cobblestone",
dmg = 3, dmg = 3,
id = "minecraft:double_stone_slab", id = "minecraft:double_stone_slab",
}, },
[ "minecraft:double_stone_slab:4" ] = {
sdmg = 0,
sid = "minecraft:brick_block",
dmg = 4,
id = "minecraft:double_stone_slab",
},
[ "minecraft:double_stone_slab:5" ] = { [ "minecraft:double_stone_slab:5" ] = {
sdmg = 0, sdmg = 0,
sid = "minecraft:stonebrick", sid = "minecraft:stonebrick",
@ -826,11 +846,11 @@ function Builder:resupply()
turtle.setHeading(0) turtle.setHeading(0)
self:autocraft(supplies) self:autocraft(supplies)
Logger.log('builder', 'Waiting for supplies') Logger.log('builder', 'Waiting for supplies')
supplyPage.grid:setValues(supplies) supplyPage:setSupplies(supplies)
UI:setPage('supply') UI:setPage('supply')
end end
end end
function Builder:placeDown(slot) function Builder:placeDown(slot)
return turtle.placeDown(slot.index) return turtle.placeDown(slot.index)
end end
@ -1346,8 +1366,10 @@ function Builder:build()
print('failed to place block') print('failed to place block')
end end
end end
self:saveProgress(self.index+1)
elseif (i % 50) == 0 then -- is Air
os.sleep(0) -- sleep in case there are a large # of skipped blocks
end end
self:saveProgress(self.index+1)
if turtle.abort then if turtle.abort then
turtle.status = 'aborting' turtle.status = 'aborting'
@ -1445,8 +1467,7 @@ substitutionPage = UI.Page({
{ text = 'Air', event = 'air', help = 'Air' }, { text = 'Air', event = 'air', help = 'Air' },
}, },
}), }),
inName = UI.Text({ y = 4, width = UI.term.width }), info = UI.Window({ y = 4, width = UI.term.width, height = 3 }),
outName = UI.Text({ y = 5, width = UI.term.width }),
grid = UI.ScrollingGrid({ grid = UI.ScrollingGrid({
columns = { columns = {
{ heading = 'Name', key = 'name', width = UI.term.width-9 }, { heading = 'Name', key = 'name', width = UI.term.width-9 },
@ -1471,19 +1492,20 @@ substitutionPage.menuBar:add({
}) })
}) })
function substitutionPage:draw() function substitutionPage.info:draw()
local inName = blocks.blockDB:getName(self.sub.id, self.sub.dmg) local sub = self.parent.sub
self.inName.value = ' Replace ' .. inName local inName = blocks.blockDB:getName(sub.id, sub.dmg)
local outName = ''
self.outName.value = '' if sub.sid then
if self.sub.sid then outName = blocks.blockDB:getName(sub.sid, sub.sdmg)
local outName = blocks.blockDB:getName(self.sub.sid, self.sub.sdmg)
self.outName.value = ' With ' .. outName
end end
--self.grid:adjustWidth() self:clear()
UI.Page.draw(self) self:setCursorPos(1, 1)
self:print(' Replace ' .. inName .. '\n')
self:print(' ' .. sub.id .. ':' .. sub.dmg .. '\n', nil, colors.yellow)
self:print(' With ' .. outName)
end end
function substitutionPage:enable() function substitutionPage:enable()
@ -1529,7 +1551,7 @@ function substitutionPage:eventHandler(event)
end end
self:applySubstitute(event.selected.id, event.selected.dmg) self:applySubstitute(event.selected.id, event.selected.dmg)
self:draw() self.info:draw()
elseif event.type == 'text_change' then elseif event.type == 'text_change' then
local text = event.text local text = event.text
@ -1594,11 +1616,10 @@ supplyPage = UI.Page({
}), }),
grid = UI.Grid({ grid = UI.Grid({
columns = { columns = {
{ heading = 'Slot', key = 'index', width = 4 }, { heading = 'Name', key = 'name', width = UI.term.width - 7 },
{ heading = 'Name', key = 'name', width = UI.term.width-12 }, { heading = 'Need', key = 'need', width = 4 },
{ heading = 'Need', key = 'need', width = 4 },
}, },
sortColumn = 'index', sortColumn = 'name',
y = 3, y = 3,
width = UI.term.width, width = UI.term.width,
height = UI.term.height - 3 height = UI.term.height - 3
@ -1672,14 +1693,30 @@ end
function supplyPage:disable() function supplyPage:disable()
Event.cancelNamedTimer('supplyRefresh') Event.cancelNamedTimer('supplyRefresh')
end end
function supplyPage:setSupplies(supplies)
local t = { }
for _,s in pairs(supplies) do
local key = s.id .. ':' .. s.dmg
local entry = t[key]
if not entry then
entry = Util.shallowCopy(s)
t[key] = entry
else
entry.need = entry.need + s.need
end
end
self.grid:setValues(t)
end
function supplyPage:refresh() function supplyPage:refresh()
self.statusBar:timedStatus('Refreshed ', 3) self.statusBar:timedStatus('Refreshed ', 3)
local t = Builder:getSupplies() local supplies = Builder:getSupplies()
if #t == 0 then if #supplies == 0 then
Builder:build() Builder:build()
else else
self.grid:setValues(t) self:setSupplies(supplies)
self.grid:draw() self.grid:draw()
end end
end end
@ -1799,13 +1836,13 @@ function listingPage:refresh()
local block = blocks.blockDB:lookup(b.id, b.dmg) local block = blocks.blockDB:lookup(b.id, b.dmg)
if not block then if not block then
blocks.blockDB:add(b.id, b.dmg, item.name, b.id) blocks.blockDB:add(b.id, b.dmg, item.name, b.id)
elseif not blocks.name and item.name then elseif not block.name and item.name then
blocks.blockDB:add(b.id, b.dmg, item.name) blocks.blockDB:add(b.id, b.dmg, item.name, b.id)
end end
b.name = item.name b.name = item.name
b.qty = item.qty b.qty = item.qty
b.is_craftable = item.is_craftable b.is_craftable = item.is_craftable
elseif not b.name then else
b.name = blocks.blockDB:getName(b.id, b.dmg) b.name = blocks.blockDB:getName(b.id, b.dmg)
end end
end end

View File

@ -1,6 +1,5 @@
require = requireInjector(getfenv(1)) require = requireInjector(getfenv(1))
local Terminal = require('terminal') local Terminal = require('terminal')
local process = require('process')
local args = { ... } local args = { ... }
local mon = device[table.remove(args, 1) or 'monitor'] local mon = device[table.remove(args, 1) or 'monitor']
@ -15,7 +14,7 @@ mon.setCursorPos(1, 1)
local oterm = Terminal.copy(term.current()) local oterm = Terminal.copy(term.current())
Terminal.mirror(term.current(), mon) Terminal.mirror(term.current(), mon)
term.current().getSize = function() return mon.getSize() end term.current().getSize = mon.getSize
if #args > 0 then if #args > 0 then
shell.run(unpack(args)) shell.run(unpack(args))

View File

@ -11,6 +11,9 @@ end
multishell.setTitle(multishell.getCurrent(), 'Storage Manager') multishell.setTitle(multishell.getCurrent(), 'Storage Manager')
-- refined storage is slooow
local cache = { }
-- Strip off color prefix -- Strip off color prefix
local function safeString(text) local function safeString(text)
@ -29,6 +32,25 @@ local function safeString(text)
return text return text
end end
function getItemDetails(item)
local key = table.concat({ item.name, item.damage, item.nbtHash }, ':')
local detail = cache[key]
if not detail then
detail = controller.findItem(item)
if detail then
Util.merge(detail, detail.getMetadata())
detail.displayName = safeString(detail.displayName)
if detail.maxDamage and detail.maxDamage > 0 and detail.damage > 0 then
detail.displayName = detail.displayName .. ' (damaged)'
end
detail.lname = detail.displayName:lower()
cache[key] = detail
end
end
return detail
end
function listItems() function listItems()
local items = { } local items = { }
local list local list
@ -38,17 +60,10 @@ function listItems()
end) end)
if list then if list then
for k,v in pairs(list) do for _,v in pairs(list) do
local item = controller.findItem(v) local item = getItemDetails(v)
if item then if item then
Util.merge(item, item.getMetadata()) item.count = v.count
item.displayName = safeString(item.displayName)
if item.maxDamage and item.maxDamage > 0 and item.damage > 0 then
item.displayName = item.displayName .. ' (damaged)'
end
item.lname = item.displayName:lower()
table.insert(items, item) table.insert(items, item)
end end
end end
@ -463,7 +478,11 @@ function listingPage:enable()
end end
function listingPage:refresh() function listingPage:refresh()
local t = os.clock()
self.allItems = listItems() self.allItems = listItems()
debug('list items')
debug(os.clock() - t)
mergeResources(self.allItems) mergeResources(self.allItems)
self:applyFilter() self:applyFilter()
end end

View File

@ -7,7 +7,8 @@ function ChestProvider:init(args)
args = args or { } args = args or { }
self.stacks = {} self.items = { } -- consolidated item info
self.stacks = { } -- raw stack info
self.name = 'chest' self.name = 'chest'
self.direction = args.direction or 'up' self.direction = args.direction or 'up'
self.wrapSide = args.wrapSide or 'bottom' self.wrapSide = args.wrapSide or 'bottom'
@ -21,48 +22,36 @@ end
function ChestProvider:refresh() function ChestProvider:refresh()
if self.p then if self.p then
--self.p.condenseItems() --self.p.condenseItems()
self.items = { }
self.stacks = self.p.list() self.stacks = self.p.list()
local t = { } for k,s in pairs(self.stacks) do
for _,s in pairs(self.stacks) do
s.id = s.name local key = s.name .. ':' .. s.damage
s.dmg = s.damage local entry = self.items[key]
s.qty = s.count if not entry then
local key = s.id .. ':' .. s.dmg local meta = self.p.getItemMeta(k)
if t[key] and t[key].qty < 64 then entry = {
t[key].max_size = t[key].qty id = s.name,
else dmg = s.damage,
t[key] = { name = meta.displayName,
qty = s.qty max_size = meta.maxCount,
qty = 0,
} }
self.items[key] = entry
end end
end entry.qty = entry.qty + s.count
for _,s in ipairs(self.stacks) do
local key = s.id .. ':' .. s.dmg
if t[key].max_size then
s.max_size = t[key].qty
else
s.max_size = 64
end
end end
end end
return self.stacks return self.items
end end
function ChestProvider:getItemInfo(id, dmg) function ChestProvider:getItemInfo(id, dmg)
local item = { id = id, dmg = dmg, qty = 0, max_size = 64 }
for k,stack in pairs(self.stacks) do for key,item in pairs(self.items) do
if stack.id == id and stack.dmg == dmg then if item.id == id and item.dmg == dmg then
local meta = self.p.getItemMeta(k) return item
if meta then
item.name = meta.displayName
item.qty = item.qty + meta.count
item.max_size = meta.maxCount
end
end end
end end
if item.name then
return item
end
end end
function ChestProvider:craft(id, dmg, qty) function ChestProvider:craft(id, dmg, qty)
@ -76,8 +65,8 @@ function ChestProvider:provide(item, qty, slot)
if self.p then if self.p then
self:refresh() self:refresh()
for key,stack in pairs(self.stacks) do for key,stack in pairs(self.stacks) do
if stack.id == item.id and stack.dmg == item.dmg then if stack.name == item.id and stack.damage == item.dmg then
local amount = math.min(qty, stack.qty) local amount = math.min(qty, stack.count)
self.p.pushItems(self.direction, key, amount, slot) self.p.pushItems(self.direction, key, amount, slot)
qty = qty - amount qty = qty - amount
if qty <= 0 then if qty <= 0 then

View File

@ -1481,7 +1481,7 @@ function UI.Grid:adjustWidth()
end end
for _,col in pairs(self.columns) do for _,col in pairs(self.columns) do
for key,row in pairs(self.values) do for key,row in ipairs(self.values) do
row = self:getDisplayValues(row, key) row = self:getDisplayValues(row, key)
local value = row[col.key] local value = row[col.key]
if value then if value then