Page 1 of 1

Massive Performance and Memory Hog

Posted: Sun Jan 13, 2013 6:06 am
by bionsuba
Hello everyone.

I am creating a simple rougelike for my class project and I have run into some problems. The game is at a very early point at this stage so all you can do is move around a little @ symbol with the arrow keys and you run into the stones and the water. I have copied the code structure and a lot of the code from the 0.8 example program entitled "no" (which I have included in an attachment with my own code), because it had a working state and menu system which I was failing to create. In doing this though, the program still operates as intended but it now takes up to 95% of my cpu and up to 150 Mb of memory for doing what should take less than 30 Mb of memory. This causes the FPS to go down the shitter and make my computer super slow. I have no way of knowing what is taking up so much processing power. Any help would be appreciated.

Re: Massive Performance and Memory Hog

Posted: Sun Jan 13, 2013 10:49 am
by Robin
You create a font for every button, every frame:

Code: Select all

love.graphics.setFont(love.graphics.newFont(32))
You create a font for the game object, every frame:

Code: Select all

love.graphics.setFont(love.graphics.newFont(12))
What you want to do instead:

Code: Select all

Button = {}
Button.__index = Button
Button.font = love.graphics.newFont(32)
-- ....
    love.graphics.setFont(self.font)

Code: Select all

Game = {}
Game.__index = Game
Game.font = love.graphics.newFont(12)
-- ...
    love.graphics.setFont(self.font)
On minor notes, it might be a good idea to make a general State table, which can handle the drawing and updating of buttons for each state, so that code won't get duplicated.
Also, use #t instead of table.getn(t). The latter is deprecated.

Re: Massive Performance and Memory Hog

Posted: Sun Jan 13, 2013 5:48 pm
by bionsuba
Thank you very much for your time, that worked perfectly.

Image