High processor usage drawing forms on mouse position

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
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

High processor usage drawing forms on mouse position

Post by Petunien »

Hi,

I get a processor usage up to 70% when I draw some forms on the mouse position.
Is there generally a problem with that or am I doing something wrong?

Maybe too much color changes or calculations in the draw commands?

Code: Select all

love.graphics.setColor(0, 200, 0, 100)
love.graphics.circle("fill", love.mouse.getX(), love.mouse.getY(), test1)
	
love.graphics.setColor(test3, test4, 0, 100)
love.graphics.rectangle("fill", love.mouse.getX()-40, love.mouse.getY()-40, test5, test6)
	
love.graphics.setColor(test3, test4, 0)
love.graphics.rectangle("line", love.mouse.getX()-40, love.mouse.getY()-40, test5, test6)
	
love.graphics.setColor(0, 255, 0)
love.graphics.circle("line", love.mouse.getX(), love.mouse.getY(), test2)
"testXYZ" are only integer variables, nothing specially.
"Docendo discimus" - Lucius Annaeus Seneca
iemfi
Citizen
Posts: 52
Joined: Fri Mar 30, 2012 11:03 am

Re: High processor usage drawing forms on mouse position

Post by iemfi »

Is that all the code there is? Perhaps the problem is somewhere else?
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: High processor usage drawing forms on mouse position

Post by Petunien »

When I cut out the mouse specific code, the processor usage is usually at 10-20%, therefore I think, the error is in this piece of code.
"Docendo discimus" - Lucius Annaeus Seneca
User avatar
tsturzl
Party member
Posts: 161
Joined: Fri Apr 08, 2011 3:24 am

Re: High processor usage drawing forms on mouse position

Post by tsturzl »

It seems odd that that would take that much processing, however calling for the mouse coordinates everytime you draw something seems like a waste. Try something like this:

Code: Select all

local x, local y = love.mouse.getPosition( )
love.graphics.setColor(0, 200, 0, 100)
love.graphics.circle("fill", x, y, test1)
   
love.graphics.setColor(test3, test4, 0, 100)
love.graphics.rectangle("fill", x-40, ly-40, test5, test6)
   
love.graphics.setColor(test3, test4, 0)
love.graphics.rectangle("line", x-40, y-40, test5, test6)
   
love.graphics.setColor(0, 255, 0)
love.graphics.circle("line", x, y, test2)
This way you call love.mouse.getPosition() once, then you reuse local variables "x" and "y". This seems slightly less intensive to me. Besides the position of the mouse can't change within the same draw call.

Try this and see if it cuts down your CPU usage, though I still don't see why it takes so much to begin with.

Karmaz? :crazy:
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: High processor usage drawing forms on mouse position

Post by Petunien »

Hmm.

I wrote the code in a new gameproject, a new main.lua.

That's all of the code:

Code: Select all

function love.update(dt)

	x, y = love.mouse.getPosition( )
	
	test1 = 100
	test2 = 100
	
	test3 = 0
	test4 = 255
	
	test5 = 80
	test6 = 80

end

function love.draw()

love.graphics.setColor(0, 200, 0, 100)
love.graphics.circle("fill", x, y, test1)
   
love.graphics.setColor(test3, test4, 0, 100)
love.graphics.rectangle("fill", x-40, y-40, test5, test6)
   
love.graphics.setColor(test3, test4, 0)
love.graphics.rectangle("line", x-40, y-40, test5, test6)
   
love.graphics.setColor(0, 255, 0)
love.graphics.circle("line", x, y, test2)

end
When I start this game with LOVE 0.8.0 (pre-release) the cpu usage is about 60%, when I run this with LOVE 0.7.2 is it really low, in the span of 0-20%.
Is this a bug or something like that of LOVE 0.8.0?

I "develop" usually with the latest build, so I don't have to change much on the release.

Edit:
Ok, I think I found the reason:
Image

It's maybe the amount of segments?

Edit²:

No, it isn't. The same with 10 segments. It's because of 0.8.0.
"Docendo discimus" - Lucius Annaeus Seneca
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: High processor usage drawing forms on mouse position

Post by Boolsheet »

What LÖVE binary are you using? And what framerate do you get with that code in 0.7.2 and 0.8.0?

There's the new smooth-line drawing in 0.8.0, but your system should be able to handle it without any problems. You can disable it with love.graphics.setLineStyle("rough") if you want to test for it.
Shallow indentations.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: High processor usage drawing forms on mouse position

Post by Nixola »

LÖVE 0.7.2 also has it
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: High processor usage drawing forms on mouse position

Post by Petunien »

Without vsync I get in 0.7.2 about 960-999 FPS, in 0.8.0 too.
The cpu usage sway without vsync in the range of 10-30%.

With setting the line-style to "rough" in 0.8.0, the cpu usage sinks down to a normally value.

I think, vsync and "rough" would be the best solution.

But why works it better in 0.7.2 than in 0.8.0, which is a newer version?
"Docendo discimus" - Lucius Annaeus Seneca
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: High processor usage drawing forms on mouse position

Post by Boolsheet »

Petunien wrote:But why works it better in 0.7.2 than in 0.8.0, which is a newer version?
The line smoothing in 0.8.0 has a different approach. It does still work on every graphics card with the drawback of some more CPU work. I don't think it should be that noticable unless you're using a slow CPU with software floating point. (If it really is the line smoothing causing the high CPU load)
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 167 guests