This commit is contained in:
2026-05-05 18:08:14 -04:00
parent f4ac7faf0b
commit 604cb7857f

View File

@@ -44,12 +44,25 @@ end
local function makeGpuBackend(gpu) local function makeGpuBackend(gpu)
gpu.refreshSize() gpu.refreshSize()
-- Per-block pixel resolution. 32 gives a nice balance between -- Try a high per-block resolution; older/cheaper GPU tiers may cap
-- pocket density and per-pixel performance on multi-block screens. -- this so fall back if it errors.
gpu.setSize(32) local trySizes = { 64, 32, 16, 8 }
for _, s in ipairs(trySizes) do
if pcall(gpu.setSize, s) then break end
end
local pw, ph = gpu.getSize() local pw, ph = gpu.getSize()
-- Pocket cell size in pixels. Bigger = chunkier pockets. print(("[roulette] GPU pixel size: %sx%s"):format(tostring(pw), tostring(ph)))
local cell = 16
if not pw or not ph or pw < 8 or ph < 8 then
error(("GPU reports unusable pixel size %sx%s. Place at least one screen block adjacent to the GPU.")
:format(tostring(pw), tostring(ph)))
end
-- Pick a cell size that gives at least 16x16 cells, capped at 16 px.
local cell = math.max(2, math.min(16, math.floor(math.min(pw, ph) / 16)))
print(("[roulette] Using cell size: %d px -> %dx%d cells"):format(
cell, math.floor(pw / cell), math.floor(ph / cell)))
return { return {
kind = "gpu", kind = "gpu",
@@ -69,10 +82,9 @@ local function makeGpuBackend(gpu)
local px = (x - 1) * cell + 1 local px = (x - 1) * cell + 1
local py = (y - 1) * cell + 1 local py = (y - 1) * cell + 1
-- drawText(x, y, text, textColor, bgColor, size, padding) -- drawText(x, y, text, textColor, bgColor, size, padding)
gpu.drawText(px, py, str, fg, bg, 1, 0) pcall(gpu.drawText, px, py, str, fg, bg, 1, 0)
end, end,
clear = function(col) clear = function(col)
-- gpu.fill() with no args clears to black; with a color clears to that color.
if col then gpu.fill(col) else gpu.fill() end if col then gpu.fill(col) else gpu.fill() end
end, end,
sync = function() sync = function()
@@ -269,8 +281,9 @@ local function start()
math.randomseed(os.epoch("utc")) math.randomseed(os.epoch("utc"))
gfx = initBackend() gfx = initBackend()
W, H = gfx.size() W, H = gfx.size()
if W < 4 or H < 4 then print(("[roulette] Wheel grid: %dx%d cells"):format(W, H))
error(("Screen too small: %dx%d cells"):format(W, H)) if W < 3 or H < 3 then
error(("Screen too small: %dx%d cells. Add more screen blocks."):format(W, H))
end end
buildPerimeter() buildPerimeter()
ballIndex = 1 ballIndex = 1