Massive Performance and Memory Hog

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
bionsuba
Prole
Posts: 2
Joined: Sun Jan 13, 2013 5:46 am

Massive Performance and Memory Hog

Post 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.
Attachments
Archive.love
(12.29 KiB) Downloaded 115 times
no.love
(285.22 KiB) Downloaded 128 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Massive Performance and Memory Hog

Post 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.
Help us help you: attach a .love.
bionsuba
Prole
Posts: 2
Joined: Sun Jan 13, 2013 5:46 am

Re: Massive Performance and Memory Hog

Post by bionsuba »

Thank you very much for your time, that worked perfectly.

Image
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 7 guests