THE .LOVE FILE IS HERE http://pan.baidu.com/s/1qWsQiRU
Em, it's my first post here . I've been making a game named 'miner' or something in English. I encounter with performance problem with my game, and do not know how to solve it.
Here're game screenshots to tell what kind of game it is:
The .love is a little big, I'll upload it if necessary.
I got only 20 or even lower FPS sometimes, and I think the key problem is that I render too many entities in one frame, about 1000~3000 drawing calls I guess. Do I have to cut down the count of entities I draw? I'm wondering if there're other solutions to my problem. I really appriciate your help!
oh I forgot there's the whole project on git. https://code.csdn.net/iamagoodguy254/lo ... ree/master
tell me if you cannot visit the page.
Somebody helps me out with the performance problem?
- liyonglove2d
- Prole
- Posts: 38
- Joined: Sun Mar 29, 2015 7:06 am
Somebody helps me out with the performance problem?
Last edited by liyonglove2d on Tue Mar 31, 2015 2:01 am, edited 2 times in total.
Re: Somebody helps me out with the performance problem?
Hi, liyonglove2d!
Maybe you at least show code of your love.draw() function here in the message (you can use "Code" tags for readability).
Without any information people can only "tell fortune" about your situation. I can only imagine that you use some type of loop in which all tiles of the map are drawn, even if they don't visible on the screen. If so, you can look at kikito's excellent solution in the topic "Faster way to draw rectangles?" in the "Support and Development" section.
And maybe you should learn more about using canvases, sprite batches, quads and meshes in the docs.
Maybe you at least show code of your love.draw() function here in the message (you can use "Code" tags for readability).
Without any information people can only "tell fortune" about your situation. I can only imagine that you use some type of loop in which all tiles of the map are drawn, even if they don't visible on the screen. If so, you can look at kikito's excellent solution in the topic "Faster way to draw rectangles?" in the "Support and Development" section.
And maybe you should learn more about using canvases, sprite batches, quads and meshes in the docs.
- liyonglove2d
- Prole
- Posts: 38
- Joined: Sun Mar 29, 2015 7:06 am
Re: Somebody helps me out with the performance problem?
Oh thanks a lot. Every entity has its own 'ondraw' function, so the love.draw() function is just very simple.arampl wrote:Hi, liyonglove2d!
Maybe you at least show code of your love.draw() function here in the message (you can use "Code" tags for readability).
Without any information people can only "tell fortune" about your situation. I can only imagine that you use some type of loop in which all tiles of the map are drawn, even if they don't visible on the screen. If so, you can look at kikito's excellent solution in the topic "Faster way to draw rectangles?" in the "Support and Development" section.
And maybe you should learn more about using canvases, sprite batches, quads and meshes in the docs.
Indeed the lights're drawn with sprite batches, tiles're drawn with canvases, but trees/animals/ui items and all other things are drawn seperately. so i'm wondering if it is these seperately-drawn objects that caused the problem.
Would you help me with these problems :
Is the drawing speed relative with the size of the image to be drawn?
How many images can be drawn to the screen in one frame if I want 60 FPS for my game?
Are there convenient ways to find out the key problem of my code?
thanks again .
Re: Somebody helps me out with the performance problem?
No one can tell you that. It depends on the system specs.liyonglove2d wrote:How many images can be drawn to the screen in one frame if I want 60 FPS for my game?
I think you can prepare all you static sprites/tiles on one (or few) big image/canvas and draw it only once.
You can also try to use texture atlases somehow: http://en.wikipedia.org/wiki/Texture_atlas.
P.S. Are your trees animated?
Tip for HUD: you can draw UI elements only once (and redraw only when they're changed), then use inverted stencil (see in the docs) to protect HUD from other drawings. Not sure, but this can involve using custom love.run() function (the default one clears screen in each frame).
- liyonglove2d
- Prole
- Posts: 38
- Joined: Sun Mar 29, 2015 7:06 am
Re: Somebody helps me out with the performance problem?
I intend to animate all the plants, though not yet... I believe there's a way to do this with high performance...
As for UI, inverted stencil is a wanderful idea, I'll give it a try!
Thanks a lot for your response
As for UI, inverted stencil is a wanderful idea, I'll give it a try!
Thanks a lot for your response
Re: Somebody helps me out with the performance problem?
For finding out what really is the bottleneck in your code I suggest you run some "timed" tests.
This will give you an idea of where your game spends the most time. There also are some love profilers around, but I never used them.
Code: Select all
function love.draw()
local start = love.timer.getTime()
-- code...
local tend = love.timer.getTime();
print("Time passed " .. tend - start);
end
Re: Somebody helps me out with the performance problem?
If I had to take a shot in the dark and make a random guess, I think what you need is to use Canvases and/or Spritebatches to bulk multiple draw calls into a single draw call. For many kinds of games, this does wonders for performance.
For your game, I can guess that rendering the background to a Canvas, instead of rendering each tile individually, will save a lot of performance.
For your game, I can guess that rendering the background to a Canvas, instead of rendering each tile individually, will save a lot of performance.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- liyonglove2d
- Prole
- Posts: 38
- Joined: Sun Mar 29, 2015 7:06 am
Re: Somebody helps me out with the performance problem?
thanks a lot, guys.
I found most of the time are spent to draw the animals and plants, there're over 200 animals and plants to be drawn in one frame. So I reduced the count by modifying the map generator. The performance is getting much better, though not good enough
Here's the code, but I dont think it will help a lot to find out the reason coz it is not documented at all and anyway tedious...
https://code.csdn.net/iamagoodguy254/lo ... ree/master
I found most of the time are spent to draw the animals and plants, there're over 200 animals and plants to be drawn in one frame. So I reduced the count by modifying the map generator. The performance is getting much better, though not good enough
Here's the code, but I dont think it will help a lot to find out the reason coz it is not documented at all and anyway tedious...
https://code.csdn.net/iamagoodguy254/lo ... ree/master
- liyonglove2d
- Prole
- Posts: 38
- Joined: Sun Mar 29, 2015 7:06 am
Re: Somebody helps me out with the performance problem?
Shall I upload the .love file?
Re: Somebody helps me out with the performance problem?
Uploading a .love is probably a good idea.
I didn't take an actual look yet, but are you drawing the whole map every frame? You should try and determine only the visible entities and map parts so you don't spend 90% of your drawing calls on offscreen targets that aren't even visible; implement some kind of spatial partition for entities and just draw the visible part of the map (plus some margin).
I didn't take an actual look yet, but are you drawing the whole map every frame? You should try and determine only the visible entities and map parts so you don't spend 90% of your drawing calls on offscreen targets that aren't even visible; implement some kind of spatial partition for entities and just draw the visible part of the map (plus some margin).
Who is online
Users browsing this forum: No registered users and 0 guests