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)
gpu.refreshSize()
-- Per-block pixel resolution. 32 gives a nice balance between
-- pocket density and per-pixel performance on multi-block screens.
gpu.setSize(32)
-- Try a high per-block resolution; older/cheaper GPU tiers may cap
-- this so fall back if it errors.
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()
-- Pocket cell size in pixels. Bigger = chunkier pockets.
local cell = 16
print(("[roulette] GPU pixel size: %sx%s"):format(tostring(pw), tostring(ph)))
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 {
kind = "gpu",
@@ -69,10 +82,9 @@ local function makeGpuBackend(gpu)
local px = (x - 1) * cell + 1
local py = (y - 1) * cell + 1
-- 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,
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
end,
sync = function()
@@ -269,8 +281,9 @@ local function start()
math.randomseed(os.epoch("utc"))
gfx = initBackend()
W, H = gfx.size()
if W < 4 or H < 4 then
error(("Screen too small: %dx%d cells"):format(W, H))
print(("[roulette] Wheel grid: %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
buildPerimeter()
ballIndex = 1