Somebody helps me out with the performance problem?

Show off your games, demos and other (playable) creations.
User avatar
liyonglove2d
Prole
Posts: 38
Joined: Sun Mar 29, 2015 7:06 am

Somebody helps me out with the performance problem?

Post by liyonglove2d » Mon Mar 30, 2015 9:32 am

THE .LOVE FILE IS HERE http://pan.baidu.com/s/1qWsQiRU

Em, it's my first post here :nyu: . 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:
game1.png
screen snap1
game1.png (770.06 KiB) Viewed 2098 times
game2.png
screensnap2
game2.png (335.7 KiB) Viewed 2098 times
The .love is a little big, I'll upload it if necessary. :3
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.
Last edited by liyonglove2d on Tue Mar 31, 2015 2:01 am, edited 2 times in total.

User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Somebody helps me out with the performance problem?

Post by arampl » Mon Mar 30, 2015 9:55 am

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.

User avatar
liyonglove2d
Prole
Posts: 38
Joined: Sun Mar 29, 2015 7:06 am

Re: Somebody helps me out with the performance problem?

Post by liyonglove2d » Mon Mar 30, 2015 10:11 am

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.
Oh thanks a lot. Every entity has its own 'ondraw' function, so the love.draw() function is just very simple.
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 :death: :
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 :nyu: .

User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Somebody helps me out with the performance problem?

Post by arampl » Mon Mar 30, 2015 10:17 am

liyonglove2d wrote:How many images can be drawn to the screen in one frame if I want 60 FPS for my game?
No one can tell you that. It depends on the system specs.

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).

User avatar
liyonglove2d
Prole
Posts: 38
Joined: Sun Mar 29, 2015 7:06 am

Re: Somebody helps me out with the performance problem?

Post by liyonglove2d » Mon Mar 30, 2015 12:58 pm

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 :)

User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Somebody helps me out with the performance problem?

Post by rmcode » Mon Mar 30, 2015 1:09 pm

For finding out what really is the bottleneck in your code I suggest you run some "timed" tests.

Code: Select all

function love.draw()
        local start = love.timer.getTime()
        -- code...
        local tend = love.timer.getTime();
        print("Time passed " .. tend - start);
end
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.

User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Somebody helps me out with the performance problem?

Post by T-Bone » Mon Mar 30, 2015 1:42 pm

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.

User avatar
liyonglove2d
Prole
Posts: 38
Joined: Sun Mar 29, 2015 7:06 am

Re: Somebody helps me out with the performance problem?

Post by liyonglove2d » Mon Mar 30, 2015 3:33 pm

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

User avatar
liyonglove2d
Prole
Posts: 38
Joined: Sun Mar 29, 2015 7:06 am

Re: Somebody helps me out with the performance problem?

Post by liyonglove2d » Mon Mar 30, 2015 3:37 pm

Shall I upload the .love file?

User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Somebody helps me out with the performance problem?

Post by s-ol » Mon Mar 30, 2015 8:14 pm

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).

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end

Post Reply

Who is online

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