kill dead code

This commit is contained in:
Your Name 2026-08-07 01:05:08 -04:00
parent a8b469876d
commit 7fa9171ba1
9 changed files with 72 additions and 187 deletions

View file

@ -45,3 +45,67 @@ function readFromSource(relPath)
end
return love.filesystem.read(relPath)
end
-- Cached image loader. The filesystem is the source of truth for art, so every
-- sprite is loaded on demand by path (deduped here) rather than from a
-- hand-maintained central table.
local spriteCache = {}
function loadSprite(path)
if not spriteCache[path] then
spriteCache[path] = love.graphics.newImage(path)
end
return spriteCache[path]
end
function cellShapeFromBox(box)
local cells = {}
for i = 1, box.w do
for j = 1, box.h do
table.insert(cells, {x = i, y = j})
end
end
return cells
end
-- Which 16x16 cells of a sprite are non-empty, for multi-cell collision shapes.
function getCellsFromSprite(sprite)
local w, h = sprite:getWidth(), sprite:getHeight()
local box = {w = w / 16, h = h / 16}
local boxCells = cellShapeFromBox(box)
if box.w < 1 or box.h < 1 then
return boxCells
end
local img = sprite:getData()
local cellsToRemove = {}
for _, cell in pairs(boxCells) do
local startPixel = {x = (cell.x - 1) * 16, y = (cell.y - 1) * 16}
local endPixel = {x = (cell.x * 16) - 1, y = (cell.y * 16) - 1}
local empty = true
for i = startPixel.x, endPixel.x do
for j = startPixel.y, endPixel.y do
local r, g, b, a = img:getPixel(i, j)
if a > 0 and (r > 0 or g > 0 or b > 0) then
empty = false
end
end
end
if empty then
cellsToRemove[cell] = cell
end
end
local i = 1
while i <= #boxCells do
if boxCells[i] == cellsToRemove[boxCells[i]] then
table.remove(boxCells, i)
else
i = i + 1
end
end
return boxCells
end