I moved garbage collect into the update loop, which fixed the memory problem and didn't have a noticeable fps impact. However, I'm sure in a bigger program calling garbage collect every frame is suicide.NÖÖB wrote:@Technocat: woah! You need the preparePix call in the plasma function, though.. if not, your ram gets eaten
Code: Select all
function love.load()
pixBuf = love.image.newImageData( 512, 256 ) -- initialize PO2 buffer
pix = love.graphics.newImage( pixBuf )
pixUpdate = 0
f1 = 0
f2 = 0
f3 = 0
pm = 3.14 / 180
end
-----------------------------------------------------------------------
function love.update( dt )
pixUpdate = pixUpdate + 1
if pixUpdate > 1 then -- limit render FPS
collectgarbage('collect')
plasma()
pixUpdate = 0
end
love.timer.sleep( 1 )
end
-----------------------------------------------------------------------
function love.draw()
love.graphics.draw( pix, pixOffsetX, pixOffsetY, 0, 2, 2, 0, 0 )
love.graphics.print("FPS: " .. love.timer.getFPS(), 1, 1 )
end
-----------------------------------------------------------------------
function updatePix( pOX, pOY )
pixOffsetX = pOX
pixOffsetY = pOY
pix = love.graphics.newImage( pixBuf )
pix:setFilter( "nearest", "nearest" )
end
-----------------------------------------------------------------------
function plasma()
f1 = f1 + 1
f2 = f2 - 7
f3 = f3 + 3
local sin = math.sin
local cos = math.cos
for l1 = 0, 180 do -- plasma size 320 x 180 ( rendered 640 x 360 )
local av = 50 * sin(( l1 + f1 ) * pm )
local av2 = 60 + av * cos(( f2 + l1 ) * pm )
local av3 = 100 + 10 * sin(( f1 + l1 ) / 10 )
local b1 = 100 + 70 * ( cos( av2 + l1 )) / 8
for l2 = 0, 320 do
local r = 140 + av2 * sin(( l2 + av2 + l1 ) / av3 )
pixBuf:setPixel(l2, l1, r, av2, b1, 255 )
end
end
updatePix( 80, 120 )
end