diff --git a/components/BasicText.lua b/components/BasicText.lua index ded46b6..8cac3e3 100644 --- a/components/BasicText.lua +++ b/components/BasicText.lua @@ -4,7 +4,7 @@ return Solyd.wrapComponent("BasicText", function(props) local fw = props.width or #props.text - local canvas = useTextCanvas(props.display) + local canvas = useTextCanvas(props.display, fw*2, 1) Solyd.useEffect(function() local text = props.text @@ -19,13 +19,13 @@ text = text .. string.rep(" ", props.width - #text) end end - canvas:write(text, props.x, props.y, props.color or colors.white, props.bg or colors.black) + canvas:write(text, 1, 1, props.color or colors.white, props.bg or colors.black) return function() - canvas:markText(text, props.x, props.y) + canvas:markText(text, 1, 1) end - end, { canvas, props.display, props.align, text, props.color, props.bg, fw }) + end, { canvas, props.display, props.align, props.text, props.color, props.bg, fw }) local x = props.right and props.x-canvas.width+1 or props.x - return nil, { canvas = { canvas, x, props.y } } + return nil, { canvas = { canvas, x*2-1, props.y*3-2 } } end) diff --git a/config.lua b/config.lua index aaca41f..2c1c11b 100644 --- a/config.lua +++ b/config.lua @@ -5,7 +5,7 @@ settings = { hideUnavailableProducts = false, pollFrequency = 30, - categoryCycleFrequency = 20, + categoryCycleFrequency = -1, activityTimeout = 60, }, theme = { diff --git a/core/ShopState.lua b/core/ShopState.lua index d1e438e..4333624 100644 --- a/core/ShopState.lua +++ b/core/ShopState.lua @@ -64,14 +64,14 @@ end end, function() while state.running do - if os.epoch("utc") > state.lastTouched + (state.config.settings.activityTimeout * 1000) then + if state.config.settings.categoryCycleFrequency > 0 and os.epoch("utc") > state.lastTouched + (state.config.settings.activityTimeout * 1000) then state.selectedCategory = state.selectedCategory + 1 if state.selectedCategory > state.numCategories then state.selectedCategory = 1 end state.productsChanged = true end - sleep(state.config.settings.categoryCycleFrequency) + sleep(math.min(1, state.config.settings.categoryCycleFrequency)) end end) end diff --git a/modules/canvas.lua b/modules/canvas.lua index 82c43b4..4cef54a 100644 --- a/modules/canvas.lua +++ b/modules/canvas.lua @@ -335,7 +335,7 @@ local self = setmetatable({__opaque = true}, TextCanvas_mt) self.width = width self.height = height - + self.brand = "TextCanvas" self.canvas = {} for y = 1, height do self.canvas[y] = {} @@ -491,43 +491,75 @@ local queuedDirty = {} local c = 0 for _, other in ipairs(others) do - -- local isPixel = PixelCanvas.is(other) + local ocanvas, ox, oy = other[1], other[2]-1, other[3]-1 + local isPixel = ocanvas.brand ~= "TextCanvas" if ocanvas.allDirty then for y = 1, ocanvas.height do for x = 1, ocanvas.width do - local tx = x+ox - local ty = y+oy - if tx >= 1 and tx <= self.width*2 and ty >= 1 and ty <= self.height*3 then - queuedDirty[ty] = queuedDirty[ty] or {} - queuedDirty[ty][tx] = true - c = c + 1 + if isPixel then + local tx = x+ox + local ty = y+oy + if tx >= 1 and tx <= self.width*2 and ty >= 1 and ty <= self.height*3 then + queuedDirty[ty] = queuedDirty[ty] or {} + queuedDirty[ty][tx] = true + c = c + 1 + end + else + local tx = x*2-1 + ox + local ty = y*3-2 + oy + -- print(ty) + if tx >= 1 and tx <= self.width*2 and ty >= 1 and ty <= self.height*3 then + queuedDirty[ty] = queuedDirty[ty] or {} + queuedDirty[ty][tx] = true + c = c + 1 + end end end end else for y, row in pairs(ocanvas.dirty) do for x, _ in pairs(row) do - -- if isPixel then - local tx = x+ox - local ty = y+oy - if tx >= 1 and tx <= self.width*2 and ty >= 1 and ty <= self.height*3 then - queuedDirty[ty] = queuedDirty[ty] or {} - queuedDirty[ty][tx] = true - c = c + 1 + if isPixel then + local tx = x+ox + local ty = y+oy + if tx >= 1 and tx <= self.width*2 and ty >= 1 and ty <= self.height*3 then + queuedDirty[ty] = queuedDirty[ty] or {} + queuedDirty[ty][tx] = true + c = c + 1 + end + else + local tx = x*2-1 + ox + local ty = y*3-2 + oy + -- print(ty) + if tx >= 1 and tx <= self.width*2 and ty >= 1 and ty <= self.height*3 then + queuedDirty[ty] = queuedDirty[ty] or {} + queuedDirty[ty][tx] = true + c = c + 1 + end + -- print(y) + -- for gayY = y-10,y+10 do + -- if gayY > 1 and gayY <= #ocanvas.dirty then + -- for gayX = x-10,x+10 do + -- if gayX > 1 and gayX <= #row then + -- queuedDirty[y*3] = queuedDirty[y*3] or {} + -- queuedDirty[y*3][x*2] = true + -- queuedDirty[y*3][x*2-1] = true + -- queuedDirty[y*3-1] = queuedDirty[y*3-1] or {} + -- queuedDirty[y*3-1][x*2] = true + -- queuedDirty[y*3-1][x*2-1] = true + -- queuedDirty[y*3-2] = queuedDirty[y*3-2] or {} + -- queuedDirty[y*3-2][x*2] = true + -- queuedDirty[y*3-2][x*2-1] = true + -- end + -- end + -- end + -- end end -- else -- -- TODO: ewwwwwwww - -- queuedDirty[y*3] = queuedDirty[y*3] or {} - -- queuedDirty[y*3][x*2] = true - -- queuedDirty[y*3][x*2-1] = true - -- queuedDirty[y*3-1] = queuedDirty[y*3-1] or {} - -- queuedDirty[y*3-1][x*2] = true - -- queuedDirty[y*3-1][x*2-1] = true - -- queuedDirty[y*3-2] = queuedDirty[y*3-2] or {} - -- queuedDirty[y*3-2][x*2] = true - -- queuedDirty[y*3-2][x*2-1] = true + -- end end end @@ -568,39 +600,62 @@ self.dirty[targetY][targetX] = true end + if self.canvas[targetY].direct[targetX] then + self.canvas[targetY].direct[targetX] = false + self.dirty[targetY][targetX] = true + end break end end t2 = os.epoch("utc") else ---@cast other TextCanvas - local otherRow = otherCanvas.canvas[targetY] - local otherT = otherRow.t[targetX] - local otherC = otherRow.c[targetX] - local otherB = otherRow.b[targetX] - if otherT then - found = true - foundText = true + -- print( targetX .. ", " .. targetY .. ": " .. ox .. ", " .. oy .. " -> " .. x .. ", " .. y) + local ty = ceil((y-oy+1)/3) --ceil(targetY - oy / 3) + local tx = ceil((x-ox+1)/2) --ceil(targetX - ox / 2) + -- print(tx .. " " .. ty) + -- if ty == 1 then + -- print("fuck") + -- print(#otherCanvas.canvas) + -- print(#otherCanvas.canvas[ty].t) + -- sleep(1) + -- end + if otherCanvas.canvas[ty] and otherCanvas.canvas[ty].c[tx] then + -- print("found text") + local otherRow = otherCanvas.canvas[ty] + local otherT = otherRow.t[tx] + local otherC = otherRow.c[tx] + local otherB = otherRow.b[tx] + if otherT then + found = true + foundText = true - local currRow = self.canvas[targetY] - local currT = currRow.t[targetX] - local currC = currRow.c[targetX] - local currB = currRow.b[targetX] + local currRow = self.canvas[targetY] + local currT = currRow.t[targetX] + local currC = currRow.c[targetX] + local currB = currRow.b[targetX] - if otherT ~= currT or otherC ~= currC or otherB ~= currB then - currRow.t[targetX] = otherT - currRow.c[targetX] = otherC - currRow.b[targetX] = otherB - currRow.direct[targetX] = true - self.dirty[targetY][targetX] = false -- Already processed + if otherT ~= currT or otherC ~= currC or otherB ~= currB then + currRow.t[targetX] = otherT + currRow.c[targetX] = otherC + currRow.b[targetX] = otherB + currRow.direct[targetX] = true + self.dirty[targetY][targetX] = false -- Already processed - local dirtyRow = self.dirtyRows[targetY] or {} - local minX, maxX = dirtyRow[1], dirtyRow[2] - minX = minX and min(minX, targetX) or targetX - maxX = maxX and max(maxX, targetX) or targetX - self.dirtyRows[targetY] = { minX, maxX } + local dirtyRow = self.dirtyRows[targetY] or {} + local minX, maxX = dirtyRow[1], dirtyRow[2] + minX = minX and min(minX, targetX) or targetX + maxX = maxX and max(maxX, targetX) or targetX + self.dirtyRows[targetY] = { minX, maxX } + end + + break + else + local currRow = self.canvas[targetY] + currRow.direct[targetX] = false end - - break + else + -- local currRow = self.canvas[targetY] + -- currRow.direct[targetX] = false end end end @@ -608,6 +663,7 @@ if not found then self.pixelCanvas.canvas[y][x] = self.clear self.dirty[targetY][targetX] = true + self.canvas[targetY].direct[targetX] = false end -- if not foundText then diff --git a/modules/hooks/textCanvas.lua b/modules/hooks/textCanvas.lua index bb1032d..6e3b1ca 100644 --- a/modules/hooks/textCanvas.lua +++ b/modules/hooks/textCanvas.lua @@ -26,12 +26,17 @@ local canvases = require("modules.canvas") ---@return TextCanvas -local function useTextCanvas(display) +local function useTextCanvas(display, w, h) local c = Solyd.useMemo(function() - return display.textCanvas - end, {display}) + return canvases.TextCanvas(w, h) + end, {display, w, h}) return c + -- local c = Solyd.useMemo(function() + -- return display.textCanvas + -- end, {display}) + + -- return c end return useTextCanvas diff --git a/profile.csv b/profile.csv new file mode 100644 index 0000000..b07402e --- /dev/null +++ b/profile.csv @@ -0,0 +1,340 @@ +fileline,count,approx. time (s) +-----------------,-----,---------------- +Rect.lua,6.0,5.0,0.0 +BasicText.lua,7.0,4.0,0.0 +BigText.lua,8.0,8.0,0.0 +BigText.lua,9.0,15.0,0.0 +BigText.lua,10.0,211.0,0.0 +Rect.lua,11.0,404.0,0.0 +BigText.lua,12.0,226.0,0.0 +BigText.lua,13.0,13.0,0.0 +BigText.lua,14.0,298.0,0.0 +BigText.lua,15.0,4237.0,5.0 +BigText.lua,16.0,3952.0,8.0 +BasicText.lua,17.0,7.0,0.0 +Rect.lua,18.0,6.0,0.0 +Rect.lua,19.0,6.0,0.0 +Button.lua,20.0,5.0,0.0 +BigText.lua,21.0,12.0,0.0 +BigText.lua,22.0,10.0,0.0 +BigText.lua,23.0,11.0,0.0 +BigText.lua,24.0,11.0,0.0 +BasicText.lua,26.0,4.0,0.0 +BasicText.lua,27.0,4.0,0.0 +aabb.lua,28.0,10.0,0.0 +BigText.lua,29.0,15.0,0.0 +canvas.lua,30.0,38.0,0.0 +solyd.lua,31.0,40.0,0.0 +solyd.lua,32.0,44.0,0.0 +solyd.lua,33.0,28.0,0.0 +solyd.lua,34.0,33.0,0.0 +radon.lua,35.0,6.0,0.0 +canvas.lua,36.0,32.0,0.0 +radon.lua,37.0,7.0,0.0 +canvas.lua,38.0,14.0,0.0 +solyd.lua,39.0,29.0,0.0 +radon.lua,40.0,1.0,0.0 +radon.lua,43.0,1.0,0.0 +radon.lua,47.0,2.0,0.0 +radon.lua,48.0,2.0,0.0 +font.lua,56.0,6.0,0.0 +radon.lua,57.0,32.0,0.0 +font.lua,58.0,24.0,0.0 +font.lua,59.0,24.0,0.0 +font.lua,60.0,24.0,0.0 +font.lua,61.0,24.0,0.0 +radon.lua,62.0,3.0,0.0 +profile.lua,64.0,10.0,1.0 +radon.lua,65.0,3.0,0.0 +font.lua,68.0,11.0,0.0 +font.lua,69.0,56.0,0.0 +font.lua,70.0,38.0,0.0 +radon.lua,71.0,41.0,0.0 +canvas.lua,72.0,46.0,0.0 +canvas.lua,73.0,8.0,0.0 +canvas.lua,74.0,11.0,0.0 +canvas.lua,75.0,8.0,0.0 +canvas.lua,76.0,209.0,0.0 +canvas.lua,77.0,189.0,1.0 +canvas.lua,78.0,27134.0,42.0 +canvas.lua,79.0,26967.0,52.0 +font.lua,80.0,23.0,0.0 +score.lua,81.0,17.0,0.0 +score.lua,82.0,27.0,0.0 +canvas.lua,83.0,15.0,0.0 +radon.lua,84.0,11.0,0.0 +canvas.lua,85.0,24.0,0.0 +radon.lua,86.0,17.0,0.0 +radon.lua,87.0,6.0,0.0 +score.lua,88.0,2.0,0.0 +radon.lua,89.0,5.0,0.0 +radon.lua,90.0,8.0,0.0 +radon.lua,91.0,5.0,0.0 +radon.lua,92.0,2.0,0.0 +radon.lua,93.0,4395.0,5.0 +canvas.lua,95.0,4393.0,12.0 +radon.lua,96.0,5.0,0.0 +radon.lua,97.0,3.0,0.0 +solyd.lua,98.0,13.0,0.0 +radon.lua,99.0,4394.0,12.0 +solyd.lua,100.0,4405.0,11.0 +solyd.lua,101.0,4407.0,6.0 +solyd.lua,102.0,4407.0,8.0 +solyd.lua,103.0,12.0,0.0 +canvas.lua,104.0,4393.0,8.0 +radon.lua,105.0,10.0,0.0 +solyd.lua,106.0,12.0,0.0 +solyd.lua,107.0,13.0,1.0 +radon.lua,111.0,1.0,0.0 +radon.lua,112.0,1.0,0.0 +radon.lua,114.0,1.0,0.0 +score.lua,116.0,183.0,0.0 +solyd.lua,118.0,12.0,0.0 +score.lua,120.0,183.0,0.0 +score.lua,121.0,1364.0,7.0 +score.lua,122.0,1183.0,3.0 +score.lua,123.0,148.0,0.0 +radon.lua,124.0,1.0,0.0 +score.lua,125.0,1035.0,0.0 +score.lua,126.0,1183.0,2.0 +radon.lua,127.0,1.0,0.0 +score.lua,128.0,183.0,4.0 +radon.lua,129.0,1.0,0.0 +radon.lua,130.0,12.0,0.0 +radon.lua,131.0,1.0,0.0 +radon.lua,132.0,12.0,0.0 +radon.lua,133.0,12.0,0.0 +radon.lua,134.0,12.0,0.0 +radon.lua,135.0,12.0,0.0 +solyd.lua,138.0,11.0,0.0 +solyd.lua,139.0,11.0,0.0 +radon.lua,144.0,1.0,0.0 +radon.lua,147.0,1.0,0.0 +radon.lua,148.0,1.0,0.0 +radon.lua,151.0,12.0,0.0 +radon.lua,152.0,1.0,0.0 +radon.lua,153.0,2.0,0.0 +radon.lua,154.0,1.0,0.0 +radon.lua,155.0,1.0,0.0 +radon.lua,156.0,1.0,0.0 +radon.lua,157.0,1.0,0.0 +radon.lua,161.0,1.0,0.0 +radon.lua,166.0,1.0,0.0 +radon.lua,167.0,1.0,0.0 +radon.lua,168.0,1.0,0.0 +radon.lua,171.0,2.0,0.0 +radon.lua,172.0,1.0,0.0 +radon.lua,175.0,1.0,0.0 +radon.lua,176.0,1.0,0.0 +radon.lua,177.0,1.0,0.0 +radon.lua,178.0,1.0,0.0 +radon.lua,179.0,1.0,0.0 +canvas.lua,181.0,210.0,2.0 +canvas.lua,182.0,951.0,2.0 +canvas.lua,183.0,765.0,2.0 +canvas.lua,184.0,248.0,0.0 +radon.lua,185.0,2.0,0.0 +radon.lua,186.0,4.0,0.0 +radon.lua,187.0,5.0,0.0 +canvas.lua,188.0,24.0,0.0 +radon.lua,189.0,1.0,0.0 +solyd.lua,190.0,1.0,0.0 +radon.lua,194.0,2.0,0.0 +solyd.lua,195.0,18.0,0.0 +solyd.lua,196.0,17.0,0.0 +solyd.lua,198.0,17.0,0.0 +solyd.lua,199.0,51.0,0.0 +radon.lua,200.0,35.0,0.0 +radon.lua,201.0,18.0,0.0 +radon.lua,202.0,35.0,0.0 +radon.lua,203.0,1.0,0.0 +solyd.lua,206.0,17.0,1.0 +radon.lua,207.0,7.0,0.0 +radon.lua,208.0,6.0,0.0 +radon.lua,209.0,3.0,0.0 +radon.lua,210.0,14.0,0.0 +radon.lua,211.0,13.0,0.0 +radon.lua,212.0,13.0,0.0 +radon.lua,213.0,13.0,0.0 +radon.lua,214.0,1.0,0.0 +radon.lua,215.0,1.0,0.0 +radon.lua,216.0,1.0,0.0 +solyd.lua,217.0,1.0,0.0 +solyd.lua,220.0,1.0,0.0 +radon.lua,222.0,4.0,0.0 +radon.lua,223.0,2.0,0.0 +radon.lua,224.0,2.0,0.0 +radon.lua,225.0,2.0,0.0 +radon.lua,226.0,2.0,0.0 +radon.lua,227.0,2.0,0.0 +radon.lua,228.0,2.0,0.0 +radon.lua,229.0,2.0,0.0 +radon.lua,230.0,2.0,0.0 +solyd.lua,233.0,17.0,0.0 +radon.lua,234.0,2.0,0.0 +radon.lua,236.0,2.0,0.0 +solyd.lua,237.0,17.0,0.0 +radon.lua,240.0,1.0,0.0 +radon.lua,241.0,18.0,0.0 +radon.lua,242.0,21.0,0.0 +radon.lua,243.0,3.0,0.0 +radon.lua,244.0,3.0,0.0 +radon.lua,245.0,3.0,0.0 +radon.lua,246.0,3.0,0.0 +radon.lua,247.0,1.0,0.0 +radon.lua,248.0,1.0,0.0 +radon.lua,249.0,2.0,0.0 +radon.lua,251.0,2.0,0.0 +radon.lua,252.0,1.0,0.0 +radon.lua,253.0,1.0,0.0 +radon.lua,254.0,1.0,0.0 +radon.lua,258.0,3.0,0.0 +radon.lua,259.0,3.0,0.0 +radon.lua,261.0,6.0,0.0 +radon.lua,262.0,3.0,0.0 +radon.lua,263.0,3.0,0.0 +radon.lua,264.0,3.0,0.0 +radon.lua,265.0,3.0,0.0 +radon.lua,266.0,3.0,0.0 +radon.lua,267.0,3.0,0.0 +radon.lua,268.0,3.0,0.0 +radon.lua,269.0,3.0,0.0 +radon.lua,274.0,3.0,0.0 +radon.lua,275.0,3.0,0.0 +radon.lua,279.0,1.0,0.0 +radon.lua,280.0,1.0,0.0 +radon.lua,281.0,1.0,0.0 +radon.lua,282.0,1.0,0.0 +radon.lua,283.0,1.0,0.0 +radon.lua,284.0,1.0,0.0 +radon.lua,297.0,1.0,0.0 +radon.lua,298.0,1.0,0.0 +radon.lua,299.0,1.0,0.0 +radon.lua,302.0,13.0,0.0 +radon.lua,303.0,12.0,0.0 +radon.lua,308.0,12.0,0.0 +canvas.lua,310.0,1.0,0.0 +radon.lua,311.0,12.0,0.0 +solyd.lua,315.0,18.0,0.0 +solyd.lua,317.0,17.0,0.0 +radon.lua,320.0,1.0,0.0 +solyd.lua,322.0,17.0,0.0 +solyd.lua,323.0,17.0,0.0 +solyd.lua,327.0,17.0,0.0 +solyd.lua,328.0,17.0,0.0 +solyd.lua,329.0,17.0,0.0 +solyd.lua,330.0,17.0,0.0 +solyd.lua,331.0,17.0,0.0 +solyd.lua,332.0,18.0,0.0 +solyd.lua,333.0,18.0,0.0 +radon.lua,334.0,1.0,0.0 +solyd.lua,335.0,17.0,0.0 +solyd.lua,338.0,17.0,0.0 +solyd.lua,340.0,17.0,0.0 +radon.lua,345.0,18.0,0.0 +solyd.lua,346.0,17.0,0.0 +radon.lua,347.0,1.0,0.0 +radon.lua,349.0,1.0,0.0 +radon.lua,351.0,1.0,0.0 +solyd.lua,352.0,18.0,0.0 +solyd.lua,355.0,17.0,0.0 +solyd.lua,358.0,17.0,0.0 +solyd.lua,360.0,11.0,0.0 +canvas.lua,362.0,4.0,0.0 +canvas.lua,363.0,4.0,0.0 +canvas.lua,367.0,4.0,0.0 +canvas.lua,368.0,4.0,0.0 +solyd.lua,370.0,15.0,0.0 +canvas.lua,371.0,105.0,0.0 +canvas.lua,372.0,101.0,1.0 +solyd.lua,373.0,6.0,0.0 +solyd.lua,374.0,5.0,0.0 +solyd.lua,375.0,5.0,0.0 +canvas.lua,376.0,101.0,0.0 +canvas.lua,377.0,101.0,0.0 +canvas.lua,378.0,106.0,0.0 +canvas.lua,379.0,101.0,0.0 +canvas.lua,381.0,9.0,0.0 +solyd.lua,382.0,5.0,0.0 +solyd.lua,384.0,1.0,0.0 +solyd.lua,386.0,1.0,0.0 +solyd.lua,389.0,1.0,0.0 +solyd.lua,393.0,1.0,0.0 +solyd.lua,395.0,1.0,0.0 +solyd.lua,397.0,1.0,0.0 +solyd.lua,398.0,12.0,0.0 +solyd.lua,399.0,11.0,0.0 +solyd.lua,400.0,4.0,0.0 +solyd.lua,401.0,4.0,0.0 +solyd.lua,405.0,4.0,0.0 +solyd.lua,406.0,4.0,0.0 +solyd.lua,407.0,4.0,0.0 +solyd.lua,408.0,7.0,0.0 +solyd.lua,409.0,7.0,0.0 +solyd.lua,410.0,7.0,0.0 +solyd.lua,411.0,7.0,0.0 +solyd.lua,415.0,7.0,0.0 +solyd.lua,416.0,7.0,0.0 +solyd.lua,417.0,7.0,0.0 +solyd.lua,422.0,11.0,0.0 +solyd.lua,426.0,1.0,0.0 +solyd.lua,432.0,1.0,0.0 +solyd.lua,436.0,17.0,0.0 +solyd.lua,439.0,17.0,0.0 +solyd.lua,446.0,1.0,0.0 +solyd.lua,447.0,1.0,0.0 +solyd.lua,448.0,18.0,0.0 +solyd.lua,449.0,17.0,0.0 +solyd.lua,450.0,17.0,0.0 +solyd.lua,451.0,17.0,0.0 +solyd.lua,452.0,18.0,0.0 +solyd.lua,453.0,17.0,0.0 +solyd.lua,454.0,17.0,0.0 +solyd.lua,455.0,113.0,1.0 +solyd.lua,456.0,97.0,0.0 +canvas.lua,457.0,1.0,0.0 +canvas.lua,458.0,7.0,0.0 +solyd.lua,459.0,102.0,0.0 +canvas.lua,460.0,66.0,0.0 +canvas.lua,461.0,60.0,0.0 +solyd.lua,462.0,17.0,0.0 +canvas.lua,468.0,13.0,0.0 +solyd.lua,469.0,29.0,0.0 +canvas.lua,470.0,12.0,0.0 +canvas.lua,472.0,12.0,0.0 +solyd.lua,473.0,17.0,0.0 +solyd.lua,474.0,18.0,0.0 +solyd.lua,475.0,17.0,0.0 +solyd.lua,477.0,61.0,0.0 +solyd.lua,478.0,19817.0,27.0 +canvas.lua,479.0,19769.0,49.0 +canvas.lua,480.0,19769.0,27.0 +solyd.lua,481.0,19770.0,41.0 +canvas.lua,482.0,19769.0,34.0 +canvas.lua,483.0,281.0,0.0 +solyd.lua,484.0,1.0,0.0 +canvas.lua,486.0,12.0,0.0 +canvas.lua,493.0,1.0,0.0 +canvas.lua,494.0,1.0,0.0 +canvas.lua,495.0,4.0,0.0 +canvas.lua,497.0,4.0,0.0 +canvas.lua,498.0,4.0,0.0 +canvas.lua,499.0,233.0,0.0 +canvas.lua,500.0,1664335.0,2739.0 +canvas.lua,501.0,1664106.0,2770.0 +canvas.lua,502.0,1664105.0,2785.0 +canvas.lua,503.0,1664105.0,2925.0 +canvas.lua,504.0,46000.0,69.0 +canvas.lua,505.0,46000.0,75.0 +canvas.lua,506.0,46000.0,70.0 +canvas.lua,509.0,3.0,0.0 +solyd.lua,540.0,1.0,0.0 +solyd.lua,530.0,1.0,0.0 +solyd.lua,532.0,1.0,0.0 +solyd.lua,534.0,1.0,0.0 +solyd.lua,535.0,1.0,0.0 +solyd.lua,536.0,1.0,0.0 +solyd.lua,522.0,1.0,0.0 +solyd.lua,538.0,8.0,0.0 +solyd.lua,549.0,17.0,0.0 +11808.0,second(s),total,(approximately). diff --git a/profile.lua b/profile.lua new file mode 100644 index 0000000..789f172 --- /dev/null +++ b/profile.lua @@ -0,0 +1,102 @@ +--| Profiler module. +--b "Pedro Miller Rabinovitch" +--$Id: prof.lua,v 1.4 2003/10/17 00:17:21 miller Exp $ +--TODO add function call profiling. Some of the skeleton is already in +--- place, but call profiling behaves different, so a couple of new +--- functionalities must be added. +--TODO add methods for proper result retrieval +--TODO use optional clock() function for millisecond precision, if it's +--- available + +local E, I = {}, {} +--& Profiler module. +-- Profiler = E + +--. Keeps track of the hit counts of each item +E.counts = { + line = {} +} +--. These should be inside the _line_ table above. +E.last_line = nil +E.last_time = os.epoch("utc") +E.started, E.ended = nil, nil + +local dontdie = 0 + +--% Activates the profiling system. +--@ [kind] (string) Optional hook kind. For now, only 'line' works, +--- so just avoid it. >: ) +function E:activate( kind ) + kind = kind or 'line' + + local function hook_counter( hk_name, param,... ) + local t = self.counts[hk_name][param] + if t == nil then + t = { count=0, time = 0, name = debug.getinfo(2).short_src } + self.counts[hk_name][param] = t + end + self.counts[hk_name][param].count = + self.counts[hk_name][param].count + 1 + + dontdie = dontdie + 1 + if dontdie > 1000000 then + dontdie = 0 + print("yielding") + self.ended = os.epoch("utc") + E:write_results("line", "profile.txt") + coroutine.yield() + end + + if self.last_line then + local delta = os.epoch("utc") - self.last_time + if delta > 0 then + self.counts[hk_name][self.last_line].time = + self.counts[hk_name][self.last_line].time + delta + self.last_time = os.epoch("utc") + end + end + + self.last_line = param + end + + self.started = os.epoch("utc") + debug.sethook( hook_counter, kind ) +end + +--% Deactivates the profiling system. +--@ [kind] (string) Optional hook kind. For now, only 'line' works, +--- so just avoid it. +function E:deactivate( kind ) + kind = kind or 'line' + self.ended = os.epoch("utc") + debug.sethook( nil, kind ) +end + +--% Prints the results. +--@ [kind] (string) Optional hook... Aah, you got it by now. +--TODO add print output formatting and sorting +function E:print_results( kind ) + kind = kind or 'line' + print( kind, 'count', 'approx. time (s)' ) + print( '----', '-----', '----------------' ) + for i,v in pairs( self.counts[kind] ) do + print( i, v.count, v.time ) + end + print( self.ended - self.started, + ' second(s) total (approximately).' ) +end + +function E:write_results( kind, filename ) + kind = kind or 'line' + local f = io.open( filename, 'w' ) + f:write( 'file', kind, ' count', ' approx. time (s)', '\n' ) + f:write( '-------------', '----', ' -----', ' ----------------', '\n' ) + for i,v in pairs( self.counts[kind] ) do + f:write( v.name, ' ', i, ' ', v.count, ' ', v.time, '\n' ) + end + f:write( self.ended - self.started, + ' second(s) total (approximately).', '\n' ) + f:close() +end + +return E diff --git a/radon.lua b/radon.lua index 12578e2..199c27b 100644 --- a/radon.lua +++ b/radon.lua @@ -113,10 +113,6 @@ local header = BigText { display=display, text="Radon Shop", x=1, y=1, align=theme.formatting.headerAlign, bg=theme.colors.headerBgColor, color = theme.colors.headerColor, width=display.bgCanvas.width } - if props.shopState.productsChanged then - canvas:markRect(1, 1, canvas.width, canvas.height) - end - local flatCanvas = { header } @@ -205,71 +201,75 @@ end local currencyX = 3 - for i = 1, #props.config.currencies do - local symbol = getCurrencySymbol(props.config.currencies[i], productTextSize) - local symbolSize = bigFont:getWidth(symbol)+6 - local bgColor - if i % 4 == 1 then - bgColor = theme.colors.currency1Color - elseif i % 4 == 2 then - bgColor = theme.colors.currency2Color - elseif i % 4 == 3 then - bgColor = theme.colors.currency3Color - elseif i % 4 == 0 then - bgColor = theme.colors.currency4Color - end - table.insert(flatCanvas, Button { - display = display, - align = "center", - text = symbol, - x = currencyX, - y = 1, - bg = bgColor, - color = theme.colors.currencyTextColor, - width = symbolSize, - onClick = function() - props.shopState.selectedCurrency = props.config.currencies[i] - props.shopState.lastTouched = os.epoch("utc") + if #props.config.currencies > 1 then + for i = 1, #props.config.currencies do + local symbol = getCurrencySymbol(props.config.currencies[i], productTextSize) + local symbolSize = bigFont:getWidth(symbol)+6 + local bgColor + if i % 4 == 1 then + bgColor = theme.colors.currency1Color + elseif i % 4 == 2 then + bgColor = theme.colors.currency2Color + elseif i % 4 == 3 then + bgColor = theme.colors.currency3Color + elseif i % 4 == 0 then + bgColor = theme.colors.currency4Color end - }) - currencyX = currencyX + symbolSize + 2 + table.insert(flatCanvas, Button { + display = display, + align = "center", + text = symbol, + x = currencyX, + y = 1, + bg = bgColor, + color = theme.colors.currencyTextColor, + width = symbolSize, + onClick = function() + props.shopState.selectedCurrency = props.config.currencies[i] + props.shopState.lastTouched = os.epoch("utc") + end + }) + currencyX = currencyX + symbolSize + 2 + end end local categoryX = display.bgCanvas.width - 2 - for i = #categories, 1, -1 do - local category = categories[i] - local categoryName = category.name - local categoryColor - if i == selectedCategory then - categoryColor = theme.colors.activeCategoryColor - categoryName = "[" .. categoryName .. "]" - elseif i % 4 == 1 then - categoryColor = theme.colors.category1Color - elseif i % 4 == 2 then - categoryColor = theme.colors.category2Color - elseif i % 4 == 3 then - categoryColor = theme.colors.category3Color - elseif i % 4 == 0 then - categoryColor = theme.colors.category4Color - end - local categoryWidth = smolFont:getWidth(categoryName)+6 - categoryX = categoryX - categoryWidth - 2 - - table.insert(flatCanvas, SmolButton { - display = display, - align = "center", - text = categoryName, - x = categoryX, - y = 4, - bg = categoryColor, - color = theme.colors.categoryTextColor, - width = categoryWidth, - onClick = function() - props.shopState.selectedCategory = i - props.shopState.lastTouched = os.epoch("utc") - canvas:markRect(1, 16, canvas.width, canvas.height-16) + if #categories > 1 then + for i = #categories, 1, -1 do + local category = categories[i] + local categoryName = category.name + local categoryColor + if i == selectedCategory then + categoryColor = theme.colors.activeCategoryColor + categoryName = "[" .. categoryName .. "]" + elseif i % 4 == 1 then + categoryColor = theme.colors.category1Color + elseif i % 4 == 2 then + categoryColor = theme.colors.category2Color + elseif i % 4 == 3 then + categoryColor = theme.colors.category3Color + elseif i % 4 == 0 then + categoryColor = theme.colors.category4Color end - }) + local categoryWidth = smolFont:getWidth(categoryName)+6 + categoryX = categoryX - categoryWidth - 2 + + table.insert(flatCanvas, SmolButton { + display = display, + align = "center", + text = categoryName, + x = categoryX, + y = 4, + bg = categoryColor, + color = theme.colors.categoryTextColor, + width = categoryWidth, + onClick = function() + props.shopState.selectedCategory = i + props.shopState.lastTouched = os.epoch("utc") + -- canvas:markRect(1, 16, canvas.width, canvas.height-16) + end + }) + end end return _.flat({ _.flat(flatCanvas) }), { @@ -309,7 +309,11 @@ -- Mark rectangle of removed canvases on bgCanvas (TODO: using bgCanvas is a hack) for _, canvas in pairs(removed) do - display.bgCanvas:dirtyRect(canvas[2], canvas[3], canvas[1].width, canvas[1].height) + if canvas[1].brand == "TextCanvas" then + display.bgCanvas:dirtyRect(canvas[2], canvas[3], canvas[1].width*2, canvas[1].height*3) + else + display.bgCanvas:dirtyRect(canvas[2], canvas[3], canvas[1].width, canvas[1].height) + end end -- For each kept canvas, mark the bounds if the new bounds are different @@ -319,8 +323,13 @@ if oldCanvas then if oldCanvas[2] ~= newCanvas[2] or oldCanvas[3] ~= newCanvas[3] then -- TODO: Optimize this? - display.bgCanvas:dirtyRect(oldCanvas[2], oldCanvas[3], oldCanvas[1].width, oldCanvas[1].height) - display.bgCanvas:dirtyRect(newCanvas[2], newCanvas[3], newCanvas[1].width, newCanvas[1].height) + if oldCanvas[1].brand == "TextCanvas" then + display.bgCanvas:dirtyRect(oldCanvas[2], oldCanvas[3], oldCanvas[1].width*2, oldCanvas[1].height*3) + display.bgCanvas:dirtyRect(newCanvas[2], newCanvas[3], newCanvas[1].width*2, newCanvas[1].height*3) + else + display.bgCanvas:dirtyRect(oldCanvas[2], oldCanvas[3], oldCanvas[1].width, oldCanvas[1].height) + display.bgCanvas:dirtyRect(newCanvas[2], newCanvas[3], newCanvas[1].width, newCanvas[1].height) + end end end end @@ -331,8 +340,12 @@ local shopState = Core.ShopState.new(config, products) +local Profiler = require("profile") + + local deltaTimer = os.startTimer(0) ShopRunner.launchShop(shopState, function() + -- Profiler:activate() while true do tree = Solyd.render(tree, Main {t = t, config = config, shopState = shopState}) @@ -341,7 +354,9 @@ diffCanvasStack(context.canvas) local t1 = os.epoch("utc") - display.ccCanvas:composite(unpack(context.canvas)) + local cstack = { {display.bgCanvas, 1, 1}, unpack(context.canvas) } + -- cstack[#cstack+1] = {display.textCanvas, 1, 1} + display.ccCanvas:composite(unpack(cstack)) display.ccCanvas:outputDirty(display.mon) local t2 = os.epoch("utc") -- print("Render time: " .. (t2-t1) .. "ms") @@ -362,6 +377,13 @@ if node then node.onClick() end + elseif name == "key" then + if e[2] == keys.q then + break + end end end + -- Profiler:deactivate() end) + +-- Profiler:write_results(nil, "profile.txt")