We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Intentionally lower CPU usage by low repaint freq
Page Index Toggle Pages: 1
Intentionally lower CPU usage by low repaint freq? (Read 462 times)
Intentionally lower CPU usage by low repaint freq?
Mar 9th, 2008, 1:31pm
 
Hi,

When an web page with a processing applet gets non-visible (e.g. somebody opens a new tab, Applets stop method is called?) the applet is not visible anymore and it doesn't make sense that it keeps drawing at all or at 30 fps and using in some cases 100% of my CPU. What is the best way to lower CPU activity in such a case to 0%?

Same problem with standalone desktop apps - sometimes I would like to lower CPU uses when they lost focus or are minimized.

I do not want to make this behavior a default but an option which has to explicitly set by the developer.

Cheers,
sb
Re: Intentionally lower CPU usage by low repaint f
Reply #1 - Mar 9th, 2008, 1:52pm
 
You could try changing behaviour based on frame.isFocused(); which will return a boolean value to say if the sketch has focus.
Re: Intentionally lower CPU usage by low repaint f
Reply #2 - Mar 9th, 2008, 2:00pm
 
And set the frame rate to 1 fps?

Is then the CPU to 0% or could one go further and set the thread to sleep that executes all the painting - or would this be dangerous?
Re: Intentionally lower CPU usage by low repaint f
Reply #3 - Mar 9th, 2008, 2:06pm
 
I don't know... you'll have to experiment and see what works, I've never tried to do such a thing, and don't know if anyone else has.
Re: Intentionally lower CPU usage by low repaint f
Reply #4 - Mar 10th, 2008, 8:44am
 
not sure from what your asking what event you'd want to watch for, but use noLoop() to stop the animation thread to save cpu (don't manipulate the thread directly).
http://processing.org/reference/noLoop_.html
Page Index Toggle Pages: 1