Page 1 of 1

Controlling Love.Draw... Possible?

Posted: Thu Aug 06, 2015 3:22 pm
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,

Re: Controlling Love.Draw... Possible?

Posted: Thu Aug 06, 2015 3:32 pm
by airstruck
Isn't it going to flicker like hell if you only draw it every 4 frames?

Re: Controlling Love.Draw... Possible?

Posted: Thu Aug 06, 2015 3:41 pm
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.

Re: Controlling Love.Draw... Possible?

Posted: Thu Aug 06, 2015 4:21 pm
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).

Re: Controlling Love.Draw... Possible?

Posted: Thu Aug 06, 2015 9:06 pm
by Positive07
I'm not sure I could recommend this but you can always tweak [wiki]love.run[/wiki] to your needs

Re: Controlling Love.Draw... Possible?

Posted: Fri Aug 07, 2015 2:02 am
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:

Re: Controlling Love.Draw... Possible?

Posted: Fri Aug 07, 2015 8:13 am
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.

Re: Controlling Love.Draw... Possible?

Posted: Mon Aug 10, 2015 11:15 pm
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!

Re: Controlling Love.Draw... Possible?

Posted: Tue Aug 11, 2015 3:25 pm
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.

Re: Controlling Love.Draw... Possible?

Posted: Mon Aug 17, 2015 12:53 pm
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%"