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.
Massive Performance and Memory Hog
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Massive Performance and Memory Hog
- Attachments
-
- Archive.love
- (12.29 KiB) Downloaded 116 times
-
- no.love
- (285.22 KiB) Downloaded 128 times
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Massive Performance and Memory Hog
You create a font for every button, every frame:
You create a font for the game object, every frame:
What you want to do instead:
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.
Code: Select all
love.graphics.setFont(love.graphics.newFont(32))
Code: Select all
love.graphics.setFont(love.graphics.newFont(12))
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)
Also, use #t instead of table.getn(t). The latter is deprecated.
Help us help you: attach a .love.
Re: Massive Performance and Memory Hog
Thank you very much for your time, that worked perfectly.
Who is online
Users browsing this forum: No registered users and 4 guests