Per-pixel plasma / copperbars

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Per-pixel plasma / copperbars

Post by TechnoCat »

NÖÖB wrote:@Technocat: woah! :awesome: You need the preparePix call in the plasma function, though.. if not, your ram gets eaten
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.

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
User avatar
schme16
Party member
Posts: 127
Joined: Thu Oct 02, 2008 2:46 am

Re: Per-pixel plasma / copperbars

Post by schme16 »

I've tested the updated garbage collection version and the original and here are my results:
Standard: 40-41 FPS
Updated (new garbage collection system): 82-87 FPS

my Specs:
AMD Athlon quad core 3.0ghz
ATI HD5670 1gb gddr4
4gb RAM
My Development Diary - http://shanegadsby.info
User avatar
NÖÖB
Prole
Posts: 41
Joined: Thu Jul 31, 2008 10:57 pm
Location: Norway

Re: Per-pixel plasma / copperbars

Post by NÖÖB »

Just tried running the code on my desktop; on my AMD Phenom II X4 965 3.4GHZ, Geforce GTX 460, I'm getting 98FPS, but if I change the frame limiting code to:

Code: Select all

function love.update( dt )
      pp = pp + dt
      if pp > 1/15 then
         collectgarbage('collect')
         plasma()
         pp = 0
      end
   love.timer.sleep( 1 )
end
then I'm getting 274 FPS :shock: (vsync off)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 219 guests