mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-17 22:09:28 -07:00
Replacing image tables with arrays of images eliminates the memory leak
This commit is contained in:
@@ -8,31 +8,25 @@ local numRows <const> = math.floor(screenHeight / glyphWidth)
|
|||||||
local numCells <const> = numColumns * numRows
|
local numCells <const> = numColumns * numRows
|
||||||
|
|
||||||
local numGlyphs <const> = 133
|
local numGlyphs <const> = 133
|
||||||
local glyphs = gfx.imagetable.new('images/matrix')
|
local glyphTable = gfx.imagetable.new('images/matrix')
|
||||||
-- local glyphMap = gfx.tilemap.new()
|
local glyphs = {}
|
||||||
-- glyphMap:setImageTable(glyphs)
|
for i = 1, numGlyphs do
|
||||||
-- glyphMap:setSize(numColumns, numRows)
|
glyphs[i] = glyphTable[i]
|
||||||
|
end
|
||||||
|
|
||||||
local ditherType = gfx.image.kDitherTypeAtkinson
|
local ditherType = gfx.image.kDitherTypeAtkinson
|
||||||
local image = gfx.image.new(glyphWidth, glyphWidth, gfx.kColorBlack)
|
local image = gfx.image.new(glyphWidth, glyphWidth, gfx.kColorBlack)
|
||||||
local numFades <const> = 15
|
local numFades <const> = 15
|
||||||
local fades = gfx.imagetable.new(numFades)
|
local fades = {}
|
||||||
for i = 1, numFades do
|
for i = 1, numFades do
|
||||||
fades:setImage(i, image:fadedImage(i / numFades, ditherType))
|
fades[i] = image:fadedImage(i / numFades, ditherType)
|
||||||
end
|
end
|
||||||
-- local fadeMap = gfx.tilemap.new()
|
|
||||||
-- fadeMap:setImageTable(fades)
|
|
||||||
-- fadeMap:setSize(numColumns, numRows)
|
|
||||||
|
|
||||||
local minSpeed <const> = 0.15
|
local minSpeed <const> = 0.15
|
||||||
local maxSpeed <const> = 1
|
local maxSpeed <const> = 1
|
||||||
local time = 0
|
local time = 0
|
||||||
local speed = maxSpeed
|
local speed = maxSpeed
|
||||||
|
|
||||||
function randomFloat()
|
|
||||||
return math.random(10000) / 10000
|
|
||||||
end
|
|
||||||
|
|
||||||
local sqrt2 <const> = math.sqrt(2)
|
local sqrt2 <const> = math.sqrt(2)
|
||||||
local sqrt5 <const> = math.sqrt(5)
|
local sqrt5 <const> = math.sqrt(5)
|
||||||
function wobble(x)
|
function wobble(x)
|
||||||
@@ -41,20 +35,19 @@ end
|
|||||||
|
|
||||||
local cells = {}
|
local cells = {}
|
||||||
for x = 1, numColumns do
|
for x = 1, numColumns do
|
||||||
local columnTimeOffset = randomFloat() * 1000
|
local columnTimeOffset = math.random() * 1000
|
||||||
local columnSpeedOffset = randomFloat() * 0.5 + 0.5
|
local columnSpeedOffset = math.random() * 0.5 + 0.5
|
||||||
for y = 1, numRows do
|
for y = 1, numRows do
|
||||||
local cell = {}
|
local cell = {}
|
||||||
cell.x = x
|
cell.x = x
|
||||||
cell.y = y
|
cell.y = y
|
||||||
cell.glyphCycle = randomFloat()
|
cell.glyphCycle = math.random()
|
||||||
cell.columnTimeOffset = columnTimeOffset
|
cell.columnTimeOffset = columnTimeOffset
|
||||||
cell.columnSpeedOffset = columnSpeedOffset
|
cell.columnSpeedOffset = columnSpeedOffset
|
||||||
cell.glyphIndex = math.random(numGlyphs) + 1
|
cell.glyphIndex = math.floor(math.random() * numGlyphs) + 1
|
||||||
cell.fadeIndex = -1
|
cell.fadeIndex = -1
|
||||||
|
|
||||||
cells[#cells + 1] = cell
|
cells[#cells + 1] = cell
|
||||||
-- glyphMap:setTileAtPosition(x, y, cell.glyphIndex)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -73,8 +66,6 @@ function playdate.update()
|
|||||||
playdate.resetElapsedTime()
|
playdate.resetElapsedTime()
|
||||||
time += delta
|
time += delta
|
||||||
|
|
||||||
-- local count = 0
|
|
||||||
|
|
||||||
for i = 1, numCells do
|
for i = 1, numCells do
|
||||||
local mustDraw = false
|
local mustDraw = false
|
||||||
local cell = cells[i]
|
local cell = cells[i]
|
||||||
@@ -90,7 +81,7 @@ function playdate.update()
|
|||||||
cell.glyphCycle = cell.glyphCycle + delta * 2
|
cell.glyphCycle = cell.glyphCycle + delta * 2
|
||||||
if cell.glyphCycle > 1 then
|
if cell.glyphCycle > 1 then
|
||||||
cell.glyphCycle = cell.glyphCycle % 1
|
cell.glyphCycle = cell.glyphCycle % 1
|
||||||
local glyphIndex = (cell.glyphIndex + math.random(math.floor(numGlyphs / 2))) % numGlyphs + 1
|
local glyphIndex = (cell.glyphIndex + math.random(20)) % numGlyphs + 1
|
||||||
if cell.glyphIndex ~= glyphIndex then
|
if cell.glyphIndex ~= glyphIndex then
|
||||||
cell.glyphIndex = glyphIndex
|
cell.glyphIndex = glyphIndex
|
||||||
if fadeIndex < numFades then
|
if fadeIndex < numFades then
|
||||||
@@ -100,19 +91,9 @@ function playdate.update()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if mustDraw then
|
if mustDraw then
|
||||||
-- count += 1
|
|
||||||
-- glyphMap:setTileAtPosition(cell.x, cell.y, cell.glyphIndex)
|
|
||||||
-- fadeMap:setTileAtPosition(cell.x, cell.y, cell.fadeIndex)
|
|
||||||
|
|
||||||
glyphs[cell.glyphIndex]:draw((cell.x - 1) * glyphWidth, (cell.y - 1) * glyphWidth)
|
glyphs[cell.glyphIndex]:draw((cell.x - 1) * glyphWidth, (cell.y - 1) * glyphWidth)
|
||||||
fades[cell.fadeIndex]:draw((cell.x - 1) * glyphWidth, (cell.y - 1) * glyphWidth)
|
fades[cell.fadeIndex]:draw((cell.x - 1) * glyphWidth, (cell.y - 1) * glyphWidth)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- print(count / numGlyphs)
|
|
||||||
|
|
||||||
-- gfx.clear()
|
|
||||||
-- glyphMap:draw(0, 0)
|
|
||||||
-- fadeMap:draw(0, 0)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user