Controlling Love.Draw... Possible?

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
Grubby
Prole
Posts: 35
Joined: Sat Jun 01, 2013 2:46 am

Controlling Love.Draw... Possible?

Post by Grubby »

It might be silly, but I was playing Kerbal Space Program and noticed a setting in the graphics options labeled "Vsync:Every second Vblank". So this gots me to thinkin about L2d and my factory simulation. In my sim, love.draw() has two particular functions of concern. One for animations and one to print out all the text data. It's my assumption that animations and GUI stuff should probably be dealt with every frame. But the text data for the most part only changes about 40% - 50% of the time. This kinda seems like a waste of cpu cycles to keep printing out data that can only change every other frame or so.

So my question is how do I draw my text data every other frame? Every 4 frames? and so on?... Is this even possible? If so, how would I tackle this? If so, would this be a good or bad thing?

Thanks,
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Controlling Love.Draw... Possible?

Post by airstruck »

Isn't it going to flicker like hell if you only draw it every 4 frames?
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Controlling Love.Draw... Possible?

Post by zorg »

You can print the text to a canvas once, and then only redraw the canvas when the text needs updating, and draw the canvas itself every frame; that may save some cpu cycles, but it's not that much of a gain in my opinion.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Rickton
Party member
Posts: 128
Joined: Tue Mar 19, 2013 4:59 pm
Contact:

Re: Controlling Love.Draw... Possible?

Post by Rickton »

I would imagine any gains made from doing this would be offset by problems or bugs introduced by messing with love.draw(). It's not like text takes very long to draw, anyway, so you'd probably spend more time implementing it than you'd save.
If you really are that concerned, use a canvas like zorg said, but unless you're actually having performance issues, I wouldn't worry about it (and if you are having performance issues, it's almost certainly something else, not drawing text every frame).
Possession - Escape from the Nether Regions, my roguelike made in LÖVE for the 2013 7-Day Roguelike Challenge
And its sequel, simply called Possession , which is available on itch.io or Steam, and whose engine I've open-sourced!
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Controlling Love.Draw... Possible?

Post by Positive07 »

I'm not sure I could recommend this but you can always tweak [wiki]love.run[/wiki] to your needs
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

Re: Controlling Love.Draw... Possible?

Post by CaptainMaelstrom »

Grubby wrote:This kinda seems like a waste of cpu cycles...
As others have mentioned, whatever CPU cycles you save will be offset by time spent developing your work-around, trouble-shooting and de-bugging it. Read up on the dangers of premature optimization! :ultraglee:
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Controlling Love.Draw... Possible?

Post by T-Bone »

Modifying love.run doesn't sound like a good solution for this. If the text rendering is really expensive (and you've actually measured that it is a framerate bottleneck) then drawing the text on a canvas is a much better solution.

In general, rendering text is pretty cheap, so I wouldn't worry about it. If you're changing the text as often as every 2-3 frames then you won't save that much by using a Canvas anyway.
Grubby
Prole
Posts: 35
Joined: Sat Jun 01, 2013 2:46 am

Re: Controlling Love.Draw... Possible?

Post by Grubby »

Thanks guys!

Now why is it every time I ask a question in these forums I get pretty much the same answer?

"Don't do what you are planning to do because the gains you get won't be worth it..."

Of course, I generalize. Premature optimization? Whats that? Heh!
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Controlling Love.Draw... Possible?

Post by T-Bone »

It's pretty hard to tell what's going to be worth it in the end, so you should be glad people are sharing their experiences :neko:

Somebody (maybe Robin or Kikito? can't remember) said something like this: First make it work. Then make it pretty. Then, if it's slow, you can start worrying about performance.
User avatar
Rucikir
Party member
Posts: 129
Joined: Tue Nov 05, 2013 6:33 pm

Re: Controlling Love.Draw... Possible?

Post by Rucikir »

Donald Knuth wrote:"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%"
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests